55# include <type_traits>
154 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
155 requires StrictWeakOrder<Compare, Key>
172 return static_cast<unsigned int>(
seed)
202 std::swap(
cmp, tree.cmp);
245 noexcept(
std::is_nothrow_default_constructible_v<
Node>
and
246 std::is_nothrow_default_constructible_v<Compare>
and
247 std::is_nothrow_copy_constructible_v<Compare>)
263 noexcept(std::is_nothrow_default_constructible_v<Node>
and
264 std::is_nothrow_copy_constructible_v<Compare>)
293 noexcept(bin_node_detail::nothrow_header_from_v<Node>
and
294 bin_node_detail::nothrow_compare_taken_v<Compare>)
295 :
head(bin_node_detail::header_from(tree.
head)),
297 cmp(bin_node_detail::compare_to_take(tree.
cmp))
301 tree.tree_root = Node::NullPtr;
320 [[deprecated(
"it makes a Mersenne Twister in a treap that has none: "
321 "use random_source(); it goes in 8.0.0")]]
333 [[deprecated(
"the generator is no longer of GSL: use random_source(); it goes in 8.0.0")]]
334 gsl_rng * gsl_rng_object() {
return r.gsl(); }
350 Node *
search(
const Key & key)
const noexcept(nothrow_compare_v<Compare, Key>)
353 return ret_val == Node::NullPtr ? nullptr : ret_val;
362 if (
root == Node::NullPtr)
365 const Key & pk =
KEY(p);
367 Node *insertion_result =
nullptr;
371 if (insertion_result == Node::NullPtr)
372 return Node::NullPtr;
382 if (insertion_result == Node::NullPtr)
383 return Node::NullPtr;
391 return Node::NullPtr;
395 noexcept(nothrow_compare_v<Compare, Key>)
397 if (
root == Node::NullPtr)
400 const Key & pk =
KEY(p);
426 if (
root == Node::NullPtr)
429 const Key & pk =
KEY(p);
460 assert(p != Node::NullPtr);
464 if (result == Node::NullPtr)
492 assert(p != Node::NullPtr);
514 assert(p != Node::NullPtr);
539 Node *
remove(
const Key & key)
noexcept(nothrow_compare_v<Compare, Key>)
544 while (p != Node::NullPtr)
546 const Key & pk =
KEY(p);
552 else if (
cmp(pk, key))
561 if (p == Node::NullPtr)
565 while (not (
LLINK(p) == Node::NullPtr
and RLINK(p) == Node::NullPtr))
587 if (t1 == Node::NullPtr)
590 if (t2 == Node::NullPtr)
604 if (
root == Node::NullPtr)
605 return Node::NullPtr;
622 if (t2 == Node::NullPtr)
634 if (t2 == Node::NullPtr)
641 if (ret == Node::NullPtr)
673 t.tree_root = Node::NullPtr;
693 t.tree_root = Node::NullPtr;
710 t.tree_root = Node::NullPtr;
728 noexcept(nothrow_compare_v<Compare, Key>)
749 noexcept(nothrow_compare_v<Compare, Key>)
794 template <
typename Key,
class Compare = Aleph::less<Key>>
795 requires StrictWeakOrder<Compare, Key>
829 template <
typename Key,
class Compare = Aleph::less<Key>>
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Exception handling system with formatted messages for Aleph-w.
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
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.
void swap(Gen_Treap &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
Swaps in constant time the nodes and the comparison criteria of this and tree.
Node * search_or_insert(Node *&root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Gen_Treap(const unsigned long seed, const Compare &__cmp=Compare())
Builds an empty treap whose priorities are those of GSL for seed: it draws them from a Mersenne Twist...
static unsigned long generator_seed(const unsigned long seed) noexcept
Node * insert_dup(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert a node in the tree.
Random_Source & random_source() noexcept
The source of random numbers, which gives the priorities.
Node *& getRoot() noexcept
Return the tree's root.
void join_dup(Node *&t1, Node *t2) noexcept
void join(Gen_Treap &t, Gen_Treap &dup) noexcept
Join this with t filtering the duplicated keys.
Node * insert_dup(Node *root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
const Random_Source & random_source() const noexcept
The source of random numbers, to look at it: its engine, or whether it is equal to another one.
Node * search_or_insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Search or insert a key.
bool verify() const
Return true if this is a consistent treap.
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 ...
void split_key_dup(const Key &key, Gen_Treap &t1, Gen_Treap &t2) noexcept(nothrow_compare_v< Compare, Key >)
Split the tree according to a key that could be in the tree.
Compare & get_compare() noexcept
See key_comp().
Gen_Treap(const Compare &cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_copy_constructible_v< Compare >)
Builds an empty treap with the comparison criteria cmp, which draws its priorities from a SplitMix64 ...
Node head
The type of node.
Gen_Treap(Gen_Treap &&tree) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >)
Takes the nodes, the comparison criteria and the generator of tree, which keeps no nodes,...
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key in a treap.
Node * remove(Node *&root, const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Gen_Treap() noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_copy_constructible_v< Compare >)
Builds an empty treap with a comparison criteria built by default, which draws its priorities from a ...
static Node * join_exclusive(Node *t1, Node *t2) noexcept
Node * insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert a node in a treap.
void join(Node *&t1, Node *t2, Node *&dup) noexcept
Node * insert(Node *root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Gsl_Compatible_Rng & rng()
The Mersenne Twister of the treap, which a treap that was given no seed makes here,...
void join_dup(Gen_Treap &t) noexcept
Join this with t independently of the presence of duplicated keys.
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove a key from the tree.
void join_exclusive(Gen_Treap &t) noexcept
Join exclusive of this with t
bool split_key(const Key &key, Gen_Treap &t1, Gen_Treap &t2) noexcept(nothrow_compare_v< Compare, Key >)
Split the tree according to a key.
Compare & key_comp() noexcept
return the comparison criteria
A random number generator with the sequences of GSL's gsl_rng_mt19937.
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
The source of random numbers of a randomized structure, which draws from one of two generators.
@ Mersenne_Twister
A Gsl_Compatible_Rng, in dynamic memory.
unsigned long get() noexcept
The next number, as operator()().
Gsl_Compatible_Rng & mersenne_twister()
The Mersenne Twister of the source, which is its engine from now on.
void seed(const std::uint64_t s) noexcept
Draws from now on from the SplitMix64 of a seed.
void swap(Random_Source &o) noexcept
Swaps the generators, with their states.
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
void split_key_dup_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split a tree according to a key value.
bool split_key_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split recursively according to a key.
Node * rotate_to_right(Node *p) noexcept
Rotate to the right the tree with root p
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Search a key in a binary search tree using optimistic search.
Main namespace for Aleph-w library functions.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
and
Check uniqueness with explicit hash + equality functors.
const long Min_Priority
Minimum priority value.
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.