diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/int-hash.cpp | 28 | ||||
-rw-r--r-- | compat/int-hash.hpp | 1 |
2 files changed, 26 insertions, 3 deletions
diff --git a/compat/int-hash.cpp b/compat/int-hash.cpp index d4f49bd3..6415f0e6 100644 --- a/compat/int-hash.cpp +++ b/compat/int-hash.cpp @@ -10,7 +10,6 @@ namespace { using namespace floormat::Hash; -// todo implement in terms of fnvhash_buf() [[maybe_unused]] CORRADE_ALWAYS_INLINE size_t fnvhash_uint_32(uint32_t x) { @@ -80,8 +79,31 @@ fm_UNROLL_8 return hash; } -size_t hash_int(uint32_t x) noexcept { return fnvhash_uint_32(x); } -size_t hash_int(uint64_t x) noexcept { return fnvhash_uint_64(x); } +size_t hash_buf(const void* buf, size_t size) noexcept +{ +#if 1 + if constexpr(sizeof nullptr > 4) + return hash_64(buf, size); + else +#endif + return hash_32(buf, size); +} + +size_t hash_int(uint32_t x) noexcept +{ +#if 1 + if constexpr(sizeof nullptr > 4) + return fnvhash_uint_64(x); + else +#endif + return fnvhash_uint_32(x); +} + +size_t hash_int(uint64_t x) noexcept +{ + return fnvhash_uint_64(x); +} + size_t hash_string_view::operator()(StringView s) const noexcept { return Hash::fnvhash_buf(s.data(), s.size()); } } // namespace floormat diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp index 27f2651f..c512d249 100644 --- a/compat/int-hash.hpp +++ b/compat/int-hash.hpp @@ -18,6 +18,7 @@ namespace floormat { // todo uint64_t hash_64(const void* buf, size_t size) noexcept; uint32_t hash_32(const void* buf, size_t size) noexcept; +size_t hash_buf(const void* buf, size_t size) noexcept; size_t hash_int(uint32_t x) noexcept; size_t hash_int(uint64_t x) noexcept; |