33# include <gsl/gsl_rng.h>
43# define NumItems 10000
49template <
template <
typename,
class>
class SetType>
unsigned long
57 cout <<
"Testing simple insertions and searches ...." <<
endl;
59 for (
int i = 0; i < n; i++)
63 table.insert(
keys(i));
67 if (table.current_alpha() > 1.1)
69 cout <<
"Resizing table to " << 1.5*table.size() <<
endl;
70 table.resize(1.5*table.size());
71 cout <<
"done!" <<
endl;
74 cout <<
"done" <<
endl;
79template <
template <
typename,
class>
class HashTable>
86 for (
typename SetType::Iterator it(
other); it.has_curr(); it.next())
87 table.insert(it.get_curr());
92template <
template <
typename,
class>
class HashTable>
100 typename SetType::Stats stats = table.stats();
101 table.print_stats(stats);
103 cout << table.size() <<
" items inserted" <<
endl
106 <<
"testing deletions ...." <<
endl;
109 const auto ctable = table;
110 assert(table.all([&
ctable] (
auto k) { return ctable.find(k) == k; }));
115 for (
size_t i = 0; i < n; i++)
118 table.remove(
keys(i));
123 assert(table.size() == 0);
127 cout <<
"testing empty() method ...." <<
endl;
132 assert(table.size() == 0);
135 cout <<
"Reinserting keys ...." <<
endl;
136 for (
size_t i = 0; i < n; ++i)
145 cout <<
"Done!" <<
endl;
148 cout <<
"Testing iterator and map ...." <<
endl;
151 ([] (
unsigned long k) ->
unsigned long
159 cout <<
"done!" <<
endl;
163 cout <<
"testing lvalue copy constructor ...." <<
endl;
170 cout <<
"testing lvalue assigment...." <<
endl;
172 for (
size_t i = 0; i < n/2; ++i)
186 cout <<
"Testing rvalue constructor ...." <<
endl;
189 cout <<
"done!" <<
endl
191 <<
"Testing rvalue assign = .... " <<
endl
194 cout <<
"done!" <<
endl
199 cout <<
"testing del() of Iterator ...." <<
endl
200 <<
"Deleting all entries through del() ...." <<
endl;
202 for (
typename SetType::Iterator it(table); it.has_curr(); )
209 cout <<
"done" <<
endl
210 <<
"Reinserting ...." <<
endl;
211 for (
int i = 0; i < n; ++i)
215 cout <<
"Searching inserted keys ...." <<
endl;
216 for (
size_t i = 0; i < n; ++i)
218 unsigned long * ptr = table.search(
keys(i));
230 cout <<
"Testing keys() in set ...." <<
endl
236 return table.has(key);
242 <<
"Testing filter of keys multiples of 13" <<
endl;
245 filter(table, [] (
const unsigned long & key)
247 return key % 13 == 0;
250 table.
filter( [] (
const unsigned long & key)
252 return key % 13 == 0;
263template <
class HashTable>
269 cout <<
"Testing simple insertions and searches ...." <<
endl;
270 for (
long i = 0; i < n; i++)
279 cout << n <<
" tries " <<
endl
281 <<
"size = " << table.size() <<
endl
283 <<
"Performing map search test" <<
endl
287 sort(
keys).for_each([] (
auto k) { cout <<
" " <<
k; });
290 sort(table.keys()).for_each([] (
auto k) { cout <<
" " <<
k; });
293 for (
auto i = 0; i < n; i++)
296 assert(
keys.all([&table] (
auto k) { return table.search(k) != nullptr; }));
297 cout <<
"Passed" <<
endl
303template <
template <
typename,
typename,
class>
class HashTable>
311 typename MapType::Stats stats = table.stats();
312 table.print_stats(stats);
314 cout << table.size() <<
" items inserted" <<
endl
317 <<
"testing deletions ...." <<
endl;
321 for (
int i = 0; i < n; i++)
322 if (table.search(
keys(i)) !=
nullptr)
324 table.remove(
keys(i));
330 assert(table.size() == 0);
333 cout <<
"testing empty() method ...." <<
endl;
338 assert(table.size() == 0);
341 cout <<
"Reinserting keys ...." <<
endl;
342 for (
size_t i = 0; i < n; ++i)
343 if (table.insert(
keys(i), i) ==
NULL)
351 cout <<
"Done!" <<
endl
353 <<
"Testing for_each and a battery of other tests ...." <<
endl;
355 assert(table.all( [&table]
356 (
const std::pair<const unsigned long, long> & p)
358 auto ptr = table.search(p.first);
359 assert(ptr != nullptr);
360 assert(table.get_data(p.first) == ptr->second);
361 return table.has(p.first);
365 cout <<
"done!" <<
endl
367 <<
"testing keys() method and other tests ...." <<
endl;
370 {
return table.has(
k); }));
372 cout <<
"done!" <<
endl
380 <<
"Testing items() method and othet stuff ...." <<
endl;
383 (std::pair<unsigned long, long> p)
384 {
return table.find(p.first) == p.second; } ));
385 cout <<
"done!" <<
endl
387 <<
"Testing remove by data pointer ...." <<
endl;
391 auto ptr = table.search(
k);
395 table.remove_by_data(ptr->second);
401 <<
"Reinserting keys for doing other tests ...." <<
endl;
402 for (
int i = 0; i < n; ++i)
403 table.insert(
keys(i), i);
405 cout <<
"done!" <<
endl
423 cerr <<
"n must be positive" <<
endl;
427 unsigned int t = std::time(
NULL);
430 try { t =
stoul(
argv[2]); }
catch (...) { t = std::time(
NULL); }
433 cout <<
argv[0] <<
" " << n <<
" " << t <<
endl;
444 cout <<
"testing of ODhash based set ...." <<
endl
448 <<
"Done all test of ODhash based set!" <<
endl
451 <<
"testing of OLhash based set ...." <<
endl
455 <<
"Done all test of OLhash based set!" <<
endl
458 <<
"Testing all tests of OLhash based map" <<
endl
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
T & append()
Allocate a new entry to the end of array.
Iterator on the items of list.
Doubly-linked list (defined in tpl_dynList.H).
bool has_curr() const noexcept
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
and
Check uniqueness with explicit hash + equality functors.
bool contains(const std::string_view &str, const std::string_view &substr)
Check if substr appears inside str.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
bool check_primes_database()
Verify the integrity of the prime database.
unsigned long next_prime(unsigned long n)
Find the smallest prime number >= n from the database.
Aleph::DynList< T > keys() const
Aleph::DynList< T > items() const
Return a list of all the elements of a container sorted by traversal order.
unsigned long insert_n_random_items_in_set(SetType< unsigned long, Aleph::equal_to< unsigned long > > &table, DynArray< unsigned long > &keys, unsigned long n)
HashTable< unsigned long, Aleph::equal_to< unsigned long > > create_table(const HashTable< unsigned long, Aleph::equal_to< unsigned long > > &other)
void test_DynSetLinHash(size_t n)
void test_DynMapLinHash(size_t n)
unsigned long insert_n_random_items_in_map(HashTable &table, DynArray< unsigned long > &keys, unsigned long n)
Dynamic map with open hashing.
Dynamic set implementations based on hash tables.
Comprehensive sorting algorithms and search utilities for Aleph-w.