43#include <gtest/gtest.h>
59 EXPECT_EQ(table.size(), 0u);
61 EXPECT_EQ(table.
search(42),
nullptr);
62 EXPECT_FALSE(table.
has(42));
69 auto * p = table.
insert(42);
70 ASSERT_NE(p,
nullptr);
73 EXPECT_EQ(table.size(), 1u);
75 EXPECT_TRUE(table.
has(42));
82 for (
int i : {5, 3, 7, 1, 9, 2, 8})
84 auto * p = table.
insert(i);
85 ASSERT_NE(p,
nullptr);
89 EXPECT_EQ(table.size(), 7u);
91 for (
int i : {1, 2, 3, 5, 7, 8, 9})
102 auto * p1 = table.
insert(42);
103 ASSERT_NE(p1,
nullptr);
105 EXPECT_EQ(table.size(), 1u);
107 auto * p2 = table.
insert(42);
108 EXPECT_EQ(p2,
nullptr);
109 EXPECT_EQ(table.size(), 1u);
120 auto * p = table.
search(20);
121 ASSERT_NE(p,
nullptr);
132 EXPECT_EQ(table.
search(20),
nullptr);
141 const auto & key = table.
find(42);
145 auto & key2 = table.
find(42);
160 EXPECT_THROW(table.
find(42), domain_error);
173 ASSERT_NE(p1,
nullptr);
175 EXPECT_EQ(table.size(), 1u);
179 ASSERT_NE(p2,
nullptr);
181 EXPECT_EQ(table.size(), 1u);
191 ASSERT_NE(p1,
nullptr);
193 EXPECT_FALSE(found1);
194 EXPECT_EQ(table.size(), 1u);
198 ASSERT_NE(p2,
nullptr);
201 EXPECT_EQ(table.size(), 1u);
209 auto * p1 = table.
add(10);
210 ASSERT_NE(p1,
nullptr);
213 auto * p2 = table.
append(20);
214 ASSERT_NE(p2,
nullptr);
217 EXPECT_EQ(table.size(), 2u);
225 auto * p = table.
insert(std::move(s));
226 ASSERT_NE(p,
nullptr);
227 EXPECT_EQ(*p,
"hello");
243 int removed = table.
remove(20);
244 EXPECT_EQ(removed, 20);
245 EXPECT_EQ(table.size(), 2u);
257 EXPECT_THROW(table.
remove(42), domain_error);
265 auto * p20 = table.
insert(20);
268 ASSERT_NE(p20,
nullptr);
273 EXPECT_EQ(table.size(), 2u);
283 for (
int i = 0; i < 50; ++i)
286 EXPECT_EQ(table.size(), 50u);
288 for (
int i = 0; i < 50; ++i)
292 EXPECT_EQ(table.size(), 0u);
299 for (
int i = 0; i < 100; ++i)
302 EXPECT_EQ(table.size(), 100u);
307 EXPECT_EQ(table.size(), 0u);
322 for (
int i : {1, 2, 3, 4, 5})
327 EXPECT_EQ(table2.size(), 5u);
328 for (
int i : {1, 2, 3, 4, 5})
341 for (
int i : {1, 2, 3})
344 for (
int i : {10, 20})
349 EXPECT_EQ(table2.size(), 3u);
350 for (
int i : {1, 2, 3})
360 for (
int i : {1, 2, 3})
365 EXPECT_EQ(table.size(), 3u);
366 for (
int i : {1, 2, 3})
374 for (
int i : {1, 2, 3, 4, 5})
379 EXPECT_EQ(table2.size(), 5u);
380 for (
int i : {1, 2, 3, 4, 5})
390 for (
int i : {1, 2, 3})
393 for (
int i : {10, 20})
396 table2 = std::move(table1);
398 EXPECT_EQ(table2.size(), 3u);
399 for (
int i : {1, 2, 3})
404 EXPECT_EQ(table1.size(), 0u);
411 for (
int i : {1, 2, 3})
414 for (
int i : {10, 20})
419 EXPECT_EQ(table1.size(), 2u);
423 EXPECT_EQ(table2.size(), 3u);
438 EXPECT_FALSE(it.has_curr());
445 for (
int i : {5, 3, 7, 1, 9})
450 keys.push_back(it.get_curr());
452 EXPECT_EQ(
keys.size(), 5u);
456 vector<int>
expected = {1, 3, 5, 7, 9};
464 for (
int i : {1, 2, 3, 4, 5})
468 ASSERT_TRUE(it.has_curr());
470 int first = it.get_curr();
473 EXPECT_EQ(table.size(), 4u);
474 EXPECT_FALSE(table.
contains(first));
502 EXPECT_EQ(table.size(), 3u);
503 EXPECT_TRUE(table.
contains(
"apple"));
504 EXPECT_TRUE(table.
contains(
"banana"));
505 EXPECT_FALSE(table.
contains(
"date"));
517 for (
int i = 0; i < 10000; ++i)
520 EXPECT_EQ(table.size(), 10000u);
523 for (
int i = 0; i < 10000; ++i)
530 auto bad_hash = [](
const int &) ->
size_t {
return 42; };
534 for (
int i = 0; i < 100; ++i)
537 EXPECT_EQ(table.size(), 100u);
539 for (
int i = 0; i < 100; ++i)
546 vector<int> inserted;
549 for (
int i = 0; i < 500; ++i)
551 if (
int key = rand() % 1000; table.
insert(key) !=
nullptr)
552 inserted.push_back(key);
556 for (
int key : inserted)
559 EXPECT_EQ(table.size(), inserted.size());
562 for (
size_t i = 0; i < inserted.size() / 2; ++i)
564 int idx = rand() % inserted.size();
565 table.
remove(inserted[idx]);
566 inserted.erase(inserted.begin() + idx);
569 EXPECT_EQ(table.size(), inserted.size());
570 for (
int key : inserted)
579 for (
int i = 0; i < 1000; ++i)
582 EXPECT_EQ(table.size(), 1000u);
585 for (
int i = 0; i < 1000; ++i)
589 for (
int i = 0; i < 950; ++i)
592 EXPECT_EQ(table.size(), 50u);
594 for (
int i = 950; i < 1000; ++i)
607 EXPECT_EQ(map.size(), 0u);
609 EXPECT_EQ(map.
search(42),
nullptr);
616 auto * p = map.
insert(1,
"one");
617 ASSERT_NE(p,
nullptr);
618 EXPECT_EQ(p->first, 1);
619 EXPECT_EQ(p->second,
"one");
620 EXPECT_EQ(map.size(), 1u);
631 EXPECT_EQ(map.size(), 3u);
641 auto * p1 = map.
insert(1,
"one");
642 ASSERT_NE(p1,
nullptr);
644 auto * p2 = map.
insert(1,
"uno");
645 EXPECT_EQ(p2,
nullptr);
646 EXPECT_EQ(map.size(), 1u);
649 EXPECT_EQ(map.
find(1),
"one");
660 ASSERT_NE(p,
nullptr);
661 EXPECT_EQ(p->first, 2);
662 EXPECT_EQ(p->second,
"two");
664 EXPECT_EQ(map.
search(99),
nullptr);
673 EXPECT_EQ(map.
find(1),
"one");
674 EXPECT_THROW(map.
find(99), domain_error);
680 struct No_Default_Data
683 explicit No_Default_Data(
const int v) :
value(v) {}
692 static_assert(not std::is_default_constructible_v<No_Default_Data>);
695 map.
insert(1, No_Default_Data(10));
696 map.
insert(2, No_Default_Data(20));
698 ASSERT_NE(map.
search(1),
nullptr);
699 EXPECT_EQ(map.
search(1)->second.value, 10);
700 EXPECT_EQ(map.
search(3),
nullptr);
701 EXPECT_NE(map.
search(2 + 0),
nullptr);
703 const auto & const_map = map;
704 ASSERT_NE(const_map.search(2),
nullptr);
705 EXPECT_EQ(const_map.search(2)->second.value, 20);
706 EXPECT_TRUE(const_map.has(1));
707 EXPECT_FALSE(const_map.has(3));
708 EXPECT_TRUE(const_map.contains(2));
709 EXPECT_FALSE(const_map.contains(4));
718 EXPECT_EQ(map.size(), 1u);
719 EXPECT_EQ(map[1],
"one");
723 EXPECT_EQ(map[1],
"uno");
724 EXPECT_EQ(map.size(), 1u);
732 const auto & const_map = map;
733 EXPECT_EQ(const_map[1],
"one");
734 EXPECT_THROW(const_map[99], domain_error);
745 string removed = map.
remove(2);
746 EXPECT_EQ(removed,
"two");
747 EXPECT_EQ(map.size(), 2u);
752 EXPECT_EQ(map.size(), 0u);
764 EXPECT_EQ(
keys.size(), 3u);
766 vector<int> sorted_keys;
767 keys.for_each([&sorted_keys](
int k) { sorted_keys.push_back(
k); });
768 sort(sorted_keys.begin(), sorted_keys.end());
780 EXPECT_TRUE(by_name.
values().is_empty());
784 by_name.
insert(
"three", 3);
787 by_name.
values().for_each([&values](
int v) { values.push_back(v); });
788 sort(values.begin(), values.end());
789 EXPECT_EQ(values, (vector<int>{1, 2, 3}));
793 by_number.
insert(1,
"one");
794 by_number.
insert(2,
"two");
796 vector<string> names;
797 by_number.
values().for_each([&names](
const string & v) { names.push_back(v); });
798 sort(names.begin(), names.end());
799 EXPECT_EQ(names, (vector<string>{
"one",
"two"}));
810 EXPECT_EQ(ptrs.size(), 2u);
813 ptrs.for_each([](
string * p) {
818 EXPECT_EQ(map.
find(1),
"ONE");
829 EXPECT_EQ(items.size(), 2u);
837 map.
insert(1, std::move(s));
838 EXPECT_EQ(map.
find(1),
"hello");
841 map.
insert(std::move(
k),
"world");
842 EXPECT_EQ(map.
find(2),
"world");
849TEST(DynHashTableFunctions, Join)
857 EXPECT_EQ(result.size(), 6u);
860 for (
int i : {1, 2, 3, 4, 5, 6})
861 EXPECT_TRUE(result_set.
contains(i));
864TEST(DynHashTableFunctions, Intercept)
872 EXPECT_EQ(result.size(), 3u);
875 result.for_each([&vec](
int i) { vec.push_back(i); });
876 sort(vec.begin(), vec.end());
882TEST(DynHashTableFunctions, Unique)
889 EXPECT_EQ(result.size(), 4u);
892 for (
int i : {1, 2, 3, 4})
893 EXPECT_TRUE(result_set.
contains(i));
896TEST(DynHashTableFunctions, Repeated)
905 EXPECT_GE(result.size(), 2u);
908 EXPECT_TRUE(result_set.
contains(2));
909 EXPECT_TRUE(result_set.
contains(3));
910 EXPECT_FALSE(result_set.
contains(1));
911 EXPECT_FALSE(result_set.
contains(4));
912 EXPECT_FALSE(result_set.
contains(5));
915TEST(DynHashTableFunctions, RepeatedWithIndex)
922 EXPECT_EQ(result.size(), 2u);
924 bool found_2 =
false, found_3 =
false;
928 EXPECT_EQ(p.second, 2u);
933 EXPECT_EQ(p.second, 5u);
938 EXPECT_TRUE(found_2);
939 EXPECT_TRUE(found_3);
950 for (
int i : {1, 2, 3, 4, 5})
953 EXPECT_EQ(table.size(), 5u);
954 for (
int i : {1, 2, 3, 4, 5})
962 for (
int i : {10, 20, 30})
965 EXPECT_EQ(table.size(), 3u);
979 EXPECT_EQ(table.size(), 1u);
990 for (
int cycle = 0; cycle < 10; ++cycle)
992 for (
int i = 0; i < 50; ++i)
995 EXPECT_EQ(table.size(), 50u);
997 for (
int i = 0; i < 50; ++i)
1007 auto custom_hash = [](
const int &
k) ->
size_t {
return k % 100; };
1015 EXPECT_EQ(table.size(), 3u);
1031 return x == other.x &&
y == other.y;
1042 return hash<int>()(p.x) ^ (hash<int>()(p.y) << 1);
1049 return std::hash<Point>()(p);
1064 EXPECT_EQ(table.size(), 3u);
1079 size_t map_hash_a(
const long &
k)
noexcept
1081 return static_cast<size_t>(
k) * 2654435761u;
1084 size_t map_hash_b(
const long &
k)
noexcept
1086 return static_cast<size_t>(
k) * 40503u + 17;
1090 template <
class Map>
1091 ::testing::AssertionResult maps_keys(
const Map & map,
const long from,
1092 const long to,
const int value)
1094 if (map.size() !=
static_cast<size_t>(to - from))
1095 return ::testing::AssertionFailure()
1096 <<
"size is " << map.size() <<
", expected " << to - from;
1097 for (
long k = from;
k < to; ++
k)
1099 const auto *
pair = map.search(
k);
1100 if (
pair ==
nullptr)
1101 return ::testing::AssertionFailure() <<
"key " <<
k <<
" not found";
1103 return ::testing::AssertionFailure() <<
"key " <<
k <<
" is wrong";
1105 return ::testing::AssertionSuccess();
1108 template <
class Map>
1109 void insert_keys(Map & map,
const long from,
const long to,
1112 for (
long k = from;
k < to; ++
k)
1113 ASSERT_NE(map.insert(
k,
value),
nullptr) <<
"key " <<
k;
1116 template <
class Map>
1117 struct DynMapHashFunction :
public ::testing::Test {};
1119 using Chained_Maps =
1126 TYPED_TEST(DynMapHashFunction, SwapKeepsEachMapFindingItsKeys)
1128 TypeParam a(101, map_hash_a), b(101, map_hash_b);
1129 insert_keys(a, 0, 50, 1);
1130 insert_keys(b, 1000, 1050, 2);
1134 EXPECT_TRUE(maps_keys(a, 1000, 1050, 2));
1135 EXPECT_TRUE(maps_keys(b, 0, 50, 1));
1137 insert_keys(a, 1050, 1300, 2);
1138 insert_keys(b, 50, 300, 1);
1139 EXPECT_TRUE(maps_keys(a, 1000, 1300, 2));
1140 EXPECT_TRUE(maps_keys(b, 0, 300, 1));
1145 TYPED_TEST(DynMapHashFunction, CopyAssignmentBringsTheHashFunction)
1147 TypeParam source(101, map_hash_b), target(101, map_hash_a);
1148 insert_keys(source, 0, 50, 2);
1149 insert_keys(target, 500, 520, 1);
1153 EXPECT_TRUE(maps_keys(target, 0, 50, 2));
1154 EXPECT_TRUE(maps_keys(source, 0, 50, 2));
1155 insert_keys(target, 50, 300, 2);
1156 EXPECT_TRUE(maps_keys(target, 0, 300, 2));
1157 EXPECT_TRUE(maps_keys(source, 0, 50, 2));
1162 TYPED_TEST(DynMapHashFunction, MoveAssignmentLeavesBothMapsUsable)
1164 TypeParam source(101, map_hash_b), target(101, map_hash_a);
1165 insert_keys(source, 0, 50, 2);
1166 insert_keys(target, 500, 520, 1);
1168 target = std::move(source);
1170 EXPECT_TRUE(maps_keys(target, 0, 50, 2));
1171 EXPECT_TRUE(source.is_empty());
1173 insert_keys(source, 0, 300, 3);
1174 insert_keys(target, 50, 300, 2);
1175 EXPECT_TRUE(maps_keys(source, 0, 300, 3));
1176 EXPECT_TRUE(maps_keys(target, 0, 300, 2));
1179 TYPED_TEST(DynMapHashFunction, MoveConstructionLeavesBothMapsUsable)
1181 TypeParam source(101, map_hash_b);
1182 insert_keys(source, 0, 50, 2);
1184 TypeParam target(std::move(source));
1186 EXPECT_TRUE(maps_keys(target, 0, 50, 2));
1187 EXPECT_TRUE(source.is_empty());
1189 insert_keys(source, 0, 300, 3);
1190 insert_keys(target, 50, 300, 2);
1191 EXPECT_TRUE(maps_keys(source, 0, 300, 3));
1192 EXPECT_TRUE(maps_keys(target, 0, 300, 2));
1195 TYPED_TEST(DynMapHashFunction, CopyConstructionBringsTheHashFunction)
1197 TypeParam source(101, map_hash_b);
1198 insert_keys(source, 0, 50, 2);
1200 TypeParam
copy(source);
1202 EXPECT_TRUE(maps_keys(
copy, 0, 50, 2));
1203 insert_keys(
copy, 50, 300, 2);
1204 EXPECT_TRUE(maps_keys(
copy, 0, 300, 2));
1205 EXPECT_TRUE(maps_keys(source, 0, 50, 2));
1212 template <
class Set>
1213 struct DynHashTableThresholds :
public ::testing::Test {};
1220 TYPED_TEST(DynHashTableThresholds, AccessorsReadWhatTheTableWasGiven)
1222 const TypeParam table(101, Aleph::dft_hash_ptr_fct<int>,
1225 EXPECT_EQ(table.get_lower_alpha(), 0.2f);
1226 EXPECT_EQ(table.get_upper_alpha(), 0.6f);
1229 TYPED_TEST(DynHashTableThresholds, SettersRejectThresholdsOutOfOrder)
1231 TypeParam table(101, Aleph::dft_hash_ptr_fct<int>,
1234 table.set_upper_alpha(0.8f);
1235 table.set_lower_alpha(0.3f);
1236 EXPECT_EQ(table.get_lower_alpha(), 0.3f);
1237 EXPECT_EQ(table.get_upper_alpha(), 0.8f);
1239 EXPECT_THROW(table.set_upper_alpha(0.3f), std::domain_error);
1240 EXPECT_THROW(table.set_lower_alpha(0.8f), std::domain_error);
1241 EXPECT_EQ(table.get_lower_alpha(), 0.3f);
1242 EXPECT_EQ(table.get_upper_alpha(), 0.8f);
1247 TYPED_TEST(DynHashTableThresholds, TheTableObeysTheSetters)
1249 TypeParam raised(101, Aleph::dft_hash_ptr_fct<int>,
1251 TypeParam as_built(101, Aleph::dft_hash_ptr_fct<int>,
1253 const size_t capacity = raised.capacity();
1254 ASSERT_EQ(as_built.capacity(), capacity);
1256 raised.set_upper_alpha(0.9f);
1257 for (
int k = 0;
k < 80; ++
k)
1259 ASSERT_NE(raised.insert(
k),
nullptr);
1260 ASSERT_NE(as_built.insert(
k),
nullptr);
1263 EXPECT_EQ(raised.capacity(), capacity);
1264 EXPECT_GT(as_built.capacity(), capacity);
1274 size_t chained_hash(
const int &
k)
noexcept
1276 return static_cast<size_t>(
k) * 2654435761u + 13;
1279 size_t chained_key_hash(
const long &
k)
noexcept
1281 return static_cast<size_t>(
k) * 40503u + 7;
1290TEST(DynSetLhashMove, TakesTheListsAndLeavesAUsableTableWithoutThem)
1292 static_assert(std::is_nothrow_move_constructible_v<DynSetLhash<int>>);
1295 for (
int i = 0; i < 2000; ++i)
1296 ASSERT_NE(source.insert(i),
nullptr);
1297 const size_t capacity = source.capacity();
1298 const int *
const where = source.search(1234);
1302 ASSERT_EQ(target.size(), 2000u);
1303 EXPECT_EQ(target.capacity(), capacity);
1304 EXPECT_EQ(target.
search(1234), where);
1305 for (
int i = 0; i < 2000; ++i)
1308 EXPECT_TRUE(source.is_empty());
1309 EXPECT_EQ(source.size(), 0u);
1310 EXPECT_EQ(source.capacity(), 0u);
1311 EXPECT_EQ(source.current_alpha(), 0.0f);
1312 EXPECT_EQ(source.search(5),
nullptr);
1313 EXPECT_FALSE(source.contains(5));
1314 EXPECT_THROW(source.remove(5), std::domain_error);
1315 EXPECT_FALSE(source.get_it().has_curr());
1317 source.for_each([&visited] (
const int &) { ++visited; });
1318 EXPECT_EQ(visited, 0u);
1321 ASSERT_NE(source.insert(7),
nullptr);
1323 for (
int i = 0; i < 1000; ++i)
1324 (
void) source.insert(i);
1325 ASSERT_EQ(source.size(), 1000u);
1326 for (
int i = 0; i < 1000; ++i)
1327 ASSERT_TRUE(source.contains(i));
1328 for (
int i = 0; i < 1000; i += 2)
1330 EXPECT_EQ(source.size(), 500u);
1331 EXPECT_FALSE(source.contains(0));
1332 EXPECT_TRUE(source.contains(1));
1334 ASSERT_NE(target.
insert(5000),
nullptr);
1335 EXPECT_EQ(target.size(), 2001u);
1341 size_t counted_hash_calls = 0;
1343 size_t counted_hash(
const int &
k)
noexcept
1345 ++counted_hash_calls;
1346 return chained_hash(
k);
1352TEST(DynSetLhashMove, TheTableThatWasMovedFromKeepsItsFunctionAndItsPolicy)
1355 for (
int i = 0; i < 300; ++i)
1356 ASSERT_NE(source.insert(i),
nullptr);
1357 source.set_with_resize(
false);
1360 EXPECT_FALSE(target.get_with_resize());
1361 EXPECT_FALSE(source.get_with_resize());
1362 counted_hash_calls = 0;
1363 for (
int i = 0; i < 300; ++i)
1365 EXPECT_EQ(counted_hash_calls, 300u);
1369 counted_hash_calls = 0;
1370 for (
int i = 0; i < 1000; ++i)
1371 ASSERT_NE(source.insert(i),
nullptr);
1372 EXPECT_EQ(counted_hash_calls, 1000u);
1374 for (
int i = 0; i < 1000; ++i)
1375 ASSERT_TRUE(source.contains(i));
1381TEST(DynSetLhashMove, TheTableThatWasMovedFromKeepsItsLoadThresholds)
1385 for (
int i = 0; i < 50; ++i)
1386 ASSERT_NE(source.insert(i),
nullptr);
1389 ASSERT_EQ(source.capacity(), 0u);
1390 EXPECT_EQ(target.size(), 50u);
1393 for (
int i = 0; i < 2 * lists - 1; ++i)
1394 ASSERT_NE(source.insert(i),
nullptr);
1396 ASSERT_NE(source.insert(2 * lists - 1),
nullptr);
1398 for (
int i = 0; i < 2 * lists; ++i)
1399 ASSERT_TRUE(source.contains(i));
1404TEST(DynSetLhashMove, ATableWithoutListsIsATableLikeAnyOther)
1407 for (
int i = 0; i < 50; ++i)
1408 ASSERT_NE(source.insert(i),
nullptr);
1410 ASSERT_EQ(source.capacity(), 0u);
1413 EXPECT_TRUE(
copy.is_empty());
1415 ASSERT_NE(
copy.insert(3),
nullptr);
1416 EXPECT_TRUE(
copy.contains(3));
1419 EXPECT_EQ(moved.capacity(), 0u);
1420 EXPECT_EQ(source.capacity(), 0u);
1421 ASSERT_NE(moved.
insert(4),
nullptr);
1424 source.swap(target);
1425 EXPECT_EQ(source.size(), 50u);
1426 EXPECT_EQ(target.capacity(), 0u);
1428 EXPECT_EQ(target.size(), 50u);
1430 moved = std::move(target);
1431 EXPECT_EQ(moved.size(), 50u);
1435 ASSERT_EQ(moved.capacity(), 0u);
1436 EXPECT_EQ(moved.resize(31), 31u);
1437 EXPECT_EQ(moved.capacity(), 31u);
1438 ASSERT_NE(moved.
insert(6),
nullptr);
1442 ASSERT_EQ(without.capacity(), 0u);
1443 without.set_hash_fct(chained_hash);
1444 ASSERT_NE(without.insert(8),
nullptr);
1445 EXPECT_TRUE(without.contains(8));
1446 EXPECT_EQ(rehashed.size(), 50u);
1451TEST(DynMapHashMove, TakesThePairsAndLeavesAUsableMap)
1453 static_assert((std::is_nothrow_move_constructible_v<DynMapHash<long, std::string>>));
1456 for (
long k = 0;
k < 500; ++
k)
1457 source.insert(
k, std::to_string(
k));
1458 const auto *
const where = source.search(77);
1462 ASSERT_EQ(target.size(), 500u);
1463 EXPECT_EQ(target.
search(77), where);
1464 EXPECT_EQ(target.
find(499),
"499");
1465 EXPECT_TRUE(source.is_empty());
1466 EXPECT_EQ(source.capacity(), 0u);
1467 EXPECT_EQ(source.search(77),
nullptr);
1468 EXPECT_FALSE(source.has(77));
1470 source.insert(77,
"again");
1471 EXPECT_EQ(source.find(77),
"again");
1472 for (
long k = 1000;
k < 1300; ++
k)
1473 source.insert(
k, std::to_string(
k));
1474 EXPECT_EQ(source.size(), 301u);
1475 EXPECT_EQ(source.find(1299),
"1299");
1480 ::testing::InitGoogleTest(&argc, argv);
1481 return RUN_ALL_TESTS();
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
TYPED_TEST(ArcHeapLifecycle, ClearNullsTheHandles)
size_t size_t int32_t value
Self-adjusting dynamic hash table.
Key * add(const Key &key)
Key * search_or_insert(const Key &key)
Key * append(const Key &key)
bool contains(const Key &key) const noexcept
Return true if the key exists in the table.
void remove(Key *key)
Removes a key from the hash table using its pointer.
const Key & get_last() const
Key * insert(const Key &key)
Inserts key into the hash set.
const Key & find(const Key &key) const
void clear()
Empties the container.
std::pair< Key *, bool > contains_or_insert(const Key &key)
Key * search(const Key &key) noexcept
Searches for a key in the hash table.
bool has(const Key &key) const noexcept
Checks if a key exists in the hash table.
bool is_empty() const noexcept
Checks if the container is empty.
const Key & get_first() const
Doubly-linked list (defined in tpl_dynList.H).
DynList< Data > values() const
Returns the values of the map.
DynList< Data * > values_ptr()
Pair * insert(const Key &key, const Data &data)
Inserts into the hash map the pair (key, record) indexed by key.
Data remove(const Key &key)
Removes a key-value pair from the map and returns the value.
Pair * search(const Key &key) noexcept(nothrow_search< const Key & >)
Searches for the pair whose key is key.
DynList< Pair * > items_ptr()
DynList< Key > keys() const
Data & find(const Key &key)
Finds and returns a reference to the value associated with key.
bool contains(const Key &key) const noexcept(nothrow_search< const Key & >)
Checks if a key exists in the map; an alias for has().
Represents a point with rectangular coordinates in a 2D plane.
bool operator==(const Point &point) const noexcept
Checks for exact equality between two points.
Minimal std::expected-style result type for C++20.
size_t point_hash(const Point &p)
Main namespace for Aleph-w library functions.
Itor unique(Itor __first, Itor __last, BinaryPredicate __binary_pred=BinaryPredicate())
Remove consecutive duplicates in place.
DynList< T > intercept(const Container< T > &c1, const Container< T > &c2)
Return intersection of two containers as a DynList.
DynList< std::pair< T, size_t > > repeated_with_index(const Container< T > &c)
Return repeated elements paired with their occurrence count.
DynList< T > repeated(const Container< T > &c)
Return elements that appear more than once in the container.
const float hash_default_upper_alpha
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
const unsigned long DefaultPrime
Default prime number used when no specific size is requested.
Hash-based dynamic set (defined in tpl_dynSetHash.H).
size_t operator()(const Point &p) const
size_t custom_hash(const int &key)
Dynamic set implementations based on hash tables.