diff --git a/include/omath/linear_algebra/vector2.hpp b/include/omath/linear_algebra/vector2.hpp index 4dc96c7..2994144 100644 --- a/include/omath/linear_algebra/vector2.hpp +++ b/include/omath/linear_algebra/vector2.hpp @@ -234,6 +234,21 @@ namespace omath }; } // namespace omath +template<> struct std::hash> +{ + [[nodiscard]] + std::size_t operator()(const omath::Vector2& vec) const noexcept + { + std::size_t hash = 0; + constexpr std::hash hasher; + + hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + + return hash; + } +}; + template struct std::formatter> // NOLINT(*-dcl58-cpp) { diff --git a/include/omath/linear_algebra/vector3.hpp b/include/omath/linear_algebra/vector3.hpp index 7e5838f..77d60cf 100644 --- a/include/omath/linear_algebra/vector3.hpp +++ b/include/omath/linear_algebra/vector3.hpp @@ -273,6 +273,7 @@ namespace omath template<> struct std::hash> { + [[nodiscard]] std::size_t operator()(const omath::Vector3& vec) const noexcept { std::size_t hash = 0; diff --git a/include/omath/linear_algebra/vector4.hpp b/include/omath/linear_algebra/vector4.hpp index d1e1377..25d6a6d 100644 --- a/include/omath/linear_algebra/vector4.hpp +++ b/include/omath/linear_algebra/vector4.hpp @@ -202,6 +202,22 @@ namespace omath }; } // namespace omath +template<> struct std::hash> +{ + [[nodiscard]] + std::size_t operator()(const omath::Vector4& vec) const noexcept + { + std::size_t hash = 0; + constexpr std::hash hasher; + + hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.w) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + return hash; + } +}; + template struct std::formatter> // NOLINT(*-dcl58-cpp) {