42# ifndef TPL_BINTREEOPS_H
43# define TPL_BINTREEOPS_H
55 template <
class Node,
class Cmp = Aleph::less<
typename Node::key_type>>
68 using Key =
typename Node::key_type;
137 if (
root == Node::NullPtr)
153 return Node::NullPtr;
168 if (
root == Node::NullPtr)
196 if (r == Node::NullPtr)
219 if (
root == Node::NullPtr)
221 ts =
tg = Node::NullPtr;
266 root = Node::NullPtr;
274 if (
root == Node::NullPtr)
276 ts =
tg = Node::NullPtr;
304 root = Node::NullPtr;
316 if (
root == Node::NullPtr)
317 return Node::NullPtr;
345 Node *
l = Node::NullPtr, *r = Node::NullPtr;
348 return Node::NullPtr;
383 if (
t2 == Node::NullPtr)
411 if (
t1 == Node::NullPtr)
414 if (
t2 == Node::NullPtr)
426 assert(p != Node::NullPtr);
450 if (
root == Node::NullPtr)
452 l = r = Node::NullPtr;
473 while (current != Node::NullPtr)
475 if (
cmp(key,
KEY(current)))
501 root = Node::NullPtr;
516 if (
root == Node::NullPtr)
523 return Node::NullPtr;
532 return Node::NullPtr;
538 return Node::NullPtr;
552 if (
root == Node::NullPtr)
592 template <
class Node,
597 using Key =
typename Node::key_type;
620 if (r == Node::NullPtr)
623 if (this->
cmp(key,
KEY(r)))
629 if (this->
cmp(
KEY(r), key))
669 Node *parent =
nullptr;
672 while (r != Node::NullPtr)
673 if (
const auto &
kr =
KEY(r); this->
cmp(key,
kr))
685 else if (this->
cmp(
kr, key))
722 if (
root == Node::NullPtr)
724 l = r = Node::NullPtr;
764 if (
root == Node::NullPtr)
766 l = r = Node::NullPtr;
800 if (
root == Node::NullPtr)
804 return Node::NullPtr;
825 if (
root == Node::NullPtr)
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
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of 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.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
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.
void next()
Advance all underlying iterators (bounds-checked).
DynList< T > maps(const C &c, Op op)
Classic map operation.
Utility functions for binary tree operations.
Extended binary node with subtree count.