From 461481e6bb8149c07121eb85a984e6393fa2b80d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 8 Jun 2024 12:17:46 +0200 Subject: [PATCH] add hash() member function to global_coords --- src/global-coords.cpp | 7 +++++++ src/global-coords.hpp | 2 ++ test/hash.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/global-coords.cpp b/src/global-coords.cpp index 4f3797f2..549a49ae 100644 --- a/src/global-coords.cpp +++ b/src/global-coords.cpp @@ -1,5 +1,6 @@ #include "global-coords.hpp" #include "point.inl" +#include "compat/hash.hpp" #include #include @@ -32,6 +33,12 @@ Debug& operator<<(Debug& dbg, const chunk_coords_& c) return dbg; } +size_t global_coords::hash() const noexcept +{ + static_assert(sizeof *this == 4 + 4); + return hash_buf(this, sizeof *this); +} + namespace { static_assert(sizeof(decltype(local_coords::x))*8 == 8); diff --git a/src/global-coords.hpp b/src/global-coords.hpp index 031b84d7..67547f4d 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -138,6 +138,8 @@ struct global_coords final constexpr global_coords& operator+=(Vector2i vec) noexcept; constexpr global_coords& operator-=(Vector2i vec) noexcept; constexpr Vector2i operator-(global_coords other) const noexcept; + + size_t hash() const noexcept; }; constexpr local_coords global_coords::local() const noexcept diff --git a/test/hash.cpp b/test/hash.cpp index b5eed2b0..63a2f568 100644 --- a/test/hash.cpp +++ b/test/hash.cpp @@ -44,7 +44,7 @@ template for (int8_t k = 0; k <= ZMax; k++) { auto p = global_coords{i, j, k}; - auto h = hash_buf(&p, sizeof p); + auto h = p.hash(); h %= BucketCount; auto ref = bitset[h]; if (ref) [[unlikely]]