Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::HtdRbTreeRk< Key, Compare > Class Template Reference

Hybrid top-down/bottom-up red-black tree with rank support. More...

#include <tpl_hRbTreeRk.H>

Inheritance diagram for Aleph::HtdRbTreeRk< Key, Compare >:
[legend]
Collaboration diagram for Aleph::HtdRbTreeRk< Key, Compare >:
[legend]

Classes

struct  Iterator
 In-order iterator. More...
 

Public Types

using Color = unsigned char
 
using Node = RbNodeRk< Key >
 
using key_type = Key
 

Public Member Functions

Compare & key_comp () noexcept
 
const Compare & key_comp () const noexcept
 
Compare & get_compare () noexcept
 
constexpr const Compare & get_compare () const noexcept
 
 HtdRbTreeRk () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >)
 Builds an empty tree with a comparison criteria built by default.
 
 HtdRbTreeRk (Compare __cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >)
 Builds an empty tree with the comparison criteria __cmp.
 
void swap (HtdRbTreeRk &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swaps in constant time the nodes and the comparison criteria of this and tree.
 
 HtdRbTreeRk (HtdRbTreeRk &&tree) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >)
 Takes the nodes and the comparison criteria of tree, which is left empty and can take nodes again.
 
HtdRbTreeRk & operator= (HtdRbTreeRk &&tree) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swaps the nodes and the comparison criteria with tree.
 
 HtdRbTreeRk (const HtdRbTreeRk &)=delete
 
HtdRbTreeRk & operator= (const HtdRbTreeRk &)=delete
 
virtual ~HtdRbTreeRk ()=default
 
constexpr bool is_empty () const noexcept
 
size_t size () const noexcept
 O(1) size using root count.
 
void reset () noexcept
 
Node * insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert a node into the tree.
 
Node * search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Search for key or insert if not found.
 
Node * insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert allowing duplicate keys.
 
Node * search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
 Search for a key.
 
Node * remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
 Remove node with given key.
 
Node *& getRoot () noexcept
 
Node * getRoot () const noexcept
 
Node * select (size_t i) const
 Select the i-th smallest element (0-indexed).
 
std::pair< long, Node * > position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
 Find position of a key.
 
std::pair< long, Node * > find_position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
 Find position where key would be inserted.
 
Node * remove_pos (size_t i)
 Remove element at position i.
 
void split_pos (size_t pos, HtdRbTreeRk &t1, HtdRbTreeRk &t2)
 Split tree at position.
 
bool verify () const
 Verify red-black and rank invariants.
 

Private Types

using Path = InlineStack< Node *, Node::MaxHeight+1 >
 

Private Member Functions

bool less (const Key &k1, const Key &k2) const noexcept(nothrow_compare_v< Compare, Key >)
 
bool equals (const Key &k1, const Key &k2) const noexcept(nothrow_compare_v< Compare, Key >)
 
void restoreRedCondition (Node *p, Node *&fp, Node *ffp, Node *fffp) noexcept
 
