40# include <string_view>
53 return (
long) (100.0*rand()/(RAND_MAX+1.0));
85 output << node->get_key() <<
" ";
101int main(
int argc,
char *argv[])
104 unsigned int t = std::time(0);
109 const std::string_view arg = argv[1];
110 auto [ptr, ec] = std::from_chars(arg.data(), arg.data() + arg.size(), n);
112 <<
"Invalid or out-of-range value for n";
117 cerr <<
"n must be positive" << endl;
123 const std::string_view arg = argv[2];
124 auto [ptr, ec] = std::from_chars(arg.data(), arg.data() + arg.size(), t);
126 <<
"Invalid or out-of-range value for t";
131 output.open(
"treap-aux.Tree", ios::out | ios::trunc);
133 <<
"Could not open treap-aux.Tree";
134 fig_file.open(
"bal-04-aux.Tree", ios::out | ios::trunc);
136 <<
"Could not open bal-04-aux.Tree";
137 tex_file.open(
"treap-aux.tex", ios::out | ios::trunc);
139 <<
"Could not open treap-aux.tex";
141 cout <<
"writeTreap " << n <<
" " << t << endl;
148 cout <<
"Inserting " << n <<
" random values in tree ...\n";
150 for (i = 0; i < n; i++)
154 value = 1 +
static_cast<int>(10.0 * n * rand() / (RAND_MAX + 1.0));
169 fig_file << endl <<
"START-AUX " << endl;
183 for (i = 0; i < n; i++)
185 value =
static_cast<int>(n * 10.0 * rand() / (RAND_MAX + 1.0));
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.
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Core header for the Aleph-w library.
size_t size_t int32_t value
Node *& getRoot() noexcept
Return the tree's root.
void set_seed(const unsigned long seed)
Seeds the Mersenne Twister of the treap, as gsl_rng_set() did: the priorities are from then on those ...
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key in a treap.
Node * insert(Node *root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
static constexpr result_type min() noexcept
The least number of operator()().
signed long int get_si() const
__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 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.
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)