diff options
author | Evan Brown <ezb@google.com> | 2023-03-02 10:03:38 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-02 10:04:18 -0800 |
commit | d51d3cf3feacf836f1acfe6c97c10978077599ab (patch) | |
tree | 66375048493b39def4527ae286a929cf0521d29f /absl/container/internal/raw_hash_set.cc | |
parent | 4ae8771a314abe8b0e85cee3be3ead30451c63e7 (diff) | |
download | abseil-d51d3cf3feacf836f1acfe6c97c10978077599ab.tar.gz abseil-d51d3cf3feacf836f1acfe6c97c10978077599ab.tar.bz2 abseil-d51d3cf3feacf836f1acfe6c97c10978077599ab.zip |
Use multiple empty generations so that we can detect when iterators from different empty hashtables are compared.
PiperOrigin-RevId: 513568915
Change-Id: I3f387d0bae0e86749dff540e4fdd5037304ac975
Diffstat (limited to 'absl/container/internal/raw_hash_set.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/absl/container/internal/raw_hash_set.cc b/absl/container/internal/raw_hash_set.cc index a6d9b7c0..b91d5a47 100644 --- a/absl/container/internal/raw_hash_set.cc +++ b/absl/container/internal/raw_hash_set.cc @@ -28,19 +28,18 @@ namespace container_internal { // A single block of empty control bytes for tables without any slots allocated. // This enables removing a branch in the hot path of find(). -// We have 17 bytes because there may be a generation counter. Any constant is -// fine for the generation counter. -alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[17] = { +alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[16] = { ctrl_t::kSentinel, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - static_cast<ctrl_t>(0)}; + ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty}; #ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL constexpr size_t Group::kWidth; #endif +namespace { + // Returns "random" seed. inline size_t RandomSeed() { #ifdef ABSL_HAVE_THREAD_LOCAL @@ -58,6 +57,18 @@ inline size_t RandomSeed() { return value ^ static_cast<size_t>(reinterpret_cast<uintptr_t>(&counter)); } +} // namespace + +GenerationType* EmptyGeneration() { + if (SwisstableGenerationsEnabled()) { + constexpr size_t kNumEmptyGenerations = 1024; + static constexpr GenerationType kEmptyGenerations[kNumEmptyGenerations]{}; + return const_cast<GenerationType*>( + &kEmptyGenerations[RandomSeed() % kNumEmptyGenerations]); + } + return nullptr; +} + bool CommonFieldsGenerationInfoEnabled:: should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl, size_t capacity) const { |