45# ifndef TPL_HTDRBTREERK_H
46# define TPL_HTDRBTREERK_H
92template <
class Key,
class Compare = Aleph::less<Key>>
114 bool less(
const Key &
k1,
const Key &
k2)
const noexcept
251 const Key &
qk =
KEY(q);
267 const Key &
pk =
KEY(p);
304 const Key &
pk =
KEY(p);
330 const Key &
qk =
KEY(q);
345 const Key &
pk =
KEY(p);
378 const Key &
pk =
KEY(p);
410 const Key &
pk =
KEY(p);
462 if (
RLINK(p) == succ)
735 std::swap(
root, tree.root);
736 std::swap(
cmp, tree.cmp);
796 const Key &
pk =
KEY(p);
824 const Key &
pk =
KEY(p);
873 std::pair<long, Node*>
position(
const Key & key)
const noexcept
875 std::pair<long, Node*>
ret_val;
890 std::pair<long, Node*>
r;
980template <
class Key,
class Compare = Aleph::less<Key>>
C++20 concepts for constraining comparison functors.
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 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
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.
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_red_black_bst_rk(Node *node, Compare &cmp)
Verify that tree rooted at node is a valid red-black BST with 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.
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).