110 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
177 while (p != Node::NullPtr);
219 while (p != Node::NullPtr);
298 else if (
DIFF(
r) == -1)
314 [[gnu::always_inline]]
338 else if (
DIFF(
r) == -1)
448 while (
LLINK(succ) != Node::NullPtr)
464 LLINK(p) = Node::NullPtr;
466 if (
RLINK(p) == succ)
522 for (
size_t i = 0; i < sz - 1; ++i)
530 for (
size_t i = 0; i < sz - 1; ++i)
557 std::swap(
root, tree.root);
558 std::swap(
cmp, tree.cmp);
580 return result == Node::NullPtr ?
nullptr : result;
590 if (
root == Node::NullPtr)
620 if (
root == Node::NullPtr)
644 if (
root == Node::NullPtr)
664 if (
root == Node::NullPtr)
681 if (
LLINK(p) == Node::NullPtr)
690 if (
RLINK(p) == Node::NullPtr)
734 std::pair<long, Node *>
position(
const Key & key)
const noexcept
736 std::pair<long, Node *>
ret_val;
751 std::pair<long, Node *>
r(-2,
nullptr);
770 while (p != Node::NullPtr)
786 if (p == Node::NullPtr)
787 return Node::NullPtr;
789 if (
LLINK(p) == Node::NullPtr)
803 while (
LLINK(*
pp) != Node::NullPtr)
820 if (
DIFF(parent) == 2)
829 else if (
DIFF(parent) == 1)
842 if (p == Node::NullPtr)
843 return Node::NullPtr;
845 if (
RLINK(p) == Node::NullPtr)
858 while (
RLINK(*
pp) != Node::NullPtr)
874 if (
DIFF(parent) == -2)
882 else if (
DIFF(parent) == -1)
897 if (
t1 == Node::NullPtr)
899 if (
t2 == Node::NullPtr)
906 if (
t1 != Node::NullPtr)
915 if (
t2 != Node::NullPtr)
933 DIFF(
pivot) =
static_cast<signed char>(
h2) -
static_cast<signed char>(
h1);
990 if (
DIFF(parent) == 2)
1004 Node *
t2,
const size_t h2)
noexcept
1039 if (
DIFF(parent) == -2)
1057 if (p == Node::NullPtr)
1059 t1 =
t2 = Node::NullPtr;
1060 return Node::NullPtr;
1071 LLINK(p) = Node::NullPtr;
1076 RLINK(p) = Node::NullPtr;
1082 else if (
cmp(
KEY(p), key))
1089 RLINK(p) = Node::NullPtr;
1094 LLINK(p) = Node::NullPtr;
1118 if (p == Node::NullPtr)
1120 t1 =
t2 = Node::NullPtr;
1130 LLINK(p) = Node::NullPtr;
1135 RLINK(p) = Node::NullPtr;
1147 RLINK(p) = Node::NullPtr;
1152 LLINK(p) = Node::NullPtr;
1164 if (p == Node::NullPtr)
1166 t1 =
t2 = Node::NullPtr;
1177 LLINK(p) = Node::NullPtr;
1182 RLINK(p) = Node::NullPtr;
1195 RLINK(p) = Node::NullPtr;
1200 LLINK(p) = Node::NullPtr;
1219 if (t.root == Node::NullPtr)
1222 if (
root == Node::NullPtr)
1225 t.root = Node::NullPtr;
1233 t.root = Node::NullPtr;
1247 if (right != Node::NullPtr)
1249 if (left != Node::NullPtr)
1270 if (
root == Node::NullPtr)
1274 Node *found =
nullptr;
1277 root = Node::NullPtr;
1285 if (right != Node::NullPtr)
1287 if (left != Node::NullPtr)
1296 else if (
cmp(key,
KEY(p)))
1320 if (
root == Node::NullPtr)
1325 root = Node::NullPtr;
1333 if (right != Node::NullPtr)
1335 if (left != Node::NullPtr)
1345 (
void)
t1.insert_dup(p);
1364 if (
root == Node::NullPtr)
1370 root = Node::NullPtr;
1377 root = Node::NullPtr;
1385 root = Node::NullPtr;
1390 while (curr != Node::NullPtr)
1394 LLINK(curr) = Node::NullPtr;
1400 RLINK(curr) = Node::NullPtr;
1407 (
void)
t2.insert(curr);
1428 using Base::operator=;
1442 template <
typename Key,
class Compare = Aleph::less<Key>>
1460 template <
typename Key,
class Compare = Aleph::less<Key>>
C++20 concepts for constraining comparison functors.
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 & 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.
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.
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.
and
Check uniqueness with explicit hash + equality functors.
bool is_avl_rk(Node *p)
Verify if tree rooted at p is a valid AVL tree with correct counters.
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.
@ 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.
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).