55# include <gsl/gsl_rng.h>
146 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
159 void init(
const unsigned int seed)
177 std::swap(
cmp, tree.cmp);
178 std::swap(
r, tree.r);
229 if (
root == Node::NullPtr)
232 const Key &
pk =
KEY(p);
239 return Node::NullPtr;
250 return Node::NullPtr;
258 return Node::NullPtr;
263 if (
root == Node::NullPtr)
266 const Key &
pk =
KEY(p);
292 if (
root == Node::NullPtr)
295 const Key &
pk =
KEY(p);
320 assert(p != Node::NullPtr);
324 if (result == Node::NullPtr)
346 assert(p != Node::NullPtr);
362 assert(p != Node::NullPtr);
384 while (p != Node::NullPtr)
386 const Key &
pk =
KEY(p);
392 else if (
cmp(
pk, key))
401 if (p == Node::NullPtr)
427 if (
t1 == Node::NullPtr)
430 if (
t2 == Node::NullPtr)
444 if (
root == Node::NullPtr)
445 return Node::NullPtr;
462 if (
t2 == Node::NullPtr)
474 if (
t2 == Node::NullPtr)
481 if (
ret == Node::NullPtr)
508 t.tree_root = Node::NullPtr;
522 t.tree_root = Node::NullPtr;
539 t.tree_root = Node::NullPtr;
609 template <
typename Key,
class Compare = Aleph::less<Key>>
642 template <
typename Key,
class Compare = Aleph::less<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_bad_alloc_if(C)
Throws std::bad_alloc if condition holds.
Standard functor implementations and comparison objects.
Inorder iterator on the nodes of a binary tree.
Treap - A randomized binary search tree using heap-ordered priorities.
Node * insert(Node *p) noexcept
Insert a node in a treap.
void set_seed(const unsigned long seed) noexcept
Set the random number generator seed.
Node * remove(const Key &key) noexcept
Remove a key from the tree.
bool verify() const noexcept
Return true if this is a consistent treap.
Gen_Treap(const unsigned long seed, const Compare &__cmp=Compare())
Initialize a treap with random seed and comparison criteria __cmp
void split_key_dup(const Key &key, Gen_Treap &t1, Gen_Treap &t2)
Split the tree according to a key that could be in the tree.
Node * search(const Key &key) const noexcept
Search a key in a treap.
Node * insert_dup(Node *root, Node *p) noexcept
Node *& getRoot() noexcept
Return the tree's root.
void join_dup(Node *&t1, Node *t2) noexcept
void swap(Gen_Treap &tree) noexcept
Swap in constant time all the nodes of this with tree
void join(Gen_Treap &t, Gen_Treap &dup) noexcept
Join this with t filtering the duplicated keys.
void init(const unsigned int seed)
Compare & key_comp() noexcept
return the comparison criteria
Gen_Treap(const Compare &cmp=Compare())
Initialize a treap with random seed from system time and comparison criteria cmp
Node * search_or_insert(Node *&root, Node *p) noexcept
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
Node * insert_dup(Node *p) noexcept
Insert a node in the tree.
Compare & get_compare() noexcept
Node head
The type of node.
static Node * join_exclusive(Node *t1, Node *t2) noexcept
void join(Node *&t1, Node *t2, Node *&dup) noexcept
bool split_key(const Key &key, Gen_Treap &t1, Gen_Treap &t2)
Split the tree according to a key.
Node * remove(Node *&root, const Key &key) noexcept
void join_dup(Gen_Treap &t) noexcept
Join this with t independently of the presence of duplicated keys.
gsl_rng * gsl_rng_object() noexcept
Get a pointer to gsl random number generator.
void join_exclusive(Gen_Treap &t) noexcept
Join exclusive of this with t
Node * insert(Node *root, Node *p) noexcept
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Node * rotate_to_left(Node *p) noexcept
Rotate to the left the tree with root p
Node * rotate_to_right(Node *p) noexcept
Rotate to the right the tree with root p
bool split_key_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept
Split recursively according to a key.
void split_key_dup_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept
Split a tree according to a key value.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
const long Min_Priority
Minimum priority value.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Iterator on nodes of the tree.
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Treap (a special type of randomized binary search tree) using nodes with virtual destructors.
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Utility functions for binary tree operations.
Binary tree operations (split, join, rotate).
Treap node definition with BST key and heap priority.