From 171c59a01b07b7513cf7a281bbcb141e8182d274 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 2 Jun 2015 13:29:52 +0100 Subject: Changed appropriate containers to unordered_map Thanks to @worktycho for guidance! * Potential speed improvements --- src/Vector3.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index 346bc1bbb..279fe5cd7 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -235,6 +235,12 @@ public: return *this; } + /** Provides a hash of a vector's contents */ + size_t operator()(const Vector3 & a_Vector) const + { + return ((std::hash()(a_Vector.x) ^ (std::hash()(a_Vector.y) << 1)) ^ std::hash()(a_Vector.z)); + } + // tolua_begin inline Vector3 operator + (const Vector3& a_Rhs) const -- cgit v1.2.3 From f44d123ba8ca14c3df90afff85a0674a4463cfa2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 7 Jun 2015 11:52:14 +0100 Subject: Vector hasher is now a separate class --- src/Vector3.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/Vector3.h') 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 & a_Vector) const - { - return ((std::hash()(a_Vector.x) ^ (std::hash()(a_Vector.y) << 1)) ^ std::hash()(a_Vector.z)); - } - // tolua_begin inline Vector3 operator + (const Vector3& a_Rhs) const @@ -390,6 +384,28 @@ template <> inline Vector3 Vector3::Floor(void) const +template +class VectorHasher +{ +public: + /** Provides a hash of a vector's contents */ + size_t operator()(const Vector3 & a_Vector) const + { + // Guaranteed to have no hash collisions for any 128x128x128 area + size_t Hash = 0; + Hash ^= static_cast(a_Vector.x); + Hash <<= 8; + Hash ^= static_cast(a_Vector.y); + Hash <<= 8; + Hash ^= static_cast(a_Vector.z); + return Hash; + } +}; + + + + + template const double Vector3::EPS = 0.000001; -- cgit v1.2.3