29# include <gsl/gsl_rng.h>
44 cout << node->get_key() <<
" ";
52 try { n =
stoi(
argv[1]); }
catch (...) { n = 10; }
57 cerr <<
"n must be positive" <<
endl;
61 unsigned int seed = 0;
77 cout <<
"Inserting " << n <<
" random values in tree ...\n";
79 for (
int i = 0; i < n; i++)
100 cout <<
"Sorting keys array" <<
endl;
102 for (
int i = 0; i <
keys.size(); ++i)
103 cout <<
keys(i) <<
" ";
107 cout <<
"inorden traversal prio" <<
endl;
111 cout <<
"Testing select" <<
endl;
113 for (
int i = 0; i < n; i++)
116 cout << node->get_key() <<
" ";
124 cout <<
"testing random positions" <<
endl;
125 for (
int i = 0; i < n; ++i)
128 std::pair<int, Splay_Tree_Rk<int>::Node*> pos =
134 cout << idx <<
"<-->" << pos.first <<
endl
135 <<
keys(idx) <<
"<-->" << pos.second->get_key() <<
" " <<
endl;
138 for (
int i = 0; i < n/2; i++)
141 int & value =
keys(idx);
142 cout << value <<
" ";
143 node = tree.
remove(value);
145 assert(node->get_key() == value);
150 cout <<
endl <<
"verifying Splay_Rk after deletions ... "
153 cout <<
" done" <<
endl;
155 cout <<
"Inorden" <<
endl;
Core header for the Aleph-w library.
Set-like container backed by a dynamic array.
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
std::pair< long, Node * > position(const Key &key)
Returns the inorder (sorted) position of key.
Node * insert(Node *p)
Inserts a node in a top down splay tree.
Node * remove(const Key &key)
Remove a key from a top-down splay tree.
Node * search(const Key &key)
Searches a key in a top down splay tree.
Node * select(const size_t &i)
Returns the node whose inorder position in the extended tree is i.
Node *& getRoot()
Get the top-down splay tree's root.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
size_t internal_path_length(Node *p) noexcept
Compute the internal path length.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
Main namespace for Aleph-w library functions.
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.
void quicksort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using iterative quicksort with optimizations.
void printNode(Splay_Tree_Rk< int >::Node *node, int, int)
Utility functions for binary tree operations.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Top-down splay tree with rank support.