summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/stllike/hash_test.cpp
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-02-25 16:30:05 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-02-25 16:30:05 +0000
commita3871bdb217657971d24998772618e39b4386340 (patch)
tree59f75a5ed3dbf8e7e793d7c820dcbac33b7c6532 /vespalib/src/tests/stllike/hash_test.cpp
parent830902094e2c13e5e2b511266cd41c905898feda (diff)
- Ensure that hashtable::clear does not touch capacity of hashtable.
- No need to deallocate/reallocate on clear.
Diffstat (limited to 'vespalib/src/tests/stllike/hash_test.cpp')
-rw-r--r--vespalib/src/tests/stllike/hash_test.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/vespalib/src/tests/stllike/hash_test.cpp b/vespalib/src/tests/stllike/hash_test.cpp
index 561c7b34035..59081c0ab73 100644
--- a/vespalib/src/tests/stllike/hash_test.cpp
+++ b/vespalib/src/tests/stllike/hash_test.cpp
@@ -555,7 +555,7 @@ TEST("test that begin and end are identical with empty hashtables") {
EXPECT_TRUE(empty_but_reserved.begin() == empty_but_reserved.end());
}
-TEST ("test that large_allocator works fine with std::vector") {
+TEST("test that large_allocator works fine with std::vector") {
using V = std::vector<uint64_t, allocator_large<uint64_t>>;
V a;
a.push_back(1);
@@ -568,4 +568,18 @@ TEST ("test that large_allocator works fine with std::vector") {
ASSERT_EQUAL(b.size(), c.size());
}
+TEST("test that hash table clear does not resize hashtable") {
+ hash_set<int> a(100);
+ EXPECT_EQUAL(0u, a.size());
+ EXPECT_EQUAL(128u, a.capacity());
+ for (size_t i(0); i < 100; i++) {
+ a.insert(i);
+ }
+ EXPECT_EQUAL(100u, a.size());
+ EXPECT_EQUAL(128u, a.capacity());
+ a.clear();
+ EXPECT_EQUAL(0u, a.size());
+ EXPECT_EQUAL(128u, a.capacity());
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }