diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-06-07 12:52:14 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-06-07 13:53:59 +0200 |
commit | f44d123ba8ca14c3df90afff85a0674a4463cfa2 (patch) | |
tree | d017fd5b9dd4f98b7b52b8262d1bf21f568fca10 /src/Vector3.h | |
parent | Use emplace to construct structures (diff) | |
download | cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar.gz cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar.bz2 cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar.lz cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar.xz cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.tar.zst cuberite-f44d123ba8ca14c3df90afff85a0674a4463cfa2.zip |
Diffstat (limited to 'src/Vector3.h')
-rw-r--r-- | src/Vector3.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/Vector3.h b/src/Vector3.h index 279fe5cd7..168071469 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -235,12 +235,6 @@ public: return *this; } - /** Provides a hash of a vector's contents */ - size_t operator()(const Vector3<T> & a_Vector) const - { - return ((std::hash<T>()(a_Vector.x) ^ (std::hash<T>()(a_Vector.y) << 1)) ^ std::hash<T>()(a_Vector.z)); - } - // tolua_begin inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const @@ -390,6 +384,28 @@ template <> inline Vector3<int> Vector3<int>::Floor(void) const +template <typename What> +class VectorHasher +{ +public: + /** Provides a hash of a vector's contents */ + size_t operator()(const Vector3<What> & a_Vector) const + { + // Guaranteed to have no hash collisions for any 128x128x128 area + size_t Hash = 0; + Hash ^= static_cast<size_t>(a_Vector.x); + Hash <<= 8; + Hash ^= static_cast<size_t>(a_Vector.y); + Hash <<= 8; + Hash ^= static_cast<size_t>(a_Vector.z); + return Hash; + } +}; + + + + + template <typename T> const double Vector3<T>::EPS = 0.000001; |