diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-14 09:02:23 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-14 09:29:05 +0200 |
commit | c077f0f904cce505e15543b855b4330ca547b53d (patch) | |
tree | 2ecddfb72651edeccde1b6cf0c044ed9a63dcfab /src/world.cpp | |
parent | dd12320061e18236838b5836fc1de4b033f581ad (diff) |
replace hash with fnv1
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/world.cpp b/src/world.cpp index 46a65f64..fd6e4cbb 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -6,21 +6,15 @@ using namespace floormat; -size_t std::hash<chunk_coords_>::operator()(const chunk_coords_& coord) const noexcept -{ - std::size_t x = 0; - - x |= size_t(uint16_t(coord.y)) << 16; - x |= size_t(uint16_t(coord.x)); - if constexpr(sizeof(size_t) > 4) - x |= size_t(uint8_t(coord.z- chunk_z_min) & 0xf) << 32; - else - x ^= size_t(uint8_t(coord.z- chunk_z_min) & 0xf) * size_t(1664525); +size_t world::object_id_hasher::operator()(object_id id) const noexcept { return (size_t)int_hash(id); } - if constexpr(sizeof(size_t) > 4) - return int_hash(uint64_t(x)); - else - return int_hash(uint32_t(x)); +size_t world::chunk_coords_hasher::operator()(const chunk_coords_& coord) const noexcept +{ + uint64_t x = 0; + x |= uint64_t((uint16_t)coord.x) << 0; + x |= uint64_t((uint16_t)coord.y) << 16; + x |= uint64_t( (uint8_t)coord.z) << 32; + return (size_t)int_hash(x); } namespace floormat { |