42# ifndef TPL_BINTREEOPS_H
43# define TPL_BINTREEOPS_H
56 template <
class Node,
class Cmp = Aleph::less<
typename Node::key_type>>
70 using Key =
typename Node::key_type;
139 if (
root == Node::NullPtr)
155 return Node::NullPtr;
170 if (
root == Node::NullPtr)
198 if (
r == Node::NullPtr)
221 if (
root == Node::NullPtr)
223 ts =
tg = Node::NullPtr;
268 root = Node::NullPtr;
276 if (
root == Node::NullPtr)
278 ts =
tg = Node::NullPtr;
306 root = Node::NullPtr;
318 if (
root == Node::NullPtr)
319 return Node::NullPtr;
347 Node *
l = Node::NullPtr, *
r = Node::NullPtr;
350 return Node::NullPtr;
385 if (
t2 == Node::NullPtr)
413 if (
t1 == Node::NullPtr)
416 if (
t2 == Node::NullPtr)
428 assert(p != Node::NullPtr);
452 if (
root == Node::NullPtr)
454 l =
r = Node::NullPtr;
475 while (current != Node::NullPtr)
477 if (
cmp(key,
KEY(current)))
503 root = Node::NullPtr;
518 if (
root == Node::NullPtr)
525 return Node::NullPtr;
534 return Node::NullPtr;
540 return Node::NullPtr;
554 if (
root == Node::NullPtr)
594 template <
class Node,
599 using Key =
typename Node::key_type;
622 if (
r == Node::NullPtr)
671 Node *parent =
nullptr;
674 while (
r != Node::NullPtr)
687 else if (this->
cmp(
kr, key))
724 if (
root == Node::NullPtr)
726 l =
r = Node::NullPtr;
766 if (
root == Node::NullPtr)
768 l =
r = Node::NullPtr;
802 if (
root == Node::NullPtr)
806 return Node::NullPtr;
827 if (
root == Node::NullPtr)
C++20 concepts for constraining comparison functors.
WeightedDigraph::Node Node
Functor encompassing basic operation for extended binary search trees.
BinTreeXt_Operation(Cmp cmp=Cmp()) noexcept
Initialize the functor with comparison criteria cmp
long find_position(Node *r, const Key &key, Node *&p) noexcept
Find the inorder position of a key in an extended binary search tree.
Node * insert_dup_root(Node *&root, Node *p) noexcept
Insert a node as root of an extended binary search tree.
bool split_key_rec(Node *root, const Key &key, Node *&l, Node *&r) noexcept
Split an extended binary search tree according to a key.
typename Node::key_type Key
void split_key_dup_rec(Node *root, const Key &key, Node *&l, Node *&r) noexcept
Split an extended binary search tree according to a key which can be in the tree.
Functor encompassing basic operation for binary search trees.
typename Node::key_type key_type
The type of key.
bool split_key_rec(Node *&root, const Key &key, Node *&ts, Node *&tg) noexcept
Split recursively according to a key.
void split_key_dup_rec_helper(Node *root, const typename Node::key_type &key, Node *&ts, Node *&tg) noexcept
void split_key(Node *root, const Key &key, Node *&l, Node *&r) noexcept
Split a binary search tree according to a key.
Node * join(Node *t1, Node *t2, Node *&dup) noexcept
Fast union of two binary search trees.
Node * search_or_insert(Node *&r, Node *p) noexcept
Search or insert a node in a binary search tree.
Node * insert_dup(Node *&root, Node *p) noexcept
Insert a node p in a binary search tree.
Node * search_parent(Node *root, const Key &key, Node *&parent) noexcept
Search a key and find its node and parent.
typename Node::key_type Key
BinTree_Operation(Cmp cmp_=Cmp()) noexcept
The type of key.
Node * insert_root_rec(Node *root, Node *p) noexcept
Insert a node as root in a binary search tree.
void split_key_dup_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg) noexcept
Split a tree according to a key value.
Node * insert_dup_root(Node *&root, Node *p) noexcept
Insert node p as root of a binary search tree.
Node * join_preorder(Node *t1, Node *t2, Node *&dup) noexcept
Union of two binary search trees.
Cmp & get_compare() noexcept
Node * insert_root(Node *&root, Node *p) noexcept
Insert the node p as the root of a binary search tree.
Node * search(Node *root, const Key &key) noexcept
Search a node with a specific key.
Node * search_or_insert_root_rec(Node *root, Node *p) noexcept
Search and eventually insert p as root in a binary search tree.
Cmp & key_comp() noexcept
Return the comparison criteria.
bool split_key_rec_helper(Node *root, const Key &key, Node *&ts, Node *&tg) noexcept
Node * remove(Node *&root, const Key &key) noexcept
Remove a key from a binary search tree.
Node * insert(Node *&root, Node *p) noexcept
Insert a node p in a binary search tree.
__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
Node * insert_root(Node *&root, Node *p) noexcept
Insert a node p as root of an extended binary search tree.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
Node * join_exclusive(Node *&ts, Node *&tg) noexcept
Exclusive join of two binary trees.
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
Node * search_rank_parent(Node *root, const Key &key) noexcept
Rank search of a key in a binary search tree.
long inorder_position(Node *r, const Key &key, Node *&p) noexcept
Compute the inorder position of a key.
Main namespace for Aleph-w library functions.
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.
void next()
Advance all underlying iterators (bounds-checked).
Utility functions for binary tree operations.
Extended binary node with subtree count.