summaryrefslogtreecommitdiff
path: root/absl/container/internal/raw_hash_set_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2024-02-07 15:26:28 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2024-02-07 15:27:13 -0800
commit0be9f99723eba44462245013d6a433c1ad9157ee (patch)
tree9de6a37384a7e9b28bd7f13fcf67f0e646d01839 /absl/container/internal/raw_hash_set_test.cc
parent3e59efa2ad1d1777257bd3b1845d5acc4a931687 (diff)
Avoid hash computation and `Group::Match` in small tables copy and use `IterateOverFullSlots` for iterating for all tables.
PiperOrigin-RevId: 605116090 Change-Id: Ia65c664421f7630225b00f1c45c636b4681121ce
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r--absl/container/internal/raw_hash_set_test.cc46
1 files changed, 44 insertions, 2 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 5852904f..1c428ea7 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -1765,6 +1765,40 @@ TEST(Table, CopyConstruct) {
}
}
+TEST(Table, CopyDifferentSizes) {
+ IntTable t;
+
+ for (int i = 0; i < 100; ++i) {
+ t.emplace(i);
+ IntTable c = t;
+ for (int j = 0; j <= i; ++j) {
+ ASSERT_TRUE(c.find(j) != c.end()) << "i=" << i << " j=" << j;
+ }
+ // Testing find miss to verify that table is not full.
+ ASSERT_TRUE(c.find(-1) == c.end());
+ }
+}
+
+TEST(Table, CopyDifferentCapacities) {
+ for (int cap = 1; cap < 100; cap = cap * 2 + 1) {
+ IntTable t;
+ t.reserve(static_cast<size_t>(cap));
+ for (int i = 0; i <= cap; ++i) {
+ t.emplace(i);
+ if (i != cap && i % 5 != 0) {
+ continue;
+ }
+ IntTable c = t;
+ for (int j = 0; j <= i; ++j) {
+ ASSERT_TRUE(c.find(j) != c.end())
+ << "cap=" << cap << " i=" << i << " j=" << j;
+ }
+ // Testing find miss to verify that table is not full.
+ ASSERT_TRUE(c.find(-1) == c.end());
+ }
+ }
+}
+
TEST(Table, CopyConstructWithAlloc) {
StringTable t;
t.emplace("a", "b");
@@ -2747,7 +2781,9 @@ TEST(Table, CountedHash) {
TEST(Table, IterateOverFullSlotsEmpty) {
IntTable t;
- auto fail_if_any = [](int64_t* i) { FAIL() << "expected no slots " << i; };
+ auto fail_if_any = [](const ctrl_t*, int64_t* i) {
+ FAIL() << "expected no slots " << i;
+ };
container_internal::IterateOverFullSlots(
RawHashSetTestOnlyAccess::GetCommon(t),
RawHashSetTestOnlyAccess::GetSlots(t), fail_if_any);
@@ -2771,7 +2807,13 @@ TEST(Table, IterateOverFullSlotsFull) {
container_internal::IterateOverFullSlots(
RawHashSetTestOnlyAccess::GetCommon(t),
RawHashSetTestOnlyAccess::GetSlots(t),
- [&slots](int64_t* i) { slots.push_back(*i); });
+ [&t, &slots](const ctrl_t* ctrl, int64_t* i) {
+ ptrdiff_t ctrl_offset =
+ ctrl - RawHashSetTestOnlyAccess::GetCommon(t).control();
+ ptrdiff_t slot_offset = i - RawHashSetTestOnlyAccess::GetSlots(t);
+ ASSERT_EQ(ctrl_offset, slot_offset);
+ slots.push_back(*i);
+ });
EXPECT_THAT(slots, testing::UnorderedElementsAreArray(expected_slots));
}
}