42#include <gtest/gtest.h>
68 auto * p = table.
insert(42);
81 for (
int i : {5, 3, 7, 1, 9, 2, 8})
83 auto * p = table.
insert(i);
90 for (
int i : {1, 2, 3, 5, 7, 8, 9})
101 auto * p1 = table.
insert(42);
106 auto * p2 = table.
insert(42);
119 auto * p = table.
search(20);
140 const auto & key = table.
find(42);
208 auto * p1 = table.
add(10);
212 auto * p2 = table.
append(20);
224 auto * p = table.
insert(std::move(s));
282 for (
int i = 0; i < 50; ++i)
287 for (
int i = 0; i < 50; ++i)
298 for (
int i = 0; i < 100; ++i)
321 for (
int i : {1, 2, 3, 4, 5})
327 for (
int i : {1, 2, 3, 4, 5})
340 for (
int i : {1, 2, 3})
343 for (
int i : {10, 20})
349 for (
int i : {1, 2, 3})
359 for (
int i : {1, 2, 3})
365 for (
int i : {1, 2, 3})
373 for (
int i : {1, 2, 3, 4, 5})
379 for (
int i : {1, 2, 3, 4, 5})
389 for (
int i : {1, 2, 3})
392 for (
int i : {10, 20})
398 for (
int i : {1, 2, 3})
410 for (
int i : {1, 2, 3})
413 for (
int i : {10, 20})
444 for (
int i : {5, 3, 7, 1, 9})
449 keys.push_back(it.get_curr());
455 vector<int>
expected = {1, 3, 5, 7, 9};
463 for (
int i : {1, 2, 3, 4, 5})
469 int first = it.get_curr();
516 for (
int i = 0; i < 10000; ++i)
522 for (
int i = 0; i < 10000; ++i)
529 auto bad_hash = [](
const int &) ->
size_t {
return 42; };
533 for (
int i = 0; i < 100; ++i)
538 for (
int i = 0; i < 100; ++i)
545 vector<int> inserted;
548 for (
int i = 0; i < 500; ++i)
550 if (
int key =
rand() % 1000; table.
insert(key) !=
nullptr)
551 inserted.push_back(key);
555 for (
int key : inserted)
558 EXPECT_EQ(table.size(), inserted.size());
561 for (
size_t i = 0; i < inserted.size() / 2; ++i)
563 int idx =
rand() % inserted.size();
564 table.
remove(inserted[idx]);
565 inserted.erase(inserted.begin() + idx);
568 EXPECT_EQ(table.size(), inserted.size());
569 for (
int key : inserted)
578 for (
int i = 0; i < 1000; ++i)
584 for (
int i = 0; i < 1000; ++i)
588 for (
int i = 0; i < 950; ++i)
593 for (
int i = 950; i < 1000; ++i)
615 auto * p = map.
insert(1,
"one");
640 auto * p1 = map.
insert(1,
"one");
643 auto * p2 = map.
insert(1,
"uno");
744 GTEST_SKIP() <<
"values() has wrong return type in tpl_dynSetHash.H:540";
758 ptrs.for_each([](
string * p) {
782 map.
insert(1, std::move(s));
786 map.
insert(std::move(
k),
"world");
805 for (
int i : {1, 2, 3, 4, 5, 6})
820 result.for_each([&
vec](
int i) {
vec.push_back(i); });
837 for (
int i : {1, 2, 3, 4})
873 EXPECT_EQ(p.second, 2u);
878 EXPECT_EQ(p.second, 5u);
895 for (
int i : {1, 2, 3, 4, 5})
899 for (
int i : {1, 2, 3, 4, 5})
907 for (
int i : {10, 20, 30})
937 for (
int i = 0; i < 50; ++i)
942 for (
int i = 0; i < 50; ++i)
952 auto custom_hash = [](
const int &
k) ->
size_t {
return k % 100; };
994 return std::hash<Point>()(p);
1020 ::testing::InitGoogleTest(&
argc,
argv);
Self-adjusting dynamic hash table.
Key * add(const Key &key)
Key * search_or_insert(const Key &key)
Key * search(const Key &key) const noexcept
Searches for a key in the hash table.
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)
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
Dynamic singly linked list with functional programming support.
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.
bool contains(const Key &key) const noexcept
Alias for has()
DynList< Pair * > items_ptr()
Pair * search(const Key &key) const noexcept
Searches for key and, if found, returns a pointer to the associated pair stored in the table.
DynList< Key > keys() const
Data & find(const Key &key)
Finds and returns a reference to the value associated with key.
Represents a point with rectangular coordinates in a 2D plane.
bool operator==(const Point &point) const noexcept
Checks for exact equality between two points.
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)
DynList< std::pair< T, size_t > > repeated_with_index(const Container< T > &c)
DynList< T > repeated(const Container< T > &c)
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.
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.
size_t operator()(const Point &p) const
size_t custom_hash(const int &key)
Dynamic set implementations based on hash tables.