From ceffe8d2de09b49232c6fd9214ab0b2e4782042b Mon Sep 17 00:00:00 2001 From: Stefan Hermann Date: Tue, 12 Nov 2024 16:01:15 +0100 Subject: [PATCH] perf and bugfix --- include/utils/hasher.hpp | 13 ++++++------- src/example.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/utils/hasher.hpp b/include/utils/hasher.hpp index 093b8fa..1185db5 100644 --- a/include/utils/hasher.hpp +++ b/include/utils/hasher.hpp @@ -2,7 +2,6 @@ // See also https://github.com/jermp/bench_hash_functions -#include #include namespace pthash { @@ -171,7 +170,7 @@ struct murmurhash2_64 { typedef hash64 hash_type; // generic range of bytes - static inline hash64 hash(byte_range range, uint64_t seed) { + static inline hash64 hash(byte_range const& range, uint64_t seed) { return MurmurHash2_64(range.begin, range.end - range.begin, seed); } @@ -181,7 +180,7 @@ struct murmurhash2_64 { } // specialization for uint64_t - static inline hash64 hash(uint64_t val, uint64_t seed) { + static inline hash64 hash(uint64_t const& val, uint64_t seed) { return MurmurHash2_64(reinterpret_cast(&val), sizeof(val), seed); } }; @@ -190,7 +189,7 @@ struct murmurhash2_128 { typedef hash128 hash_type; // generic range of bytes - static inline hash128 hash(byte_range range, uint64_t seed) { + static inline hash128 hash(byte_range const& range, uint64_t seed) { return {MurmurHash2_64(range.begin, range.end - range.begin, seed), MurmurHash2_64(range.begin, range.end - range.begin, ~seed)}; } @@ -202,7 +201,7 @@ struct murmurhash2_128 { } // specialization for uint64_t - static inline hash128 hash(uint64_t val, uint64_t seed) { + static inline hash128 hash(uint64_t const& val, uint64_t seed) { return {MurmurHash2_64(reinterpret_cast(&val), sizeof(val), seed), MurmurHash2_64(reinterpret_cast(&val), sizeof(val), ~seed)}; } @@ -217,12 +216,12 @@ struct xxhash128 { } // specialization for uint64_t - static inline hash_type hash(uint64_t val, uint64_t seed) { + static inline hash_type hash(uint64_t const& val, uint64_t seed) { return XXH128(&val, sizeof(val), seed); } // specialization for std::pair - static inline hash_type hash(std::pair val, uint64_t seed) { + static inline hash_type hash(std::pair const& val, uint64_t seed) { return XXH128(&val, sizeof(val), seed); } }; diff --git a/src/example.cpp b/src/example.cpp index 34bcd28..9a72419 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -41,7 +41,7 @@ int main() { // pthash_type; typedef dense_partitioned_phf, // bucketer inter_R, // encoder type true, // minimal pthash_search_type::add_displacement // additive displacement