diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-09-18 14:39:40 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-09-18 14:39:40 +0200 |
commit | f2f4479ae174233da0deb382760ba5201ccf9223 (patch) | |
tree | d06a1d5f73749dcfcc310a7d0fbb5b0066761e36 /vespalib/src/tests | |
parent | 5e5137cf0ab9cc67452f36b488394458f827b2b0 (diff) |
Use make_for_lookup() member function on existing comparator
to make a new comparator which is used for lookup.
Diffstat (limited to 'vespalib/src/tests')
-rw-r--r-- | vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp | 14 | ||||
-rw-r--r-- | vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp | 18 |
2 files changed, 17 insertions, 15 deletions
diff --git a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp index 4f4c3ac94eb..58fd5b4c356 100644 --- a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp +++ b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp @@ -20,7 +20,7 @@ using vespalib::datastore::EntryRef; using RefT = vespalib::datastore::EntryRefT<22>; using MyAllocator = vespalib::datastore::UniqueStoreAllocator<uint32_t, RefT>; using MyDataStore = vespalib::datastore::DataStoreT<RefT>; -using MyCompare = vespalib::datastore::UniqueStoreComparator<uint32_t, RefT>; +using MyComparator = vespalib::datastore::UniqueStoreComparator<uint32_t, RefT>; using GenerationHandler = vespalib::GenerationHandler; using vespalib::makeLambdaTask; using vespalib::GenerationHolder; @@ -48,7 +48,7 @@ struct DataStoreFixedSizeHashTest : public ::testing::Test GenerationHolder _generation_holder; MyAllocator _allocator; MyDataStore& _store; - std::unique_ptr<const vespalib::datastore::EntryComparator> _comp; + const MyComparator _comparator; std::unique_ptr<FixedSizeHashMap> _hash_map; vespalib::Rand48 _rnd; @@ -70,7 +70,7 @@ DataStoreFixedSizeHashTest::DataStoreFixedSizeHashTest() _generation_holder(), _allocator({}), _store(_allocator.get_data_store()), - _comp(std::make_unique<MyCompare>(_store)), + _comparator(_store), _hash_map(), _rnd() { @@ -106,7 +106,7 @@ DataStoreFixedSizeHashTest::size() const noexcept void DataStoreFixedSizeHashTest::insert(uint32_t key) { - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); std::function<EntryRef(void)> insert_entry([this, key]() -> EntryRef { return _allocator.allocate(key); }); auto& result = _hash_map->add(_hash_map->get_comp(comp), insert_entry); auto ref = result.first.load_relaxed(); @@ -117,7 +117,7 @@ DataStoreFixedSizeHashTest::insert(uint32_t key) void DataStoreFixedSizeHashTest::remove(uint32_t key) { - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); auto result = _hash_map->remove(_hash_map->get_comp(comp)); if (result != nullptr) { auto ref = result->first.load_relaxed(); @@ -130,7 +130,7 @@ DataStoreFixedSizeHashTest::remove(uint32_t key) bool DataStoreFixedSizeHashTest::has_key(uint32_t key) { - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); auto result = _hash_map->find(_hash_map->get_comp(comp)); if (result != nullptr) { auto ref = result->first.load_relaxed(); @@ -270,7 +270,7 @@ TEST_F(DataStoreFixedSizeHashTest, lookups_works_after_insert_and_remove) commit(); } for (auto &kv : expected) { - MyCompare comp(_store, kv.first); + auto comp = _comparator.make_for_lookup(kv.first); EXPECT_EQ(kv.second, _hash_map->find(_hash_map->get_comp(comp)) != nullptr); } } diff --git a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp index eec3a6e6188..9c2369dea08 100644 --- a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp +++ b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp @@ -25,7 +25,7 @@ using vespalib::datastore::ICompactable; using RefT = vespalib::datastore::EntryRefT<22>; using MyAllocator = vespalib::datastore::UniqueStoreAllocator<uint32_t, RefT>; using MyDataStore = vespalib::datastore::DataStoreT<RefT>; -using MyCompare = vespalib::datastore::UniqueStoreComparator<uint32_t, RefT>; +using MyComparator = vespalib::datastore::UniqueStoreComparator<uint32_t, RefT>; using MyHashMap = vespalib::datastore::ShardedHashMap; using GenerationHandler = vespalib::GenerationHandler; using vespalib::makeLambdaTask; @@ -101,6 +101,7 @@ struct DataStoreShardedHashTest : public ::testing::Test GenerationHandler _generationHandler; MyAllocator _allocator; MyDataStore& _store; + const MyComparator _comparator; MyHashMap _hash_map; vespalib::ThreadStackExecutor _writer; // 1 write thread vespalib::ThreadStackExecutor _readers; // multiple reader threads @@ -134,7 +135,8 @@ DataStoreShardedHashTest::DataStoreShardedHashTest() : _generationHandler(), _allocator({}), _store(_allocator.get_data_store()), - _hash_map(std::make_unique<MyCompare>(_store)), + _comparator(_store), + _hash_map(std::make_unique<MyComparator>(_comparator)), _writer(1), _readers(4), _rnd(), @@ -178,7 +180,7 @@ DataStoreShardedHashTest::commit() void DataStoreShardedHashTest::insert(uint32_t key) { - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); std::function<EntryRef(void)> insert_entry([this, key]() -> EntryRef { return _allocator.allocate(key); }); auto& result = _hash_map.add(comp, EntryRef(), insert_entry); auto ref = result.first.load_relaxed(); @@ -189,7 +191,7 @@ DataStoreShardedHashTest::insert(uint32_t key) void DataStoreShardedHashTest::remove(uint32_t key) { - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); auto result = _hash_map.remove(comp, EntryRef()); if (result != nullptr) { auto ref = result->first.load_relaxed(); @@ -210,7 +212,7 @@ DataStoreShardedHashTest::read_work(uint32_t cnt) for (i = 0; i < cnt && _stop_read.load() == 0; ++i) { auto guard = _generationHandler.takeGuard(); uint32_t key = rnd.lrand48() % (_keyLimit + 1); - MyCompare comp(_store, key); + auto comp = _comparator.make_for_lookup(key); auto result = _hash_map.find(comp, EntryRef()); if (result != nullptr) { auto ref = result->first.load_relaxed(); @@ -264,7 +266,7 @@ void DataStoreShardedHashTest::populate_sample_values(uint32_t cnt) { for (uint32_t i = 0; i < cnt; ++i) { - MyCompare comp(_store, i); + auto comp = _comparator.make_for_lookup(i); auto result = _hash_map.find(comp, EntryRef()); ASSERT_NE(result, nullptr); EXPECT_EQ(i, _allocator.get_wrapped(result->first.load_relaxed()).value()); @@ -276,7 +278,7 @@ void DataStoreShardedHashTest::clear_sample_values(uint32_t cnt) { for (uint32_t i = 0; i < cnt; ++i) { - MyCompare comp(_store, i); + auto comp = _comparator.make_for_lookup(i); auto result = _hash_map.find(comp, EntryRef()); ASSERT_NE(result, nullptr); EXPECT_EQ(i, _allocator.get_wrapped(result->first.load_relaxed()).value()); @@ -312,7 +314,7 @@ DataStoreShardedHashTest::test_normalize_values(bool use_filter, bool one_filter EXPECT_TRUE(_hash_map.normalize_values([](EntryRef ref) noexcept { RefT iref(ref); return RefT(iref.offset() + 300, iref.bufferId()); })); } for (uint32_t i = 0; i < large_population; ++i) { - MyCompare comp(_store, i); + auto comp = _comparator.make_for_lookup(i); auto result = _hash_map.find(comp, EntryRef()); ASSERT_NE(result, nullptr); EXPECT_EQ(i, _allocator.get_wrapped(result->first.load_relaxed()).value()); |