diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-08 08:20:12 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-08 10:38:53 +0200 |
commit | 39670daf26c4fbbfe9148dec30c9f0e075eff404 (patch) | |
tree | 50778183928c5aad1a9308a86852bb4a68581b30 /compat | |
parent | 63edd105d758a39b856f9099b339de30895df8ac (diff) |
improve hash api and hash test
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; |