28# include <gsl/gsl_rng.h>
38# define NumItems 10000
44template <
template <
typename,
class>
class SetType>
unsigned long
52 cout <<
"Testing simple insertions and searches ...." <<
endl;
54 for (
int i = 0; i < n; i++)
58 table.insert(
keys(i));
62 if (table.current_alpha() > 1.1)
64 cout <<
"Resizing table to " << 1.5*table.size() <<
endl;
65 table.resize(1.5*table.size());
66 cout <<
"done!" <<
endl;
69 cout <<
"done" <<
endl;
74template <
template <
typename,
class>
class HashTable>
81 for (
typename SetType::Iterator it(
other); it.has_curr(); it.next())
82 table.insert(it.get_curr());
87template <
template <
typename,
class>
class HashTable>
95 typename SetType::Stats stats = table.stats();
96 table.print_stats(stats);
98 cout << table.size() <<
" items inserted" <<
endl
101 <<
"testing deletions ...." <<
endl;
104 const auto ctable = table;
105 assert(table.all([&
ctable] (
auto k) { return ctable.find(k) == k; }));
110 for (
size_t i = 0; i < n; i++)
113 table.remove(
keys(i));
118 assert(table.size() == 0);
122 cout <<
"testing empty() method ...." <<
endl;
127 assert(table.size() == 0);
130 cout <<
"Reinserting keys ...." <<
endl;
131 for (
size_t i = 0; i < n; ++i)
140 cout <<
"Done!" <<
endl;
143 cout <<
"Testing iterator and map ...." <<
endl;
146 ([] (
unsigned long k) ->
unsigned long
154 cout <<
"done!" <<
endl;
158 cout <<
"testing lvalue copy constructor ...." <<
endl;
165 cout <<
"testing lvalue assigment...." <<
endl;
167 for (
size_t i = 0; i < n/2; ++i)
181 cout <<
"Testing rvalue constructor ...." <<
endl;
184 cout <<
"done!" <<
endl
186 <<
"Testing rvalue assign = .... " <<
endl
189 cout <<
"done!" <<
endl
194 cout <<
"testing del() of Iterator ...." <<
endl
195 <<
"Deleting all entries through del() ...." <<
endl;
197 for (
typename SetType::Iterator it(table); it.has_curr(); )
204 cout <<
"done" <<
endl
205 <<
"Reinserting ...." <<
endl;
206 for (
int i = 0; i < n; ++i)
210 cout <<
"Searching inserted keys ...." <<
endl;
211 for (
size_t i = 0; i < n; ++i)
213 unsigned long * ptr = table.search(
keys(i));
225 cout <<
"Testing keys() in set ...." <<
endl
231 return table.has(key);
237 <<
"Testing filter of keys multiples of 13" <<
endl;
240 filter(table, [] (
const unsigned long & key)
242 return key % 13 == 0;
245 table.
filter( [] (
const unsigned long & key)
247 return key % 13 == 0;
258template <
class HashTable>
264 cout <<
"Testing simple insertions and searches ...." <<
endl;
265 for (
long i = 0; i < n; i++)
274 cout << n <<
" tries " <<
endl
276 <<
"size = " << table.size() <<
endl
278 <<
"Performing map search test" <<
endl
282 sort(
keys).for_each([] (
auto k) { cout <<
" " <<
k; });
285 sort(table.keys()).for_each([] (
auto k) { cout <<
" " <<
k; });
288 for (
auto i = 0; i < n; i++)
291 assert(
keys.all([&table] (
auto k) { return table.search(k) != nullptr; }));
292 cout <<
"Passed" <<
endl
298template <
template <
typename,
typename,
class>
class HashTable>
306 typename MapType::Stats stats = table.stats();
307 table.print_stats(stats);
309 cout << table.size() <<
" items inserted" <<
endl
312 <<
"testing deletions ...." <<
endl;
316 for (
int i = 0; i < n; i++)
317 if (table.search(
keys(i)) !=
nullptr)
319 table.remove(
keys(i));
325 assert(table.size() == 0);
328 cout <<
"testing empty() method ...." <<
endl;
333 assert(table.size() == 0);
336 cout <<
"Reinserting keys ...." <<
endl;
337 for (
size_t i = 0; i < n; ++i)
338 if (table.insert(
keys(i), i) ==
NULL)
346 cout <<
"Done!" <<
endl
348 <<
"Testing for_each and a battery of other tests ...." <<
endl;
350 assert(table.all( [&table]
351 (
const std::pair<const unsigned long, long> & p)
353 auto ptr = table.search(p.first);
354 assert(ptr != nullptr);
355 assert(table.get_data(p.first) == ptr->second);
356 return table.has(p.first);
360 cout <<
"done!" <<
endl
362 <<
"testing keys() method and other tests ...." <<
endl;
365 {
return table.has(
k); }));
367 cout <<
"done!" <<
endl
375 <<
"Testing items() method and othet stuff ...." <<
endl;
378 (std::pair<unsigned long, long> p)
379 {
return table.find(p.first) == p.second; } ));
380 cout <<
"done!" <<
endl
382 <<
"Testing remove by data pointer ...." <<
endl;
386 auto ptr = table.search(
k);
390 table.remove_by_data(ptr->second);
396 <<
"Reinserting keys for doing other tests ...." <<
endl;
397 for (
int i = 0; i < n; ++i)
398 table.insert(
keys(i), i);
400 cout <<
"done!" <<
endl
418 cerr <<
"n must be positive" <<
endl;
422 unsigned int t = std::time(
NULL);
425 try { t =
stoul(
argv[2]); }
catch (...) { t = std::time(
NULL); }
428 cout <<
argv[0] <<
" " << n <<
" " << t <<
endl;
439 cout <<
"testing of ODhash based set ...." <<
endl
443 <<
"Done all test of ODhash based set!" <<
endl
446 <<
"testing of OLhash based set ...." <<
endl
450 <<
"Done all test of OLhash based set!" <<
endl
453 <<
"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.
Dynamic singly linked list with functional programming support.
bool has_curr() const noexcept
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
and
Check uniqueness with explicit hash + equality functors.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
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.
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.
size_t 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.