Skip to content

Commit 461481e

Browse files
committed
add hash() member function to global_coords
1 parent 53d61d8 commit 461481e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/global-coords.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "global-coords.hpp"
22
#include "point.inl"
3+
#include "compat/hash.hpp"
34
#include <array>
45
#include <algorithm>
56

@@ -32,6 +33,12 @@ Debug& operator<<(Debug& dbg, const chunk_coords_& c)
3233
return dbg;
3334
}
3435

36+
size_t global_coords::hash() const noexcept
37+
{
38+
static_assert(sizeof *this == 4 + 4);
39+
return hash_buf(this, sizeof *this);
40+
}
41+
3542
namespace {
3643

3744
static_assert(sizeof(decltype(local_coords::x))*8 == 8);

src/global-coords.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct global_coords final
138138
constexpr global_coords& operator+=(Vector2i vec) noexcept;
139139
constexpr global_coords& operator-=(Vector2i vec) noexcept;
140140
constexpr Vector2i operator-(global_coords other) const noexcept;
141+
142+
size_t hash() const noexcept;
141143
};
142144

143145
constexpr local_coords global_coords::local() const noexcept

test/hash.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ template<int16_t CoordMax, int8_t ZMax, uint32_t MaxCollisions>
4444
for (int8_t k = 0; k <= ZMax; k++)
4545
{
4646
auto p = global_coords{i, j, k};
47-
auto h = hash_buf(&p, sizeof p);
47+
auto h = p.hash();
4848
h %= BucketCount;
4949
auto ref = bitset[h];
5050
if (ref) [[unlikely]]

0 commit comments

Comments
 (0)