diff options
author | Abseil Team <absl-team@google.com> | 2024-01-31 13:45:52 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-01-31 13:46:58 -0800 |
commit | 4c7e7c7d94eaaa3bff3142c257d880a468a35934 (patch) | |
tree | b8418ca1620a45c7c772945194e9537165ac13f4 /absl/container/internal/raw_hash_set.h | |
parent | 780bfc194d807dbd56363635ca40bf96743aa00b (diff) | |
download | abseil-4c7e7c7d94eaaa3bff3142c257d880a468a35934.tar.gz abseil-4c7e7c7d94eaaa3bff3142c257d880a468a35934.tar.bz2 abseil-4c7e7c7d94eaaa3bff3142c257d880a468a35934.zip |
Type erased hash_slot_fn that depends only on key types (and hash function).
PiperOrigin-RevId: 603148301
Change-Id: Ie2e5702995c9e1ef4d5aaab23bc89a1eb5007a86
Diffstat (limited to 'absl/container/internal/raw_hash_set.h')
-rw-r--r-- | absl/container/internal/raw_hash_set.h | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index c464de6a..3b793825 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -1802,7 +1802,7 @@ struct PolicyFunctions { size_t slot_size; // Returns the hash of the pointed-to slot. - size_t (*hash_slot)(void* set, void* slot); + size_t (*hash_slot)(const void* hash_fn, void* slot); // Transfer the contents of src_slot to dst_slot. void (*transfer)(void* set, void* dst_slot, void* src_slot); @@ -1847,7 +1847,7 @@ ABSL_ATTRIBUTE_NOINLINE void TransferRelocatable(void*, void* dst, void* src) { } // Type-erased version of raw_hash_set::drop_deletes_without_resize. -void DropDeletesWithoutResize(CommonFields& common, +void DropDeletesWithoutResize(CommonFields& common, const void* hash_fn, const PolicyFunctions& policy, void* tmp_space); // A SwissTable. @@ -2989,7 +2989,7 @@ class raw_hash_set { inline void drop_deletes_without_resize() { // Stack-allocate space for swapping elements. alignas(slot_type) unsigned char tmp[sizeof(slot_type)]; - DropDeletesWithoutResize(common(), GetPolicyFunctions(), tmp); + DropDeletesWithoutResize(common(), &hash_ref(), GetPolicyFunctions(), tmp); } // Called whenever the table *might* need to conditionally grow. @@ -3238,13 +3238,6 @@ class raw_hash_set { return settings_.template get<3>(); } - // Make type-specific functions for this type's PolicyFunctions struct. - static size_t hash_slot_fn(void* set, void* slot) { - auto* h = static_cast<raw_hash_set*>(set); - return PolicyTraits::apply( - HashElement{h->hash_ref()}, - PolicyTraits::element(static_cast<slot_type*>(slot))); - } static void transfer_slot_fn(void* set, void* dst, void* src) { auto* h = static_cast<raw_hash_set*>(set); h->transfer(static_cast<slot_type*>(dst), static_cast<slot_type*>(src)); @@ -3266,7 +3259,7 @@ class raw_hash_set { static const PolicyFunctions& GetPolicyFunctions() { static constexpr PolicyFunctions value = { sizeof(slot_type), - &raw_hash_set::hash_slot_fn, + PolicyTraits::template get_hash_slot_fn<hasher>(), PolicyTraits::transfer_uses_memcpy() ? TransferRelocatable<sizeof(slot_type)> : &raw_hash_set::transfer_slot_fn, |