summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-10 09:04:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-10 10:35:00 +0200
commit95b940b807eb213e2e86a32f8f4cc98fd6b13400 (patch)
treec42c9ba29424e56e27ed2b81eecf8c2d07dde910 /compat
parent8c2dca2cfaf57f22fe2fe84d939d0071c06ddd6c (diff)
src/world: cleanup & fix hash stuff
Diffstat (limited to 'compat')
-rw-r--r--compat/int-hash.cpp37
-rw-r--r--compat/int-hash.hpp27
2 files changed, 41 insertions, 23 deletions
diff --git a/compat/int-hash.cpp b/compat/int-hash.cpp
new file mode 100644
index 00000000..ae2e6729
--- /dev/null
+++ b/compat/int-hash.cpp
@@ -0,0 +1,37 @@
+#include "int-hash.hpp"
+#include <bit>
+
+namespace floormat {
+
+size_t int_hash32(uint32_t x) noexcept
+{
+ if constexpr(sizeof(size_t) == 4)
+ {
+ // by Chris Wellons <https://nullprogram.com/blog/2018/07/31/>
+
+ x ^= x >> 15;
+ x *= 0x2c1b3c6dU;
+ x ^= x >> 12;
+ x *= 0x297a2d39U;
+ x ^= x >> 15;
+
+ return x;
+ }
+ else
+ return int_hash64(x);
+}
+
+size_t int_hash64(uint64_t x) noexcept
+{
+ // NASAM by Pelle Evensen <https://mostlymangling.blogspot.com/2020/01/nasam-not-another-strange-acronym-mixer.html>
+
+ x ^= std::rotr(x, 25) ^ std::rotr(x, 47);
+ x *= 0x9E6C63D0676A9A99UL;
+ x ^= x >> 23 ^ x >> 51;
+ x *= 0x9E6D62D06F6A9A9BUL;
+ x ^= x >> 23 ^ x >> 51;
+
+ return x;
+}
+
+} // namespace floormat
diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp
index 52b4c170..e5cfc67a 100644
--- a/compat/int-hash.hpp
+++ b/compat/int-hash.hpp
@@ -1,30 +1,11 @@
#pragma once
-#include <bit>
namespace floormat {
-constexpr inline size_t int_hash(size_t x) noexcept
-{
- if constexpr(sizeof(size_t) == 4)
- {
- // by Chris Wellons <https://nullprogram.com/blog/2018/07/31/>
- x ^= x >> 15;
- x *= 0x2c1b3c6dU;
- x ^= x >> 12;
- x *= 0x297a2d39U;
- x ^= x >> 15;
- }
- else if constexpr(sizeof(size_t) == 8)
- {
- // NASAM by Pelle Evensen <https://mostlymangling.blogspot.com/2020/01/nasam-not-another-strange-acronym-mixer.html>
- x ^= std::rotr(x, 25) ^ std::rotr(x, 47);
- x *= 0x9E6C63D0676A9A99UL;
- x ^= x >> 23 ^ x >> 51;
- x *= 0x9E6D62D06F6A9A9BUL;
- x ^= x >> 23 ^ x >> 51;
- }
+size_t int_hash32(uint32_t x) noexcept;
+size_t int_hash64(uint64_t x) noexcept;
- return x;
-}
+inline size_t int_hash(uint32_t x) noexcept { return int_hash32(x); }
+inline size_t int_hash(uint64_t x) noexcept { return int_hash64(x); }
} // namespace floormat