32# include <gsl/gsl_rng.h>
35# include <string_view>
67 tex_file <<
"$(" << node->get_key() <<
"," <<
pri.get_si();
82 output << node->get_key() <<
" ";
101 unsigned int t = std::time(0);
106 const std::string_view
arg =
argv[1];
107 auto [ptr,
ec] = std::from_chars(
arg.data(),
arg.data() +
arg.size(), n);
109 <<
"Invalid or out-of-range value for n";
114 cerr <<
"n must be positive" <<
endl;
120 const std::string_view
arg =
argv[2];
121 auto [ptr,
ec] = std::from_chars(
arg.data(),
arg.data() +
arg.size(), t);
123 <<
"Invalid or out-of-range value for t";
128 output.open(
"treap-aux.Tree", ios::out | ios::trunc);
130 <<
"Could not open treap-aux.Tree";
131 fig_file.open(
"bal-04-aux.Tree", ios::out | ios::trunc);
133 <<
"Could not open bal-04-aux.Tree";
134 tex_file.open(
"treap-aux.tex", ios::out | ios::trunc);
136 <<
"Could not open treap-aux.tex";
138 cout <<
"writeTreap " << n <<
" " << t <<
endl;
145 cout <<
"Inserting " << n <<
" random values in tree ...\n";
147 for (i = 0; i < n; i++)
152 node = tree.
search(value);
181 for (i = 0; i < n; i++)
184 node = tree.
search(value);
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Core header for the Aleph-w library.
void set_seed(const unsigned long seed) noexcept
Set the random number generator seed.
Node * search(const Key &key) const noexcept
Search a key in a treap.
Node *& getRoot() noexcept
Return the tree's root.
gsl_rng * gsl_rng_object() noexcept
Get a pointer to gsl random number generator.
Node * insert(Node *root, Node *p) noexcept
__gmp_expr< mpz_t, mpz_t > mpz_class
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
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
Node * find_max(Node *root) noexcept
Return the maximum key contained in a binary search tree.
Main namespace for Aleph-w library functions.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
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.
gsl_rng * rand_gen
Internal RNG handle used by the helper functors in this header.
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Utility functions for binary tree operations.
Treap: randomized BST combining tree and heap properties.
void print_key(Treap< int >::Node *node, int, int)
Treap< int >::Node * last_node
void print_treap(Treap< int >::Node *node, int, int)
void print_prio(Treap< int >::Node *node, int, int)
void print_pair(Treap< int >::Node *node, int, int)