]> git.lizzy.rs Git - irrlicht.git/commitdiff
Add hash for vector2d and vector3d (#93)
authorRichard Try <bazrovstepan@gmail.com>
Tue, 10 May 2022 17:26:24 +0000 (20:26 +0300)
committerGitHub <noreply@github.com>
Tue, 10 May 2022 17:26:24 +0000 (19:26 +0200)
include/vector2d.h
include/vector3d.h

index 08672a38e5b388a2955087cab95e03c71dbad965..a0eb7ea821b8615ed4c58b239ade51562afee520 100644 (file)
@@ -8,6 +8,8 @@
 #include "irrMath.h"\r
 #include "dimension2d.h"\r
 \r
+#include <functional>\r
+\r
 namespace irr\r
 {\r
 namespace core\r
@@ -414,5 +416,21 @@ public:
 } // end namespace core\r
 } // end namespace irr\r
 \r
+namespace std\r
+{\r
+\r
+template<class T>\r
+struct hash<irr::core::vector2d<T> >\r
+{\r
+       size_t operator()(const irr::core::vector2d<T>& vec) const\r
+       {\r
+               size_t h1 = hash<T>()(vec.X);\r
+               size_t h2 = hash<T>()(vec.Y);\r
+               return (h1 << (4 * sizeof(h1)) | h1 >> (4 * sizeof(h1))) ^ h2;\r
+       }\r
+};\r
+\r
+}\r
+\r
 #endif\r
 \r
index 4dbc53b844df2249f96e482e442fe91a7843b451..ed910e9f29bea6fe777e807a62a2f84eb8310faf 100644 (file)
@@ -7,6 +7,8 @@
 \r
 #include "irrMath.h"\r
 \r
+#include <functional>\r
+\r
 namespace irr\r
 {\r
 namespace core\r
@@ -466,5 +468,22 @@ namespace core
 } // end namespace core\r
 } // end namespace irr\r
 \r
+namespace std\r
+{\r
+\r
+template<class T>\r
+struct hash<irr::core::vector3d<T> >\r
+{\r
+       size_t operator()(const irr::core::vector3d<T>& vec) const\r
+       {\r
+               size_t h1 = hash<T>()(vec.X);\r
+               size_t h2 = hash<T>()(vec.Y);\r
+               size_t h3 = hash<T>()(vec.Z);\r
+               return (h1 << (5 * sizeof(h1)) | h1 >> (3 * sizeof(h1))) ^ (h2 << (2 * sizeof(h2)) | h2 >> (6 * sizeof(h2))) ^ h3;\r
+       }\r
+};\r
+\r
+}\r
+\r
 #endif\r
 \r