42# include <type_traits>
43# include <unordered_set>
45# include <gtest/gtest.h>
63 "HashSet<Key> default backend must be OLhashTable. "
64 "If this changed intentionally, document it as a breaking change.");
68 "HashMap<Key,Data> default backend must be MapOLhash. "
69 "If this changed intentionally, document it as a breaking change.");
73 "DynHashSet<Key> default backend must be OLhashTable.");
76static_assert(std::is_same_v<DynHashMap<int, int>,
78 "DynHashMap<Key,Data> default backend must be MapOLhash.");
87template <
typename Set>
90 std::unordered_set<int> result;
91 s.for_each([&](
const int k) { result.insert(
k); });
95template <
typename Map>
96std::unordered_set<int> collect_keys(Map &
m)
98 std::unordered_set<int> result;
99 m.
for_each([&](
const std::pair<int, std::string> &p) { result.insert(p.first); });
107struct HashSetOLTest : ::testing::Test
114 for (
int i = 0; i <
N; ++i)
117 for (
int i = 0; i <
N; ++i)
118 EXPECT_TRUE(s.contains(i)) <<
"key " << i <<
" missing after insert";
123 for (
int i = 0; i <
N; ++i)
132 for (
int i = 0; i <
N; ++i)
137 for (
int i = 0; i <
N; ++i)
138 EXPECT_TRUE(found.count(i)) <<
"key " << i <<
" missing from iteration";
143 for (
int i = 0; i <
N; ++i)
150 for (
int i = 0; i <
N; ++i)
153 EXPECT_TRUE(s.contains(i)) <<
"key " << i <<
" missing after remove(42)";
162 s.for_each([&](
const int k) {
if (
k == 7) ++
count; });
170struct HashSetODTest : ::testing::Test
177 for (
int i = 0; i <
N; ++i)
180 for (
int i = 0; i <
N; ++i)
181 EXPECT_TRUE(s.contains(i)) <<
"key " << i <<
" missing after insert";
186 for (
int i = 0; i <
N; ++i)
195 for (
int i = 0; i <
N; ++i)
200 for (
int i = 0; i <
N; ++i)
201 EXPECT_TRUE(found.count(i)) <<
"key " << i <<
" missing from iteration";
206 for (
int i = 0; i <
N; ++i)
212 for (
int i = 0; i <
N; ++i)
215 EXPECT_TRUE(s.contains(i)) <<
"key " << i <<
" missing after remove(42)";
228 for (
int i = 0; i <
N; ++i)
241struct HashMapOLTest : ::testing::Test
248 for (
int i = 0; i <
N; ++i)
249 m.
insert(i, std::to_string(i));
251 for (
int i = 0; i <
N; ++i)
254 ASSERT_NE(p,
nullptr) <<
"key " << i <<
" not found";
261 for (
int i = 0; i <
N; ++i)
262 m.
insert(i, std::to_string(i));
270 for (
int i = 0; i <
N; ++i)
271 m.
insert(i, std::to_string(i));
273 auto keys = collect_keys(
m);
275 for (
int i = 0; i <
N; ++i)
276 EXPECT_TRUE(
keys.count(i)) <<
"key " << i <<
" missing from iteration";
283struct HashMapODTest : ::testing::Test
290 for (
int i = 0; i <
N; ++i)
291 m.
insert(i, std::to_string(i));
293 for (
int i = 0; i <
N; ++i)
296 ASSERT_NE(p,
nullptr) <<
"key " << i <<
" not found";
303 for (
int i = 0; i <
N; ++i)
304 m.
insert(i, std::to_string(i));
312 for (
int i = 0; i <
N; ++i)
313 m.
insert(i, std::to_string(i));
315 auto keys = collect_keys(
m);
317 for (
int i = 0; i <
N; ++i)
318 EXPECT_TRUE(
keys.count(i)) <<
"key " << i <<
" missing from iteration";
330 for (
int i = 0; i <
N; ++i)
332 ol.insert(i, std::to_string(i));
333 od.insert(i, std::to_string(i));
338 for (
int i = 0; i <
N; ++i)
340 auto *pol =
ol.search(i);
341 auto *
pod =
od.search(i);
355 for (
int i = 0; i <
N; ++i)
365 for (
int i = 0; i <
N; ++i)
366 m.
insert(i, std::to_string(i));
368 auto keys = collect_keys(
m);
TEST_F(StaticArenaFixture, simple_fail)
Key * search(const Key &key) const noexcept
searches the table for the key.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Unified hash table interface.