summaryrefslogtreecommitdiffhomepage
path: root/attic/int-hash.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-14 08:54:55 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-14 08:54:55 +0200
commitd4b8d17cfa36ef78cd765a4da8c63a440b83cc47 (patch)
treea45564e3a0fd45c32891f5fe4b349c4599c8e834 /attic/int-hash.cpp
parent5d5c0c3020cca1681f9e368804f0ae712c2bf1b5 (diff)
add hash tests
Diffstat (limited to 'attic/int-hash.cpp')
-rw-r--r--attic/int-hash.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/attic/int-hash.cpp b/attic/int-hash.cpp
new file mode 100644
index 00000000..00f2e474
--- /dev/null
+++ b/attic/int-hash.cpp
@@ -0,0 +1,37 @@
+#include "int-hash.hpp"
+#include <bit>
+
+namespace floormat {
+
+size_t int_hash(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_hash(uint64_t(x));
+}
+
+size_t int_hash(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