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/Mobs/Path.h | 2 +- src/Simulator/IncrementalRedstoneSimulator.h | 12 +++++++----- src/Vector3.h | 28 ++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index 491165795..d4ad066e3 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -145,7 +145,7 @@ private: /* Pathfinding fields */ std::priority_queue, compareHeuristics> m_OpenList; - std::unordered_map m_Map; + std::unordered_map> m_Map; Vector3i m_Destination; Vector3i m_Source; int m_BoundingBoxWidth; diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index b0d3ad7af..9fbefae73 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -76,19 +76,21 @@ private: { public: /// Per-chunk data for the simulator, specified individual chunks to simulate - std::unordered_map, Vector3i> m_ChunkData; + + /** test */ + std::unordered_map, VectorHasher> m_ChunkData; std::vector m_PoweredBlocks; std::vector m_LinkedBlocks; - std::unordered_map m_SimulatedPlayerToggleableBlocks; - std::unordered_map m_RepeatersDelayList; + std::unordered_map> m_SimulatedPlayerToggleableBlocks; + std::unordered_map> m_RepeatersDelayList; }; public: typedef std::vector PoweredBlocksList; typedef std::vector LinkedBlocksList; - typedef std::unordered_map SimulatedPlayerToggleableList; - typedef std::unordered_map RepeatersDelayList; + typedef std::unordered_map> SimulatedPlayerToggleableList; + typedef std::unordered_map> RepeatersDelayList; private: 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