Node * searchFlipColorsAndInsert (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 Insert with stack tracking for count updates.
 
Node * searchFlipColorsAndInsertDup (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 
Node * searchAndBuildPath (const Key &key, Path &path) noexcept(nothrow_compare_v< Compare, Key >)
 
void findSuccAndSwap (Node *p, Node *&fp, Path &path) noexcept
 
void balanceDownAndColor (Node *p, Node *&fp, Node *&sp, Path &path) noexcept
 
void rotateNephewAndColor (Node *fp, Node *sp, Node *np, Path &path) noexcept
 
void doubleRotateNephewAndColor (Node *fp, Node *sp, Node *snp, Path &path) noexcept
 
void removeAndFixBlackCondition (Node *q, Path &path) noexcept
 Remove node and fix red-black violations.
 
void init () noexcept
 

Static Private Member Functions

static Node * getSibling (Node *p, Node *fp) noexcept
 
static Node * rotate_to_right_rk (Node *p, Node *fp) noexcept
 Right rotation with count update.
 
static Node * rotate_to_left_rk (Node *p, Node *fp) noexcept
 Left rotation with count update.
 
static void flipColors (Node *p) noexcept
 
static void colorSiblingAsRed (Node *sp) noexcept
 
static void colorParentAndSibling (Node *fp, Node *sp) noexcept
 
static void updateCountRec (Node *p) noexcept
 Recursively update counts for entire subtree - O(n)
 
static bool verifyCountsRec (Node *p) noexcept
 

Private Attributes

Node headNode
 
Node headParent
 
Node headGrandParent
 
Node * head
 
Node * fHead
 
Node * ffHead
 
Node *& root
 
Compare cmp
 

Detailed Description

template<class Key, class Compare = Aleph::less<Key>>
requires StrictWeakOrder<Compare, Key>
class Aleph::HtdRbTreeRk< Key, Compare >

Hybrid top-down/bottom-up red-black tree with rank support.

This class implements a self-balancing binary search tree with O(log n) rank operations (select, position). It combines:

  • Insertion: Top-down with proactive color flipping and stack tracking
  • Deletion: Bottom-up using a stack to track ancestors
  • Rank operations: Subtree counts maintained during all operations
Complexity (ALL O(log n)):
  • search, insert, remove: O(log n)
  • select(i): O(log n) - get i-th smallest element
  • position(key): O(log n) - get rank of a key
  • find_position(key): O(log n) - get insertion position
  • size(): O(1)

This is the only implementation that achieves O(log n) for ALL operations including removal with rank support.

Template Parameters
KeyThe type of keys stored in the tree
CompareComparison functor (default: Aleph::less<Key>)
See also
HtdRbTree Hybrid tree without rank support
Gen_Rb_Tree_Rk Bottom-up tree with rank
GenTdRbTreeRk Top-down tree with rank (O(n) remove)
Author
Leandro Rabindranath León

Definition at line 94 of file tpl_hRbTreeRk.H.

Member Typedef Documentation

◆ Color

template<class Key , class Compare = Aleph::less<Key>>
using Aleph::HtdRbTreeRk< Key, Compare >::Color = unsigned char

Definition at line 97 of file tpl_hRbTreeRk.H.

◆ key_type

template<class Key , class Compare = Aleph::less<Key>>
using Aleph::HtdRbTreeRk< Key, Compare >::key_type = Key

Definition at line 734 of file tpl_hRbTreeRk.H.

◆ Node

template<class Key , class Compare = Aleph::less<Key>>
using Aleph::HtdRbTreeRk< Key, Compare >::Node = RbNodeRk<Key>

Definition at line 98 of file tpl_hRbTreeRk.H.

◆ Path

template<class Key , class Compare = Aleph::less<Key>>
using Aleph::HtdRbTreeRk< Key, Compare >::Path = InlineStack<Node *, Node::MaxHeight + 1>
private

Definition at line 117 of file tpl_hRbTreeRk.H.

Constructor & Destructor Documentation

◆ HtdRbTreeRk() [1/4]

template<class Key , class Compare = Aleph::less<Key>>
Aleph::HtdRbTreeRk< Key, Compare >::HtdRbTreeRk ( )
inlinenoexcept

Builds an empty tree with a comparison criteria built by default.

It is a constructor apart from the one that takes the comparison, and not a default argument of that one: GCC and Clang do not count a default argument in the noexcept of the implicit default constructor of a tree that inherits these, and what the construction of the comparison threw would end the program there.

Exceptions
whatthe default construction of the key of a header node or of the comparison, or the copy of the comparison, throws; nothing when they are noexcept.

Definition at line 754 of file tpl_hRbTreeRk.H.

◆ HtdRbTreeRk() [2/4]

template<class Key , class Compare = Aleph::less<Key>>
Aleph::HtdRbTreeRk< Key, Compare >::HtdRbTreeRk ( Compare  __cmp)
inlinenoexcept

Builds an empty tree with the comparison criteria __cmp.

Parameters
[in]__cmpthe comparison criteria, which the tree copies.
Exceptions
whatthe default construction of the key of a header node or the copy of __cmp throws; nothing when both are noexcept. The copy is from a Compare that is not const, which a comparison may have apart from the one from a const one.

Definition at line 771 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::init().

◆ HtdRbTreeRk() [3/4]

template<class Key , class Compare = Aleph::less<Key>>
Aleph::HtdRbTreeRk< Key, Compare >::HtdRbTreeRk ( HtdRbTreeRk< Key, Compare > &&  tree)
inlinenoexcept

Takes the nodes and the comparison criteria of tree, which is left empty and can take nodes again.

It builds no key, if it can: the key of each of the three header nodes is built by default when that cannot throw; else it is that of the same header node of tree, moved, when the move of a key cannot throw (see bin_node_detail::header_from()).

Parameters
[in,out]treethe tree to move from. It keeps its comparison criteria, which are copied: from a const one, or from one that is not const, if they have only that copy. Criteria that cannot be copied are moved, and tree keeps criteria that were moved from.
Exceptions
whatthe copy of the comparison criteria throws, or their move if they cannot be copied; and what the default construction of the key of a header node throws, with a key whose move may throw too. Then tree keeps its nodes. Nothing when they are noexcept.

Definition at line 815 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::init(), Aleph::RbNodeRk< Key >::NullPtr, and Aleph::HtdRbTreeRk< Key, Compare >::root.

◆ HtdRbTreeRk() [4/4]

template<class Key , class Compare = Aleph::less<Key>>
Aleph::HtdRbTreeRk< Key, Compare >::HtdRbTreeRk ( const HtdRbTreeRk< Key, Compare > &  )
delete

◆ ~HtdRbTreeRk()

template<class Key , class Compare = Aleph::less<Key>>
virtual Aleph::HtdRbTreeRk< Key, Compare >::~HtdRbTreeRk ( )
virtualdefault

Member Function Documentation

◆ balanceDownAndColor()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::balanceDownAndColor ( Node *  p,
Node *&  fp,
Node *&  sp,
Path &  path 
)
inlineprivatenoexcept

◆ colorParentAndSibling()

template<class Key , class Compare = Aleph::less<Key>>
static void Aleph::HtdRbTreeRk< Key, Compare >::colorParentAndSibling ( Node *  fp,
Node *  sp 
)
inlinestaticprivatenoexcept

Definition at line 588 of file tpl_hRbTreeRk.H.

References BLACK, COLOR, LLINK, RED, and RLINK.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::removeAndFixBlackCondition().

◆ colorSiblingAsRed()

template<class Key , class Compare = Aleph::less<Key>>
static void Aleph::HtdRbTreeRk< Key, Compare >::colorSiblingAsRed ( Node *  sp)
inlinestaticprivatenoexcept

Definition at line 582 of file tpl_hRbTreeRk.H.

References BLACK, COLOR, and RED.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::removeAndFixBlackCondition().

◆ doubleRotateNephewAndColor()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::doubleRotateNephewAndColor ( Node *  fp,
Node *  sp,
Node *  snp,
Path &  path 
)
inlineprivatenoexcept

◆ equals()

template<class Key , class Compare = Aleph::less<Key>>
bool Aleph::HtdRbTreeRk< Key, Compare >::equals ( const Key &  k1,
const Key &  k2 
) const
inlineprivatenoexcept

◆ find_position()

template<class Key , class Compare = Aleph::less<Key>>
std::pair< long, Node * > Aleph::HtdRbTreeRk< Key, Compare >::find_position ( const Key &  key) const
inlinenoexcept

Find position where key would be inserted.

Works even if key doesn't exist in the tree.

Parameters
keyKey to find position for
Returns
Pair of (position, node). Node is nullptr if key not found.
Exceptions
anythingthat the comparison or its copy throws; the search does not modify the tree, so it is left as it was.
Note
It is noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller.

Definition at line 1034 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp, Aleph::HtdRbTreeRk< Key, Compare >::find_position(), r, and Aleph::HtdRbTreeRk< Key, Compare >::root.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::find_position().

◆ findSuccAndSwap()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::findSuccAndSwap ( Node *  p,
Node *&  fp,
Path &  path 
)
inlineprivatenoexcept

◆ flipColors()

template<class Key , class Compare = Aleph::less<Key>>
static void Aleph::HtdRbTreeRk< Key, Compare >::flipColors ( Node *  p)
inlinestaticprivatenoexcept

◆ get_compare() [1/2]

template<class Key , class Compare = Aleph::less<Key>>
constexpr const Compare & Aleph::HtdRbTreeRk< Key, Compare >::get_compare ( ) const
inlineconstexprnoexcept

Definition at line 739 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp.

◆ get_compare() [2/2]

template<class Key , class Compare = Aleph::less<Key>>
Compare & Aleph::HtdRbTreeRk< Key, Compare >::get_compare ( )
inlinenoexcept

Definition at line 738 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp.

◆ getRoot() [1/2]

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::getRoot ( ) const
inlinenoexcept

Definition at line 990 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::root.

◆ getRoot() [2/2]

template<class Key , class Compare = Aleph::less<Key>>
Node *& Aleph::HtdRbTreeRk< Key, Compare >::getRoot ( )
inlinenoexcept

Definition at line 989 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::root.

◆ getSibling()

template<class Key , class Compare = Aleph::less<Key>>
static Node * Aleph::HtdRbTreeRk< Key, Compare >::getSibling ( Node *  p,
Node *  fp 
)
inlinestaticprivatenoexcept

Definition at line 130 of file tpl_hRbTreeRk.H.

References LLINK, and RLINK.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::removeAndFixBlackCondition().

◆ init()

◆ insert()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::insert ( Node *  p)
inlinenoexcept

Insert a node into the tree.

Parameters
pNode to insert (must have COLOR=RED and null children)
Returns
Pointer to inserted node, or nullptr if duplicate key
Exceptions
anythingthat the comparison throws; the color flips and rotations done on the way down leave a valid red-black tree with right counters, and p is linked after the last comparison, so the tree keeps its keys, without p.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 869 of file tpl_hRbTreeRk.H.

References COLOR, Aleph::COUNT(), Aleph::RbNodeRk< Key >::NullPtr, RED, Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::searchFlipColorsAndInsert().

Referenced by HtdRbTreeRkTest::insert_range(), Aleph::HtdRbTreeRk< Key, Compare >::search_or_insert(), Aleph::HtdRbTreeRk< Key, Compare >::split_pos(), and TEST_F().

◆ insert_dup()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::insert_dup ( Node *  p)
inlinenoexcept

Insert allowing duplicate keys.

Parameters
pNode to insert
Returns
Pointer to inserted node
Exceptions
anythingthat the comparison throws; then the tree is valid with its keys, without p, as in insert().
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 922 of file tpl_hRbTreeRk.H.

References COLOR, Aleph::COUNT(), Aleph::RbNodeRk< Key >::NullPtr, RED, Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::searchFlipColorsAndInsertDup().

◆ is_empty()

template<class Key , class Compare = Aleph::less<Key>>
constexpr bool Aleph::HtdRbTreeRk< Key, Compare >::is_empty ( ) const
inlineconstexprnoexcept

◆ key_comp() [1/2]

template<class Key , class Compare = Aleph::less<Key>>
const Compare & Aleph::HtdRbTreeRk< Key, Compare >::key_comp ( ) const
inlinenoexcept

Definition at line 737 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp.

◆ key_comp() [2/2]

template<class Key , class Compare = Aleph::less<Key>>
Compare & Aleph::HtdRbTreeRk< Key, Compare >::key_comp ( )
inlinenoexcept

Definition at line 736 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp.

◆ less()

template<class Key , class Compare = Aleph::less<Key>>
bool Aleph::HtdRbTreeRk< Key, Compare >::less ( const Key &  k1,
const Key &  k2 
) const
inlineprivatenoexcept

Definition at line 122 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp.

◆ operator=() [1/2]

template<class Key , class Compare = Aleph::less<Key>>
HtdRbTreeRk & Aleph::HtdRbTreeRk< Key, Compare >::operator= ( const HtdRbTreeRk< Key, Compare > &  )
delete

◆ operator=() [2/2]

template<class Key , class Compare = Aleph::less<Key>>
HtdRbTreeRk & Aleph::HtdRbTreeRk< Key, Compare >::operator= ( HtdRbTreeRk< Key, Compare > &&  tree)
inlinenoexcept

Swaps the nodes and the comparison criteria with tree.

Parameters
[in,out]treethe tree to swap with.
Returns
*this.
Exceptions
whatthe swap of the comparison criteria throws, which goes first: then the nodes stay where they were.

Definition at line 839 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::swap().

◆ position()

template<class Key , class Compare = Aleph::less<Key>>
std::pair< long, Node * > Aleph::HtdRbTreeRk< Key, Compare >::position ( const Key &  key) const
inlinenoexcept

Find position of a key.

Parameters
keyKey to find
Returns
Pair of (position, node). Position is -1 if not found.
Exceptions
anythingthat the comparison or its copy throws; the search does not modify the tree, so it is left as it was.
Note
It is noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller.

Definition at line 1014 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp, Aleph::inorder_position(), and Aleph::HtdRbTreeRk< Key, Compare >::root.

◆ remove()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::remove ( const Key &  key)
inlinenoexcept

Remove node with given key.

Parameters
keyKey to remove
Returns
Pointer to removed node, or nullptr if not found
Exceptions
anythingthat the comparison throws; the tree changes only after the last comparison, so it is left as it was.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 968 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::equals(), KEY, Aleph::RbNodeRk< Key >::NullPtr, Aleph::HtdRbTreeRk< Key, Compare >::removeAndFixBlackCondition(), Aleph::RbNodeRk< Key >::reset(), Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::searchAndBuildPath().

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::remove_pos().

◆ remove_pos()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::remove_pos ( size_t  i)
inline

Remove element at position i.

Parameters
iPosition (0-indexed)
Returns
Removed node
Exceptions
std::out_of_rangeif i >= size()

Definition at line 1049 of file tpl_hRbTreeRk.H.

References ah_out_of_range_error_if, KEY, Aleph::HtdRbTreeRk< Key, Compare >::remove(), Aleph::HtdRbTreeRk< Key, Compare >::select(), and Aleph::HtdRbTreeRk< Key, Compare >::size().

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::split_pos().

◆ removeAndFixBlackCondition()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::removeAndFixBlackCondition ( Node *  q,
Path &  path 
)
inlineprivatenoexcept

◆ reset()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::reset ( )
inlinenoexcept

◆ restoreRedCondition()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::restoreRedCondition ( Node *  p,
Node *&  fp,
Node *  ffp,
Node *  fffp 
)
inlineprivatenoexcept

◆ rotate_to_left_rk()

template<class Key , class Compare = Aleph::less<Key>>
static Node * Aleph::HtdRbTreeRk< Key, Compare >::rotate_to_left_rk ( Node *  p,
Node *  fp 
)
inlinestaticprivatenoexcept

◆ rotate_to_right_rk()

template<class Key , class Compare = Aleph::less<Key>>
static Node * Aleph::HtdRbTreeRk< Key, Compare >::rotate_to_right_rk ( Node *  p,
Node *  fp 
)
inlinestaticprivatenoexcept

Right rotation with count update.

After rotation:

  • q becomes parent of p
  • q.count = p.count (takes p's position)
  • p.count = 1 + LCOUNT + RCOUNT

Definition at line 145 of file tpl_hRbTreeRk.H.

References Aleph::COUNT(), LLINK, Aleph::RbNodeRk< Key >::NullPtr, and RLINK.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::balanceDownAndColor(), Aleph::HtdRbTreeRk< Key, Compare >::doubleRotateNephewAndColor(), Aleph::HtdRbTreeRk< Key, Compare >::restoreRedCondition(), and Aleph::HtdRbTreeRk< Key, Compare >::rotateNephewAndColor().

◆ rotateNephewAndColor()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::rotateNephewAndColor ( Node *  fp,
Node *  sp,
Node *  np,
Path &  path 
)
inlineprivatenoexcept

◆ search()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::search ( const Key &  key) const
inlinenoexcept

Search for a key.

Parameters
keyKey to search for
Returns
Pointer to node with key, or nullptr if not found
Exceptions
anythingthat the comparison throws; the search does not modify the tree, so it is left as it was.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 946 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::equals(), KEY, LLINK, Aleph::RbNodeRk< Key >::NullPtr, RLINK, and Aleph::HtdRbTreeRk< Key, Compare >::root.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::search_or_insert().

◆ search_or_insert()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::search_or_insert ( Node *  p)
inlinenoexcept

Search for key or insert if not found.

Parameters
pNode to insert if key not found
Returns
Existing node with key, or p if inserted
Exceptions
anythingthat the comparison throws; then the tree is valid with its keys, without p, as in insert().
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 893 of file tpl_hRbTreeRk.H.

References COLOR, Aleph::COUNT(), Aleph::HtdRbTreeRk< Key, Compare >::insert(), KEY, Aleph::RbNodeRk< Key >::NullPtr, RED, Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::search().

◆ searchAndBuildPath()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::searchAndBuildPath ( const Key &  key,
Path &  path 
)
inlineprivatenoexcept

◆ searchFlipColorsAndInsert()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::searchFlipColorsAndInsert ( Node *  q)
inlineprivatenoexcept

Insert with stack tracking for count updates.

Uses a stack to track the path during insertion, then updates counts bottom-up after all rotations are complete. Each color flip and rotation on the way down leaves a valid red-black tree with right counters, and q is linked after the last comparison, so a comparison that throws leaves a valid tree without q.

Definition at line 257 of file tpl_hRbTreeRk.H.

References BLACK, COLOR, Aleph::COUNT(), Aleph::HtdRbTreeRk< Key, Compare >::equals(), Aleph::HtdRbTreeRk< Key, Compare >::ffHead, Aleph::HtdRbTreeRk< Key, Compare >::fHead, Aleph::HtdRbTreeRk< Key, Compare >::flipColors(), Aleph::HtdRbTreeRk< Key, Compare >::head, KEY, LLINK, Aleph::RbNodeRk< Key >::NullPtr, RED, Aleph::HtdRbTreeRk< Key, Compare >::restoreRedCondition(), RLINK, and Aleph::HtdRbTreeRk< Key, Compare >::root.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::insert().

◆ searchFlipColorsAndInsertDup()

◆ select()

template<class Key , class Compare = Aleph::less<Key>>
Node * Aleph::HtdRbTreeRk< Key, Compare >::select ( size_t  i) const
inline

Select the i-th smallest element (0-indexed).

Parameters
iPosition (0 = smallest)
Returns
Pointer to node at position i
Exceptions
std::out_of_rangeif i >= size()

Definition at line 1000 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::select().

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::remove_pos(), and TEST_F().

◆ size()

template<class Key , class Compare = Aleph::less<Key>>
size_t Aleph::HtdRbTreeRk< Key, Compare >::size ( ) const
inlinenoexcept

◆ split_pos()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::split_pos ( size_t  pos,
HtdRbTreeRk< Key, Compare > &  t1,
HtdRbTreeRk< Key, Compare > &  t2 
)
inline

Split tree at position.

After split:

  • t1 contains elements at positions [0, pos)
  • t2 contains elements at positions [pos, size())
  • this tree becomes empty
Parameters
posSplit position
t1Tree for left part
t2Tree for right part
Exceptions
std::out_of_rangeif pos > size()
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
The nodes move one by one, and their insertion in t1 or t2 compares: a comparison that threw there would leave the node in transit out of every tree, so the move is noexcept.

Definition at line 1073 of file tpl_hRbTreeRk.H.

References ah_out_of_range_error_if, Aleph::HtdRbTreeRk< Key, Compare >::insert(), Aleph::RbNodeRk< Key >::NullPtr, Aleph::HtdRbTreeRk< Key, Compare >::remove_pos(), Aleph::HtdRbTreeRk< Key, Compare >::reset(), Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::size().

◆ swap()

template<class Key , class Compare = Aleph::less<Key>>
void Aleph::HtdRbTreeRk< Key, Compare >::swap ( HtdRbTreeRk< Key, Compare > &  tree)
inlinenoexcept

Swaps in constant time the nodes and the comparison criteria of this and tree.

Parameters
[in,out]treethe tree to swap with.
Exceptions
whatthe swap of the comparison criteria throws, which goes first: then the nodes stay where they were.

Definition at line 790 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp, and Aleph::HtdRbTreeRk< Key, Compare >::root.

Referenced by Aleph::HtdRbTreeRk< Key, Compare >::operator=().

◆ updateCountRec()

template<class Key , class Compare = Aleph::less<Key>>
static void Aleph::HtdRbTreeRk< Key, Compare >::updateCountRec ( Node *  p)
inlinestaticprivatenoexcept

◆ verify()

template<class Key , class Compare = Aleph::less<Key>>
bool Aleph::HtdRbTreeRk< Key, Compare >::verify ( ) const
inline

Verify red-black and rank invariants.

Returns
true if all invariants hold
Exceptions
whatthe comparator throws.

Definition at line 1100 of file tpl_hRbTreeRk.H.

References Aleph::HtdRbTreeRk< Key, Compare >::cmp, Aleph::is_red_black_bst_rk(), Aleph::RbNodeRk< Key >::NullPtr, Aleph::HtdRbTreeRk< Key, Compare >::root, and Aleph::HtdRbTreeRk< Key, Compare >::verifyCountsRec().

Referenced by TEST_F().

◆ verifyCountsRec()

template<class Key , class Compare = Aleph::less<Key>>
static bool Aleph::HtdRbTreeRk< Key, Compare >::verifyCountsRec ( Node *  p)
inlinestaticprivatenoexcept

Member Data Documentation

◆ cmp

◆ ffHead

template<class Key , class Compare = Aleph::less<Key>>
Node* Aleph::HtdRbTreeRk< Key, Compare >::ffHead
private

◆ fHead

template<class Key , class Compare = Aleph::less<Key>>
Node* Aleph::HtdRbTreeRk< Key, Compare >::fHead
private

◆ head

◆ headGrandParent

template<class Key , class Compare = Aleph::less<Key>>
Node Aleph::HtdRbTreeRk< Key, Compare >::headGrandParent
private

Definition at line 103 of file tpl_hRbTreeRk.H.

◆ headNode

template<class Key , class Compare = Aleph::less<Key>>
Node Aleph::HtdRbTreeRk< Key, Compare >::headNode
private

Definition at line 101 of file tpl_hRbTreeRk.H.

◆ headParent

template<class Key , class Compare = Aleph::less<Key>>
Node Aleph::HtdRbTreeRk< Key, Compare >::headParent
private

Definition at line 102 of file tpl_hRbTreeRk.H.

◆ root


The documentation for this class was generated from the following file: