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)
317 for (
int i : {1, 2, 3, 4, 5})
323 for (
int i : {1, 2, 3, 4, 5})
336 for (
int i : {1, 2, 3})
339 for (
int i : {10, 20})
345 for (
int i : {1, 2, 3})
355 for (
int i : {1, 2, 3})
361 for (
int i : {1, 2, 3})
369 for (
int i : {1, 2, 3, 4, 5})
375 for (
int i : {1, 2, 3, 4, 5})
385 for (
int i : {1, 2, 3})
388 for (
int i : {10, 20})
394 for (
int i : {1, 2, 3})
406 for (
int i : {1, 2, 3})
409 for (
int i : {10, 20})
440 for (
int i : {5, 3, 7, 1, 9})
445 keys.push_back(it.get_curr());
450 sort(keys.begin(), keys.end());
451 vector<int>
expected = {1, 3, 5, 7, 9};
459 for (
int i : {1, 2, 3, 4, 5})
465 int first = it.get_curr();
512 for (
int i = 0; i < 10000; ++i)
518 for (
int i = 0; i < 10000; ++i)
525 auto bad_hash = [](
const int &) ->
size_t {
return 42; };
529 for (
int i = 0; i < 100; ++i)
534 for (
int i = 0; i < 100; ++i)
544 for (
int i = 0; i < 500; ++i)
546 if (
int key =
rand() % 1000; table.
insert(key) !=
nullptr)
574 for (
int i = 0; i < 1000; ++i)
580 for (
int i = 0; i < 1000; ++i)
584 for (
int i = 0; i < 950; ++i)
589 for (
int i = 950; i < 1000; ++i)
611 auto * p = map.
insert(1,
"one");
636 auto * p1 = map.
insert(1,
"one");
639 auto * p2 = map.
insert(1,
"uno");
719 auto keys = map.
keys();
736 GTEST_SKIP() <<
"values() has wrong return type in tpl_dynSetHash.H:540";
774 map.
insert(1, std::move(s));
778 map.
insert(std::move(
k),
"world");
791 auto result =
join(l1, l2);
797 for (
int i : {1, 2, 3, 4, 5, 6})
829 for (
int i : {1, 2, 3, 4})
865 EXPECT_EQ(p.second, 2u);
870 EXPECT_EQ(p.second, 5u);
887 for (
int i : {1, 2, 3, 4, 5})
891 for (
int i : {1, 2, 3, 4, 5})
899 for (
int i : {10, 20, 30})
929 for (
int i = 0; i < 50; ++i)
934 for (
int i = 0; i < 50; ++i)
944 auto custom_hash = [](
const int &
k) ->
size_t {
return k % 100; };
986 return std::hash<Point>()(p);
1012 ::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
Alias for has()
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
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.
const Key & get_first() const
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T remove()
Remove the first item of the list.
DynList & swap(DynList &l) noexcept
Swap this with l.
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.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Rectangular point in the plane.
bool operator==(const Point &point) const
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
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)
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.
DynList< T > maps(const C &c, Op op)
Classic map operation.
size_t operator()(const Point &p) const
size_t custom_hash(const int &key)
Dynamic set implementations based on hash tables.