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:
parent
36120319bc
commit
62491b4cec
@ -934,9 +934,9 @@ namespace util {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#include <tuple>
|
||||
|
||||
|
||||
namespace std {
|
||||
/// 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
|
||||
|
17
point.hpp
17
point.hpp
@ -103,23 +103,6 @@ namespace util {
|
||||
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"
|
||||
|
||||
#endif // __UTIL_POINT_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user