55# include <gsl/gsl_rng.h>
147 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
179 std::swap(
cmp, tree.cmp);
180 std::swap(
r, tree.r);
231 if (
root == Node::NullPtr)
234 const Key &
pk =
KEY(p);
241 return Node::NullPtr;
252 return Node::NullPtr;
260 return Node::NullPtr;
265 if (
root == Node::NullPtr)
268 const Key &
pk =
KEY(p);
294 if (
root == Node::NullPtr)
297 const Key &
pk =
KEY(p);
322 assert(p != Node::NullPtr);
326 if (result == Node::NullPtr)
348 assert(p != Node::NullPtr);
364 assert(p != Node::NullPtr);
386 while (p != Node::NullPtr)
388 const Key &
pk =
KEY(p);
394 else if (
cmp(
pk, key))
403 if (p == Node::NullPtr)
429 if (
t1 == Node::NullPtr)
432 if (
t2 == Node::NullPtr)
446 if (
root == Node::NullPtr)
447 return Node::NullPtr;
464 if (
t2 == Node::NullPtr)
476 if (
t2 == Node::NullPtr)
483 if (
ret == Node::NullPtr)
510 t.tree_root = Node::NullPtr;
524 t.tree_root = Node::NullPtr;
541 t.tree_root = Node::NullPtr;
611 template <
typename Key,
class Compare = Aleph::less<Key>>
645 template <
typename Key,
class Compare = Aleph::less<Key>>
C++20 concepts for constraining comparison functors.
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
Strict weak ordering constraint for BST comparators.
__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.
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.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
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.
const long Min_Priority
Minimum priority value.
static std::atomic< bool > init
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.