Add hash for vector2d and vector3d (#93)

This commit is contained in:
Richard Try 2022-05-10 20:26:24 +03:00 committed by GitHub
parent 372b3642bf
commit 6928c7eb6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -8,6 +8,8 @@
#include "irrMath.h"
#include "dimension2d.h"
#include <functional>
namespace irr
{
namespace core
@ -414,5 +416,21 @@ public:
} // end namespace core
} // end namespace irr
namespace std
{
template<class T>
struct hash<irr::core::vector2d<T> >
{
size_t operator()(const irr::core::vector2d<T>& vec) const
{
size_t h1 = hash<T>()(vec.X);
size_t h2 = hash<T>()(vec.Y);
return (h1 << (4 * sizeof(h1)) | h1 >> (4 * sizeof(h1))) ^ h2;
}
};
}
#endif

View File

@ -7,6 +7,8 @@
#include "irrMath.h"
#include <functional>
namespace irr
{
namespace core
@ -466,5 +468,22 @@ namespace core
} // end namespace core
} // end namespace irr
namespace std
{
template<class T>
struct hash<irr::core::vector3d<T> >
{
size_t operator()(const irr::core::vector3d<T>& vec) const
{
size_t h1 = hash<T>()(vec.X);
size_t h2 = hash<T>()(vec.Y);
size_t h3 = hash<T>()(vec.Z);
return (h1 << (5 * sizeof(h1)) | h1 >> (3 * sizeof(h1))) ^ (h2 << (2 * sizeof(h2)) | h2 >> (6 * sizeof(h2))) ^ h3;
}
};
}
#endif