diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/int-hash.cpp | 26 | ||||
-rw-r--r-- | compat/int-hash.hpp | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/compat/int-hash.cpp b/compat/int-hash.cpp index a15fae29..0ab83c6c 100644 --- a/compat/int-hash.cpp +++ b/compat/int-hash.cpp @@ -34,6 +34,32 @@ fm_UNROLL_8 } // namespace +uint64_t fnvhash_64(const void* str_, size_t size) +{ + const auto *str = (const char*)str_, *end = str + size; + uint32_t hash = 0x811c9dc5u; +fm_UNROLL_4 + for (; str != end; ++str) + { + hash *= 0x01000193u; + hash ^= (uint8_t)*str; + } + return hash; +} + +uint64_t fnvhash_32(const void* str_, size_t size) +{ + const auto *str = (const char*)str_, *end = str + size; + uint64_t hash = 0xcbf29ce484222325u; +fm_UNROLL_4 + for (; str != end; ++str) + { + hash *= 0x100000001b3u; + hash ^= (uint8_t)*str; + } + return hash; +} + size_t int_hash(uint32_t x) noexcept { if constexpr(sizeof(size_t) == 4) diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp index 2266bb4d..6a6cbcd4 100644 --- a/compat/int-hash.hpp +++ b/compat/int-hash.hpp @@ -5,4 +5,7 @@ namespace floormat { size_t int_hash(uint32_t x) noexcept; size_t int_hash(uint64_t x) noexcept; +uint64_t fnvhash_64(const void* str, size_t size); +uint64_t fnvhash_32(const void* str, size_t size); + } // namespace floormat |