coord: generalise point hashing for all coord types

move the point hashing function into general coord operations. convert
from using std::hash to something we've made so that we know it's going
to spread the bits a little (unlike the default identity of GCC 7).
This commit is contained in:
Danny Robson 2017-06-29 16:33:53 +10:00
parent 36120319bc
commit 62491b4cec
2 changed files with 32 additions and 18 deletions

View File

@ -934,9 +934,9 @@ namespace util {
} }
///////////////////////////////////////////////////////////////////////////////
#include <tuple> #include <tuple>
namespace std { namespace std {
/// returns the dimensions of a coordinate type. /// returns the dimensions of a coordinate type.
/// ///
@ -985,4 +985,35 @@ namespace std {
} }
///////////////////////////////////////////////////////////////////////////////
#include <functional>
#include "../hash.hpp"
namespace std {
template <
size_t S,
typename T,
template <
std::size_t,typename
> class K
>
struct hash<
K<S,T>
> : public ::std::enable_if<
::util::is_coord_v<K<S,T>>
> {
std::size_t
operator() (K<S,T> k) const {
size_t v = 0xdeadbeef;
for (auto t: k)
v = ::util::hash::mix (t, v);
return v;
}
};
}
#endif #endif

View File

@ -103,23 +103,6 @@ namespace util {
typedef point4<int> point4i; typedef point4<int> point4i;
} }
#include <functional>
namespace std {
template <size_t S, typename T>
struct hash<util::point<S,T>> {
size_t operator() (util::point<S,T> p) const {
std::hash<T> h;
size_t k = 0;
for (size_t i = 0; i < S; ++i)
k = h (p.data[i] ^ k);
return k;
}
};
}
#include "point.ipp" #include "point.ipp"
#endif // __UTIL_POINT_HPP #endif // __UTIL_POINT_HPP