106template <
template <
typename>
class NodeType,
typename Key,
class Compare>
169 }
while (p != Node::NullPtr);
207 }
while (p != Node::NullPtr);
286 else if (
DIFF(
r) == -1)
302 [[gnu::always_inline]]
326 else if (
DIFF(
r) == -1)
442 while (
LLINK(succ) != Node::NullPtr)
458 LLINK(p) = Node::NullPtr;
460 if (
RLINK(p) == succ)
516 for (
size_t i = 0; i < sz - 1; ++i)
524 for (
size_t i = 0; i < sz - 1; ++i)
556 std::swap(
root, tree.root);
557 std::swap(
cmp, tree.cmp);
586 return root == Node::NullPtr;
594 return result == Node::NullPtr ? nullptr : result;
604 if (
root == Node::NullPtr)
634 if (
root == Node::NullPtr)
658 if (
root == Node::NullPtr)
678 if (
root == Node::NullPtr)
695 if (
LLINK(p) == Node::NullPtr)
704 if (
RLINK(p) == Node::NullPtr)
748 std::pair<long, Node *>
position(
const Key &key)
const noexcept
750 std::pair<long, Node *>
ret_val;
765 std::pair<long, Node *>
r(-2,
nullptr);
797 while (p != Node::NullPtr)
813 if (p == Node::NullPtr)
814 return Node::NullPtr;
816 if (
LLINK(p) == Node::NullPtr)
830 while (
LLINK(*
pp) != Node::NullPtr)
847 if (
DIFF(parent) == 2)
856 else if (
DIFF(parent) == 1)
869 if (p == Node::NullPtr)
870 return Node::NullPtr;
872 if (
RLINK(p) == Node::NullPtr)
885 while (
RLINK(*
pp) != Node::NullPtr)
901 if (
DIFF(parent) == -2)
909 else if (
DIFF(parent) == -1)
923 if (
t1 == Node::NullPtr)
925 if (
t2 == Node::NullPtr)
932 if (
t1 != Node::NullPtr)
941 if (
t2 != Node::NullPtr)
952 const size_t h2)
noexcept
959 DIFF(
pivot) =
static_cast<signed char>(
static_cast<long>(
h2) -
static_cast<long>(
h1));
999 DIFF(
pivot) =
static_cast<signed char>(
static_cast<long>(
h2) -
static_cast<long>(
left_h));
1014 if (
DIFF(parent) == 2)
1047 DIFF(
pivot) =
static_cast<signed char>(
static_cast<long>(
right_h) -
static_cast<long>(
h1));
1061 if (
DIFF(parent) == -2)
1078 if (p == Node::NullPtr)
1080 t1 =
t2 = Node::NullPtr;
1081 return Node::NullPtr;
1092 LLINK(p) = Node::NullPtr;
1097 RLINK(p) = Node::NullPtr;
1103 else if (
cmp(
KEY(p), key))
1110 RLINK(p) = Node::NullPtr;
1115 LLINK(p) = Node::NullPtr;
1138 if (p == Node::NullPtr)
1140 t1 =
t2 = Node::NullPtr;
1150 LLINK(p) = Node::NullPtr;
1155 RLINK(p) = Node::NullPtr;
1167 RLINK(p) = Node::NullPtr;
1172 LLINK(p) = Node::NullPtr;
1184 if (p == Node::NullPtr)
1186 t1 =
t2 = Node::NullPtr;
1197 LLINK(p) = Node::NullPtr;
1202 RLINK(p) = Node::NullPtr;
1215 RLINK(p) = Node::NullPtr;
1220 LLINK(p) = Node::NullPtr;
1239 if (t.root == Node::NullPtr)
1242 if (
root == Node::NullPtr)
1245 t.root = Node::NullPtr;
1253 t.root = Node::NullPtr;
1267 if (right != Node::NullPtr)
1269 if (left != Node::NullPtr)
1291 if (
root == Node::NullPtr)
1295 Node *found =
nullptr;
1298 root = Node::NullPtr;
1306 if (right != Node::NullPtr)
1308 if (left != Node::NullPtr)
1317 else if (
cmp(key,
KEY(p)))
1318 (
void)
t2.insert(p);
1342 if (
root == Node::NullPtr)
1347 root = Node::NullPtr;
1355 if (right != Node::NullPtr)
1357 if (left != Node::NullPtr)
1367 (
void)
t1.insert_dup(p);
1387 if (
root == Node::NullPtr)
1393 root = Node::NullPtr;
1400 root = Node::NullPtr;
1408 root = Node::NullPtr;
1413 while (curr != Node::NullPtr)
1417 LLINK(curr) = Node::NullPtr;
1423 RLINK(curr) = Node::NullPtr;
1430 (
void)
t2.insert(curr);
1451 using Base::operator =;
1466template <
typename Key,
class Compare = Aleph::less<Key>>
1485template <
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.
#define AH_ERROR(...)
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 & base() noexcept
Return the internal array base.
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 pop() noexcept
Pop by moving the top of stack.
T & top() noexcept
Return a modifiable reference to stack's top.
void empty() noexcept
Empty the stack.
T & push(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
Push a copy of data
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.
bool avl_stack_at_base() noexcept
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
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 pointer to the 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
Strict weak ordering constraint for BST comparators.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
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.
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.
and
Check uniqueness with explicit hash + equality functors.
@ CmpGreater
First argument is greater than second.
@ CmpLess
First argument is less than second.
@ CmpEqual
Arguments are equal.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Ranked AVL tree with nodes with a virtual destructor.
Ranked AVL tree with nodes without a virtual destructor.
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).