From 6928c7eb6f00a00df4efcf1a1ec8f2310609696b Mon Sep 17 00:00:00 2001 From: Richard Try Date: Tue, 10 May 2022 20:26:24 +0300 Subject: [PATCH] Add hash for vector2d and vector3d (#93) --- include/vector2d.h | 18 ++++++++++++++++++ include/vector3d.h | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/vector2d.h b/include/vector2d.h index 08672a38..a0eb7ea8 100644 --- a/include/vector2d.h +++ b/include/vector2d.h @@ -8,6 +8,8 @@ #include "irrMath.h" #include "dimension2d.h" +#include + namespace irr { namespace core @@ -414,5 +416,21 @@ public: } // end namespace core } // end namespace irr +namespace std +{ + +template +struct hash > +{ + size_t operator()(const irr::core::vector2d& vec) const + { + size_t h1 = hash()(vec.X); + size_t h2 = hash()(vec.Y); + return (h1 << (4 * sizeof(h1)) | h1 >> (4 * sizeof(h1))) ^ h2; + } +}; + +} + #endif diff --git a/include/vector3d.h b/include/vector3d.h index 4dbc53b8..ed910e9f 100644 --- a/include/vector3d.h +++ b/include/vector3d.h @@ -7,6 +7,8 @@ #include "irrMath.h" +#include + namespace irr { namespace core @@ -466,5 +468,22 @@ namespace core } // end namespace core } // end namespace irr +namespace std +{ + +template +struct hash > +{ + size_t operator()(const irr::core::vector3d& vec) const + { + size_t h1 = hash()(vec.X); + size_t h2 = hash()(vec.Y); + size_t h3 = hash()(vec.Z); + return (h1 << (5 * sizeof(h1)) | h1 >> (3 * sizeof(h1))) ^ (h2 << (2 * sizeof(h2)) | h2 >> (6 * sizeof(h2))) ^ h3; + } +}; + +} + #endif