31# include <gsl/gsl_rng.h>
39# define NumItems 10000
51 cout <<
"Testing simple insertions and searches ...." <<
endl;
53 for (
unsigned long i = 0; i < n; i++)
85 for (
size_t i = 0; i < n; i++)
97 cout <<
"testing empty() method ...." <<
endl;
105 cout <<
"Reinserting keys ...." <<
endl;
106 for (
size_t i = 0; i < n; ++i)
115 cout <<
"Done!" <<
endl;
118 cout <<
"Testing iterator and map ...." <<
endl;
121 ( [] (
const unsigned long &
k) ->
unsigned long
129 cout <<
"done!" <<
endl;
133 cout <<
"testing lvalue copy constructor ...." <<
endl;
140 cout <<
"testing lvalue assigment...." <<
endl;
142 for (
size_t i = 0; i < n/2; ++i)
156 cout <<
"Testing rvalue constructor ...." <<
endl;
159 cout <<
"done!" <<
endl
161 <<
"Testing rvalue assign = .... " <<
endl
164 cout <<
"done!" <<
endl
171 cout <<
"done" <<
endl
172 <<
"Reinserting ...." <<
endl;
177 for (
size_t i = 0; i < n; ++i)
181 cout <<
"Searching inserted keys ...." <<
endl;
182 for (
size_t i = 0; i < n; ++i)
196 cout <<
"Testing keys() in set ...." <<
endl
202 return table.
has(key);
208 <<
"Testing filter of keys multiples of 13" <<
endl;
211 filter(table, [](
const unsigned long & key)
213 return key % 13 == 0;
216 table.
filter( [] (
const unsigned long & key)
218 return key % 13 == 0;
235 cout <<
"Testing simple insertions and searches ...." <<
endl;
236 for (
unsigned long i = 0; i < n; i++)
256 for (
size_t i = 0; i < n; i++)
257 if (table.search(
keys(i)) !=
nullptr)
259 table.remove(
keys(i));
264 assert(table.size() == 0);
268 cout <<
"testing empty() method ...." <<
endl;
273 assert(table.size() == 0);
276 cout <<
"Reinserting keys ...." <<
endl;
277 for (
size_t i = 0; i < n; ++i)
278 if (table.insert(
keys(i), i) ==
nullptr)
286 cout <<
"Done!" <<
endl
288 <<
"Testing for_each and a battery of other tests ...." <<
endl;
290 assert(table.all([&table] (
const std::pair<const unsigned long, long> & p)
292 auto * ptr = table.search(p.first);
293 assert(ptr != nullptr);
294 assert(table.get_data(p.first) == ptr->second);
295 return table.has(p.first);
299 cout <<
"done!" <<
endl
301 <<
"testing keys() method and other tests ...." <<
endl;
304 {
return table.has(
k); }));
306 cout <<
"done!" <<
endl
308 <<
"Testing items() method and other stuff ...." <<
endl;
311 (std::pair<unsigned long, long> p)
312 {
return table.find(p.first) == p.second; } ));
313 cout <<
"done!" <<
endl
322 if (
argv[1][0] ==
'-')
337 unsigned int t = (
unsigned int)
time(
nullptr);
340 if (
argv[2][0] ==
'-')
353 t =
static_cast<unsigned int>(
parsed_t);
356 cout <<
argv[0] <<
" " << n <<
" " << t <<
endl;
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
Iterator on the items of list.
Dynamic singly linked list with functional programming support.
Generic key-value map implemented on top of a binary search tree.
bool has(const Key &key) const noexcept
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Dynamic set implemented using randomized treap binary search trees of type Treap<Key>.
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
bool has(const Key &key) const
size_t remove(const Key &key)
Removes a key from the dynamic set.
Key * search(const Key &key) const
Find an element in the set.
void empty()
remove all elements from the set
bool has_curr() const noexcept
bool equal_to(const Container &r) const noexcept
Test if elements of this are exactly contained in another container.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
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.
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.
Aleph::DynList< T > keys() const
Aleph::DynList< T > items() const
Return a list of all the elements of a container sorted by traversal order.
DynSetTree< unsigned long > create_table(const DynSetTree< unsigned long > &other)
void test_DynSet(size_t n)
unsigned long insert_n_random_items_in_set(DynSetTree< unsigned long > &table, DynArray< unsigned long > &keys, unsigned long n)
unsigned long insert_n_random_items_in_map(DynMapTree< unsigned long, long > &table, DynArray< unsigned long > &keys, unsigned long n)
void test_DynMap(size_t n)
Dynamic key-value map based on balanced binary search trees.
Comprehensive sorting algorithms and search utilities for Aleph-w.