diff options
Diffstat (limited to 'absl/container/internal')
-rw-r--r-- | absl/container/internal/hash_function_defaults.h | 5 | ||||
-rw-r--r-- | absl/container/internal/raw_hash_set.h | 17 | ||||
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 4 |
3 files changed, 15 insertions, 11 deletions
diff --git a/absl/container/internal/hash_function_defaults.h b/absl/container/internal/hash_function_defaults.h index dd6cd8f5..1f0d794d 100644 --- a/absl/container/internal/hash_function_defaults.h +++ b/absl/container/internal/hash_function_defaults.h @@ -83,11 +83,6 @@ struct StringHashEq { } }; }; - -#if defined(HAS_GLOBAL_STRING) -template <> -struct HashEq<std::string> : StringHashEq {}; -#endif template <> struct HashEq<std::string> : StringHashEq {}; template <> diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 0c0e5906..70da90f7 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -1330,8 +1330,7 @@ class raw_hash_set { void rehash(size_t n) { if (n == 0 && capacity_ == 0) return; if (n == 0 && size_ == 0) return destroy_slots(); - auto m = NormalizeCapacity(std::max( - n, static_cast<size_t>(std::ceil(size() / kMaxLoadFactor)))); + auto m = NormalizeCapacity(std::max(n, NumSlotsFast(size()))); // n == 0 unconditionally rehashes as per the standard. if (n == 0 || m > capacity_) { resize(m); @@ -1339,7 +1338,7 @@ class raw_hash_set { } void reserve(size_t n) { - rehash(static_cast<size_t>(std::ceil(n / kMaxLoadFactor))); + rehash(NumSlotsFast(n)); } // Extension API: support for heterogeneous keys. @@ -1518,6 +1517,13 @@ class raw_hash_set { slot_type&& slot; }; + // Computes std::ceil(n / kMaxLoadFactor). Faster than calling std::ceil. + static inline size_t NumSlotsFast(size_t n) { + return static_cast<size_t>( + (n * kMaxLoadFactorDenominator + (kMaxLoadFactorNumerator - 1)) / + kMaxLoadFactorNumerator); + } + // "erases" the object from the container, except that it doesn't actually // destroy the object. It only updates all the metadata of the class. // This can be used in conjunction with Policy::transfer to move the object to @@ -1825,7 +1831,10 @@ class raw_hash_set { } // On average each group has 2 empty slot (for the vectorized case). - static constexpr float kMaxLoadFactor = 14.0 / 16.0; + static constexpr int64_t kMaxLoadFactorNumerator = 14; + static constexpr int64_t kMaxLoadFactorDenominator = 16; + static constexpr float kMaxLoadFactor = + 1.0 * kMaxLoadFactorNumerator / kMaxLoadFactorDenominator; // TODO(alkis): Investigate removing some of these fields: // - ctrl/slots can be derived from each other diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index f59a19b4..cd33a3ac 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -1916,7 +1916,7 @@ TEST(Table, EffectiveLoadFactorInts) { } // Confirm that we assert if we try to erase() end(). -TEST(Table, EraseOfEndAsserts) { +TEST(TableDeathTest, EraseOfEndAsserts) { // Use an assert with side-effects to figure out if they are actually enabled. bool assert_enabled = false; assert([&]() { @@ -1928,7 +1928,7 @@ TEST(Table, EraseOfEndAsserts) { IntTable t; // Extra simple "regexp" as regexp support is highly varied across platforms. constexpr char kDeathMsg[] = "it != end"; - EXPECT_DEATH(t.erase(t.end()), kDeathMsg); + EXPECT_DEATH_IF_SUPPORTED(t.erase(t.end()), kDeathMsg); } #ifdef ADDRESS_SANITIZER |