45# ifndef TPL_HTDRBTREERK_H
46# define TPL_HTDRBTREERK_H
91template <
class Key,
class Compare = Aleph::less<Key>>
112 bool less(
const Key &
k1,
const Key &
k2)
const noexcept
249 const Key &
qk =
KEY(q);
265 const Key &
pk =
KEY(p);
302 const Key &
pk =
KEY(p);
328 const Key &
qk =
KEY(q);
343 const Key &
pk =
KEY(p);
376 const Key &
pk =
KEY(p);
408 const Key &
pk =
KEY(p);
460 if (
RLINK(p) == succ)
733 std::swap(
root, tree.root);
734 std::swap(
cmp, tree.cmp);
794 const Key &
pk =
KEY(p);
822 const Key &
pk =
KEY(p);
871 std::pair<long, Node*>
position(
const Key & key)
const noexcept
873 std::pair<long, Node*>
ret_val;
888 std::pair<long, Node*> r;
978template <
class Key,
class Compare = Aleph::less<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Inorder iterator on the nodes of a binary tree.
T & insert(const T &item)
Insert a new item by copy.
T & push(const T &data) noexcept
Push a copy of data
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.
void empty() noexcept
Empty the stack.
size_t size() const noexcept
Count the number of elements of the list.
Hybrid RB tree with rank and virtual destructor.
Hybrid top-down/bottom-up red-black tree with rank support.
void findSuccAndSwap(Node *p, Node *&fp) noexcept
Node * search(const Key &key) const noexcept
Node * insert_dup(Node *p) noexcept
const Compare & key_comp() const noexcept
HtdRbTreeRk(Compare __cmp=Compare()) noexcept
std::pair< long, Node * > find_position(const Key &key) const noexcept
Find position where key would be inserted.
void restoreRedCondition(Node *p, Node *&fp, Node *ffp, Node *fffp) noexcept
constexpr const Compare & get_compare() const noexcept
static void colorParentAndSibling(Node *fp, Node *sp) noexcept
static Node * getSibling(Node *p, Node *fp) noexcept
Node * searchFlipColorsAndInsertDup(Node *q) noexcept
Node * search_or_insert(Node *p) noexcept
void balanceDownAndColor(Node *p, Node *&fp, Node *&sp) noexcept
FixedStack< Node * > path
static void flipColors(Node *p) noexcept
static Node * rotate_to_left_rk(Node *p, Node *fp) noexcept
Left rotation with count update.
virtual ~HtdRbTreeRk()=default
void rotateNephewAndColor(Node *fp, Node *sp, Node *np) noexcept
static bool verifyCountsRec(Node *p) noexcept
bool verify() const noexcept
Verify red-black and rank invariants.
Compare & key_comp() noexcept
static void updateCountRec(Node *p) noexcept
Recursively update counts for entire subtree - O(n)
Node *& getRoot() noexcept
size_t size() const noexcept
O(1) size using root count.
bool equals(const Key &k1, const Key &k2) const noexcept
HtdRbTreeRk(HtdRbTreeRk &&tree) noexcept
void split_pos(size_t pos, HtdRbTreeRk &t1, HtdRbTreeRk &t2)
Split tree at position.
Node * select(size_t i) const
Select the i-th smallest element (0-indexed).
HtdRbTreeRk & operator=(const HtdRbTreeRk &)=delete
Node * getRoot() const noexcept
std::pair< long, Node * > position(const Key &key) const noexcept
Find position of a key.
HtdRbTreeRk & operator=(HtdRbTreeRk &&tree) noexcept
Compare & get_compare() noexcept
void removeAndFixBlackCondition(Node *q) noexcept
Remove node and fix red-black violations.
void swap(HtdRbTreeRk &tree) noexcept
constexpr bool is_empty() const noexcept
Node * remove(const Key &key) noexcept
HtdRbTreeRk(const HtdRbTreeRk &)=delete
Node * searchFlipColorsAndInsert(Node *q) noexcept
Insert with stack tracking for count updates.
static Node * rotate_to_right_rk(Node *p, Node *fp) noexcept
Right rotation with count update.
Node * insert(Node *p) noexcept
Node * searchAndBuildPath(const Key &key) noexcept
void doubleRotateNephewAndColor(Node *fp, Node *sp, Node *snp) noexcept
bool less(const Key &k1, const Key &k2) const noexcept
static void colorSiblingAsRed(Node *sp) noexcept
Node * remove_pos(size_t i)
Remove element at position i.
Extended Red-Black node with subtree counter.
RbNodeRk *& getR() noexcept
static const size_t MaxHeight
static RbNodeRk *const NullPtr
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept
Compute the inorder position of a key.
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_red_black_bst_rk(Node *node, Compare &cmp)
Verify that tree rooted at node is a valid red-black BST with counters.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Red-Black tree node with rank (subtree count).
#define BLACK
Black color constant.
#define RED
Red color constant (newly inserted nodes are red)
Iterator(const HtdRbTreeRk &t) noexcept
Iterator(HtdRbTreeRk &t) noexcept
Stack implementations backed by dynamic or fixed arrays.
Utility functions for binary tree operations.
Extended binary node with subtree count.
Basic binary tree node definitions.
Binary tree operations (split, join, rotate).