utils: hashing: use simple_xx_hasher
Use simple_xx_hasher for bytes_view and effective_replication_map::factory_key appending hashers instead of their custom, yet identical implementations. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
15
bytes.hh
15
bytes.hh
@@ -17,7 +17,7 @@
|
||||
#include <functional>
|
||||
#include <compare>
|
||||
#include "utils/mutable_view.hh"
|
||||
#include <xxhash.h>
|
||||
#include "utils/simple_hashers.hh"
|
||||
|
||||
using bytes = basic_sstring<int8_t, uint32_t, 31, false>;
|
||||
using bytes_view = std::basic_string_view<int8_t>;
|
||||
@@ -160,18 +160,7 @@ struct appending_hash<bytes_view> {
|
||||
}
|
||||
};
|
||||
|
||||
struct bytes_view_hasher : public hasher {
|
||||
XXH64_state_t _state;
|
||||
bytes_view_hasher(uint64_t seed = 0) noexcept {
|
||||
XXH64_reset(&_state, seed);
|
||||
}
|
||||
void update(const char* ptr, size_t length) noexcept {
|
||||
XXH64_update(&_state, ptr, length);
|
||||
}
|
||||
size_t finalize() {
|
||||
return static_cast<size_t>(XXH64_digest(&_state));
|
||||
}
|
||||
};
|
||||
using bytes_view_hasher = simple_xx_hasher;
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <seastar/util/bool_class.hh>
|
||||
#include "utils/maybe_yield.hh"
|
||||
#include "utils/sequenced_set.hh"
|
||||
#include "utils/simple_hashers.hh"
|
||||
|
||||
// forward declaration since replica/database.hh includes this file
|
||||
namespace replica {
|
||||
@@ -325,25 +326,12 @@ struct appending_hash<locator::effective_replication_map::factory_key> {
|
||||
}
|
||||
};
|
||||
|
||||
struct factory_key_hasher : public hasher {
|
||||
XXH64_state_t _state;
|
||||
factory_key_hasher(uint64_t seed = 0) noexcept {
|
||||
XXH64_reset(&_state, seed);
|
||||
}
|
||||
void update(const char* ptr, size_t length) noexcept {
|
||||
XXH64_update(&_state, ptr, length);
|
||||
}
|
||||
size_t finalize() {
|
||||
return static_cast<size_t>(XXH64_digest(&_state));
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<locator::effective_replication_map::factory_key> {
|
||||
size_t operator()(const locator::effective_replication_map::factory_key& key) const {
|
||||
factory_key_hasher h;
|
||||
simple_xx_hasher h;
|
||||
appending_hash<locator::effective_replication_map::factory_key>{}(h, key);
|
||||
return h.finalize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user