49template <
template <
class>
class C,
typename T>
52 for (
auto it = c.get_it(); it.has_curr(); it.next())
53 cout << it.get_curr() <<
" ";
58int main(
int argc,
char *argv[])
60 int n = argc > 1 ? atoi(argv[1]) : 100;
61 unsigned long seed = argc > 2 ? atoi(argv[2]) : std::time(NULL);
63 cout << argv[0] <<
" " << n <<
" " <<
seed << endl;
69 cout <<
"** indexes(l1) = ";
72 cout <<
"(" << t.first <<
"," << t.second <<
")";
79 auto to_str = [&
l1] (
int i) -> std::string
81 return std::to_string(i);
93 for (
auto it = lz1.
get_it(); it.has_curr(); it.next())
94 cout << it.get_curr().first <<
"," << it.get_curr().second << endl;
97 cout <<
"Building random list" << endl;
99 for (
long i = 0; i < n; ++i)
103 <<
"building array copy of previous list" << endl;
112 <<
"Copying array to a tree" << endl;
120 <<
"Sorting array for ulterior fast searching";
124 <<
"traversing all the keys of tree and verifiying them with array"
126 assert(tree.
all( [&a] (
long i)
128 return a(binary_search(a, i)) == i;
130 cout <<
"done!" << endl
132 <<
"Traversing all the keys of array and verifiying then with the tree"
134 assert(a.
all( [&tree] (
long i)
136 return tree.search(i) != NULL;
138 cout <<
"done!" << endl
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
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.
Dynamic doubly linked list with O(1) size and bidirectional access.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Dynamic set backed by balanced binary search trees with automatic memory management.
Key * append(const Key &key)
A random number generator with the sequences of GSL's gsl_rng_mt19937.
void seed(const unsigned long s) noexcept
Seeds again, as gsl_rng_set(r, s).
unsigned long get() noexcept
The next number, as operator()().
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
std::decay_t< typename HeadC::Item_Type > T
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
DynList< std::pair< size_t, typename Container::Key_Type > > indexes(const Container &c)
Return pairs of (index, key).
std::string to_str(const double d)
Convert double to a std::string with maximum round-trip precision.
Container< T > range(const T start, const T end, const T step=1)
Generate a range of values [start, end] with a given step.
void quicksort_op(C< T > &a, const Compare &cmp=Compare(), const size_t threshold=Quicksort_Threshold)
Optimized quicksort for containers using operator().
Aleph::DynList< T > keys() const
See items().
void print_seq(const C< T > &c)
Dynamic doubly linked list implementation.
Dynamic set implementations based on balanced binary search trees.
Unified hash table interface.