38#include <gtest/gtest.h>
58 auto* ptr = table.
insert(1,
"one");
63 auto*
found = table.search(1);
70 table.insert(1,
"one");
72 auto*
found = table.search(2);
78 table.insert(1,
"one");
79 table.insert(2,
"two");
80 table.insert(3,
"three");
89 auto* ptr = table.insert(1,
"one");
90 table.insert(2,
"two");
100 table.insert(1,
"one");
102 auto* ptr = table.search(1);
117 auto*
found = table.search(1);
132 table.insert(1,
"one");
134 std::string val = table[1];
140 table.insert(1,
"one");
144 std::string val = table[2];
145 }, std::invalid_argument);
155 table.insert(2,
"two");
163 *table.search(1) =
"ONE";
169 table.insert(1,
"one");
170 table.insert(2,
"two");
184 table.insert(1,
"one");
185 table.insert(2,
"two");
195 table.insert(1,
"one");
196 table.insert(2,
"two");
199 other = std::move(table);
207 table.insert(1,
"one");
236 std::string
longKey(1000,
'x');
252 for (
int i = 0; i < 100; ++i)
253 table.
insert(i,
"val" + std::to_string(i));
256 for (
int i = 0; i < 100; ++i)
268 std::string value =
"hello";
269 table.
insert(1, std::move(value));
279 std::string key =
"key";
280 std::string value =
"value";
281 table.
insert(std::move(key), std::move(value));
295 for (
int i = 0; i <
N; ++i)
298 for (
int i = 0; i <
N; ++i)
310 for (
int i = 0; i <
N; ++i)
314 for (
int i = 0; i <
N / 2; ++i)
318 for (
int i =
N / 2; i <
N; ++i)
322 for (
int i = 0; i <
N / 2; ++i)
329 std::map<int, int*> reference;
331 std::mt19937
rng(42);
332 std::uniform_int_distribution<>
key_dist(0, 999);
333 std::uniform_int_distribution<>
op_dist(0, 2);
342 if (reference.count(key) == 0)
344 auto* ptr = table.
insert(key, key * 2);
345 reference[key] = ptr;
351 if (reference.count(key))
359 if (reference.count(key))
361 table.
remove(reference[key]);
362 reference.erase(key);
368 for (
auto& [key, ptr] : reference)
376 for (
auto& [key, ptr] : reference)
393 table.insert(-1,
"negative one");
394 table.insert(-100,
"negative hundred");
395 table.insert(0,
"zero");
397 EXPECT_EQ(*table.search(-1),
"negative one");
398 EXPECT_EQ(*table.search(-100),
"negative hundred");
409 auto*
found = table.search(1);
424 return static_cast<size_t>(key * 31 + 17);
505 dest = std::move(source);
568 table.
insert(1, std::move(val));
628 const int N = 100000;
631 for (
int i = 0; i <
N; ++i)
635 for (
int i = 0; i <
N; ++i)
646 std::vector<int*>
ptrs;
650 for (
int i = 0; i <
N; ++i)
654 for (
int i = 1; i <
N; i += 2)
661 for (
int i =
N; i <
N +
N/2; ++i)
665 for (
int i = 0; i <
N; i += 2)
673 for (
int i = 1; i <
N; i += 2)
677 for (
int i =
N; i <
N +
N/2; ++i)
691 ::testing::InitGoogleTest(&
argc,
argv);
Dynamic hash table mapping keys to records with separate chaining.
Record * search(const Key &key)
Search for a key in the table.
void remove(Record *record)
Remove an entry from the table.
Record * insert(const Key &key, const Record &record)
Insert a key-record pair into the table.
T & insert(const T &item)
Insert a new item by copy.
DynList & swap(DynList &l) noexcept
Swap this with l.
DynLhashTable< int, std::string > table
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynList< T > maps(const C &c, Op op)
Classic map operation.
ComplexValue & operator=(ComplexValue &&other) noexcept
bool operator==(const ComplexValue &other) const
ComplexValue(const ComplexValue &other)
ComplexValue(const std::string &d, int c)
ComplexValue(ComplexValue &&other) noexcept
ComplexValue & operator=(const ComplexValue &other)
Dynamic hash table mapping keys to records with separate chaining.
TEST_F(DynLhashTableTest, InsertAndSearch)
size_t custom_hash(const int &key)