109 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
143 if (p != Node::NullPtr) [[
likely]]
153 if (p != Node::NullPtr) [[
likely]]
157 while (p != Node::NullPtr);
187 if (p != Node::NullPtr) [[
likely]]
195 if (p != Node::NullPtr) [[
likely]]
199 while (p != Node::NullPtr);
278 else if (
DIFF(r) == -1)
294 [[gnu::always_inline]]
318 else if (
DIFF(r) == -1)
428 while (
LLINK(succ) != Node::NullPtr)
444 LLINK(p) = Node::NullPtr;
446 if (
RLINK(p) == succ)
502 for (
size_t i = 0; i < sz - 1; ++i)
510 for (
size_t i = 0; i < sz - 1; ++i)
537 std::swap(
root, tree.root);
538 std::swap(
cmp, tree.cmp);
560 return result == Node::NullPtr ?
nullptr : result;
570 if (
root == Node::NullPtr)
600 if (
root == Node::NullPtr)
624 if (
root == Node::NullPtr)
644 if (
root == Node::NullPtr)
661 if (
LLINK(p) == Node::NullPtr)
670 if (
RLINK(p) == Node::NullPtr)
714 std::pair<long, Node *>
position(
const Key & key)
const noexcept
716 std::pair<long, Node *>
ret_val;
731 std::pair<long, Node *> r(-2,
nullptr);
750 while (p != Node::NullPtr)
766 if (p == Node::NullPtr)
767 return Node::NullPtr;
769 if (
LLINK(p) == Node::NullPtr)
783 while (
LLINK(*
pp) != Node::NullPtr)
800 if (
DIFF(parent) == 2)
809 else if (
DIFF(parent) == 1)
822 if (p == Node::NullPtr)
823 return Node::NullPtr;
825 if (
RLINK(p) == Node::NullPtr)
838 while (
RLINK(*
pp) != Node::NullPtr)
854 if (
DIFF(parent) == -2)
862 else if (
DIFF(parent) == -1)
877 if (
t1 == Node::NullPtr)
879 if (
t2 == Node::NullPtr)
886 if (
t1 != Node::NullPtr)
895 if (
t2 != Node::NullPtr)
913 DIFF(
pivot) =
static_cast<signed char>(
h2) -
static_cast<signed char>(
h1);
970 if (
DIFF(parent) == 2)
1019 if (
DIFF(parent) == -2)
1037 if (p == Node::NullPtr)
1039 t1 =
t2 = Node::NullPtr;
1040 return Node::NullPtr;
1051 LLINK(p) = Node::NullPtr;
1056 RLINK(p) = Node::NullPtr;
1062 else if (
cmp(
KEY(p), key))
1069 RLINK(p) = Node::NullPtr;
1074 LLINK(p) = Node::NullPtr;
1098 if (p == Node::NullPtr)
1100 t1 =
t2 = Node::NullPtr;
1110 LLINK(p) = Node::NullPtr;
1115 RLINK(p) = Node::NullPtr;
1127 RLINK(p) = Node::NullPtr;
1132 LLINK(p) = Node::NullPtr;
1144 if (p == Node::NullPtr)
1146 t1 =
t2 = Node::NullPtr;
1157 LLINK(p) = Node::NullPtr;
1162 RLINK(p) = Node::NullPtr;
1175 RLINK(p) = Node::NullPtr;
1180 LLINK(p) = Node::NullPtr;
1199 if (t.root == Node::NullPtr)
1202 if (
root == Node::NullPtr)
1205 t.root = Node::NullPtr;
1213 t.root = Node::NullPtr;
1227 if (right != Node::NullPtr)
1229 if (left != Node::NullPtr)
1250 if (
root == Node::NullPtr)
1257 root = Node::NullPtr;
1265 if (right != Node::NullPtr)
1267 if (left != Node::NullPtr)
1276 else if (
cmp(key,
KEY(p)))
1300 if (
root == Node::NullPtr)
1305 root = Node::NullPtr;
1313 if (right != Node::NullPtr)
1315 if (left != Node::NullPtr)
1325 (
void)
t1.insert_dup(p);
1344 if (
root == Node::NullPtr)
1350 root = Node::NullPtr;
1357 root = Node::NullPtr;
1365 root = Node::NullPtr;
1370 while (curr != Node::NullPtr)
1374 LLINK(curr) = Node::NullPtr;
1380 RLINK(curr) = Node::NullPtr;
1408 using Base::operator=;
1422 template <
typename Key,
class Compare = Aleph::less<Key>>
1439 template <
typename Key,
class Compare = Aleph::less<Key>>
Exception handling system with formatted messages for Aleph-w.
#define AH_ERROR(format, args...)
Print an error message (always enabled).
Standard functor implementations and comparison objects.
AVL tree node with rank (subtree count).
#define DIFF(p)
Access the balance factor of node p.
Base iterator template for ranked binary search trees.
T & insert(const T &item)
Insert a new item by copy.
T & push(const T &data) noexcept
Push a copy of data
size_t size() const noexcept
Return the number of elements stored in the stack.
T popn(const int &n) noexcept
Perform in constant time n pops.
bool is_empty() const noexcept
Return true if stack is empty.
T & top() const noexcept
Return a modifiable referemce to stack's top.
T pop() noexcept
Pop by moving the top of stack.
AVL balanced binary search tree with rank (order statistics).
Node * insert(Node *p) noexcept
Insert the node pointed by p in the tree.
void split_key_dup_rec(Node *p, const Key &key, Node *&t1, Node *&t2) noexcept
static Node * join_with_pivot(Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
constexpr Compare & key_comp() noexcept
The key type.
Node * search_and_stack_avl(const Key &key, signed char &cmp_result) noexcept
static size_t avl_height(Node *p) noexcept
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
static Node * join_exclusive_rec(Node *t1, size_t h1, Node *t2, size_t h2) noexcept
Gen_Avl_Tree_Rk(Compare cmf_fct=Compare()) noexcept
Node * select(const size_t i) const
Return the i-th node in order sense.
Node * search_dup_and_stack_avl(const Key &key, signed char &cmp_result) noexcept
bool avl_stack_empty() noexcept
void update_counters_after_insertion() noexcept
static Node * join_left(Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
static Rotation_Type rotation_type(Node *p) noexcept
void restore_avl_after_insertion(Node *p) noexcept
std::pair< long, Node * > find_position(const Key &key) const noexcept
Find the inorder position of a key in the tree.
Node * split_key_rec(Node *p, const Key &key, Node *&t1, Node *&t2) noexcept
Node * remove(const Key &key) noexcept
Remove from tree the node containing key.
static Node * restore_avl(Node *p, Node *pp) noexcept
static Node * rotateLeft(Node *p) noexcept
size_t size() const noexcept
Return the number of nodes in the tree.
void split_pos_rec(Node *p, size_t pos, Node *&t1, Node *&t2) noexcept
static Node * extract_max(Node *&p) noexcept
virtual ~Gen_Avl_Tree_Rk() noexcept
static Node * extract_min(Node *&p) noexcept
static Node * rotateRight(Node *p) noexcept
void join_exclusive(Gen_Avl_Tree_Rk &t) noexcept
Join this tree exclusively with another tree.
Node * swapWithSuccessor(Node *p, Node *&pp) noexcept
constexpr bool is_empty() const noexcept
Return true if tree is empty.
static Node * doubleRotateLeft(Node *p) noexcept
constexpr Compare & get_compare() noexcept
void swap(Gen_Avl_Tree_Rk &tree) noexcept
Swap in constant time all the items of this with the items of tree.
Node * insert_dup(Node *p) noexcept
Insert the node p without testing for key duplicity.
void restore_avl_after_deletion(bool left_deficit) noexcept
void split_key_dup(const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by key including duplicates.
static Node * doubleRotateRight(Node *p) noexcept
Node * split_key(const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by key.
void split_pos(const size_t pos, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by inorder position.
constexpr Node * getRoot() const noexcept
Return a modifiable reference to tree's root.
bool verify() const noexcept
Return true if the tree is a valid AVL tree with correct counters.
Node * search(const Key &key) const noexcept
Search a node containing key; if found, then a pointer to the node containing it is returned; otherwi...
void update_counters_after_deletion() noexcept
void clean_avl_stack() noexcept
FixedStack< Node * > avl_stack
The type of node.
std::pair< long, Node * > position(const Key &key) const noexcept
Compute the inorder position of a key.
static Node * join_right(Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept
Compute the inorder position of a key.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
bool is_avl_rk(Node *p)
Verify if tree rooted at p is a valid AVL tree with correct counters.
@ CmpGreater
First argument is greater than second.
@ CmpLess
First argument is less than second.
@ CmpEqual
Arguments are equal.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
AVL binary search tree with virtual destructor in its nodes and with subtree counters for select/posi...
AVL binary search tree with nodes without virtual destructor and with subtree counters for select/pos...
Stack implementations backed by dynamic or fixed arrays.
Utility functions for binary tree operations.
Extended binary node with subtree count.
Binary tree operations (split, join, rotate).