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

Top-down red-black tree with rank support (select/position). More...

#include <tpl_tdRbTreeRk.H>

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

Classes

struct  Iterator
 Iterator. More...
 

Public Types

using Node = NodeType< Key >
 
using key_type = Key
 
using compare_type = Compare
 

Public Member Functions

 GenTdRbTreeRk () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare >)
 Builds an empty tree with a comparison criteria built by default.
 
 GenTdRbTreeRk (const Compare &__cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_copy_constructible_v< Compare >)
 Builds an empty tree with the comparison criteria __cmp.
 
 GenTdRbTreeRk (GenTdRbTreeRk &&other) 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 other, which is left empty and can take nodes again.
 
GenTdRbTreeRk & operator= (GenTdRbTreeRk &&other) noexcept(std::is_nothrow_move_assignable_v< Compare >)
 Takes the nodes and the comparison criteria of other, which is left empty.
 
 GenTdRbTreeRk (const GenTdRbTreeRk &)=delete
 
GenTdRbTreeRk & operator= (const GenTdRbTreeRk &)=delete
 
void reset () noexcept
 Reset tree (does not free nodes)
 
void swap (GenTdRbTreeRk &other) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swaps in constant time the nodes and the comparison criteria of this and other.
 
virtual ~GenTdRbTreeRk ()=default
 
size_t size () const noexcept
 Get number of nodes O(1)
 
bool is_empty () const noexcept
 Check if empty.
 
Compare & get_compare () noexcept
 Get comparator.
 
const Compare & get_compare () const noexcept
 
Node * insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert a node.
 
Node * insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert a node allowing duplicates.
 
Node * search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Search or insert.
 
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
 Get root pointer.
 
Node * getRoot () const noexcept
 
Node * select (size_t i) const
 Select i-th node in order.
 
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 of a key (even if not in tree).
 
Node * remove_pos (size_t i)
 Remove node at position i.
 
void split_pos (size_t pos, GenTdRbTreeRk &t1, GenTdRbTreeRk &t2) noexcept
 Split tree by position.
 
bool verify () const
 Verify tree properties. It throws what the comparator throws.
 

Static Public Attributes

static constexpr size_t PATH_STACK_CAPACITY = 128
 

Private Member Functions

bool less (const Key &a, const Key &b) const noexcept(nothrow_compare_v< Compare, Key >)
 Returns true if a < b according to comparator; it throws what the comparator throws.
 
bool equals (const Key &a, const Key &b) const noexcept(nothrow_compare_v< Compare, Key >)
 Returns true if a == b (neither a < b nor b < a); it throws what the comparator throws.
 
void restoreRedCondition (Node *p, Node *&fp, Node *ffp, Node *fffp) noexcept
 Restore red-black property after color flip.
 
Node * searchFlipColorsAndInsert (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 Search for insertion point, flipping colors proactively.
 
Node * searchFlipColorsAndInsertDup (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 Search for insertion point allowing duplicates.
 
void colorRootAsRed () noexcept
 Color root red if safe.
 
Node * searchAndColorRed (const Key &key, Node *&fp, Node **stack, size_t &stack_len) noexcept(nothrow_compare_v< Compare, Key >)
 Search for key while coloring nodes red for deletion.
 
void init () noexcept
 Initialize header nodes.
 
void split_pos_inorder (Node *p, size_t pos, GenTdRbTreeRk &t1, GenTdRbTreeRk &t2, size_t &count) noexcept
 

Static Private Member Functions

static Node * rotate_to_right_rk (Node *p, Node *pp) noexcept
 Rotate to right with counter update.
 
static Node * rotate_to_left_rk (Node *p, Node *pp) noexcept
 Rotate to left with counter update.
 
static void flipColors (Node *p) noexcept
 Flip colors with counter preservation.
 
static size_t updateCountRec (Node *p) noexcept
 Recursively update counts in subtree - O(n)
 
static void updateCountsFromStack (Node **stack, size_t len) noexcept
 Update counts for nodes in stack (bottom-up) - O(log n) After rotations, nodes may have moved but their counts can be recalculated from their current children.
 
static Node * gotoLeftAndColorRed (Node *fp, Node *&ffp) noexcept
 Descend to left child for deletion, ensuring red.
 
static Node * gotoRightAndColorRed (Node *fp, Node *&ffp) noexcept
 Descend to right child for deletion, ensuring red.
 
static void findSuccAndSwap (Node *p, Node *&fp) noexcept
 Find successor and swap for deletion.
 
static void findPredAndSwap (Node *p, Node *&fp) noexcept
 Find predecessor and swap for deletion.
 
static void removeAndRendLeafRed (Node *p, Node *fp) noexcept
 Remove node, making it a red leaf.
 

Private Attributes

Node headNode
 Sentinel header node (parent of root)
 
Node headParent
 Sentinel grandparent node.
 
Node * head
 Pointer to header.
 
Node * fHead
 Pointer to header's parent.
 
Node *& root
 Reference to root (right child of head)
 
Compare cmp
 Comparison functor.
 

Detailed Description

template<template< class > class NodeType, typename Key, class Compare = Aleph::less<Key>>
requires StrictWeakOrder<Compare, Key>
class Aleph::GenTdRbTreeRk< NodeType, Key, Compare >

Top-down red-black tree with rank support (select/position).

This class extends the top-down red-black tree algorithm with subtree counters in each node, enabling O(log n) operations for:

  • select(i): Get the i-th smallest element
  • position(key): Get the rank/position of a key
  • find_position(key): Find position even if key doesn't exist
  • split_pos(pos, t1, t2): Split tree by position
Complexity:
  • search, select, position: O(log n)
  • insert: O(log n) - uses stack for count updates
  • remove: O(n) - swaps make incremental updates unreliable

For O(log n) remove with rank, use Rb_Tree_Rk (bottom-up) which tracks the full path during descent.

Advantages over bottom-up:
  • Single-pass descent for insert (rotations done on the way down)
  • O(1) size() operation
  • O(log n) indexed access (select)
  • O(log n) position queries
Template Parameters
NodeTypeNode template (typically RbNodeRk or RbNodeRkVtl).
KeyThe type of keys stored in the tree.
CompareComparison functor for ordering keys.
See also
Gen_Rb_Tree_Rk Bottom-up red-black tree with rank support.
GenTdRbTree Top-down red-black tree without rank support.

Definition at line 99 of file tpl_tdRbTreeRk.H.

Member Typedef Documentation

◆ compare_type

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::compare_type = Compare

Definition at line 104 of file tpl_tdRbTreeRk.H.

◆ key_type

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::key_type = Key

Definition at line 103 of file tpl_tdRbTreeRk.H.

◆ Node

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::Node = NodeType<Key>

Definition at line 102 of file tpl_tdRbTreeRk.H.

Constructor & Destructor Documentation

◆ GenTdRbTreeRk() [1/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk ( )
inlinenoexcept

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

Exceptions
whatthe default construction of the key of a header node or of the comparison criteria throws; nothing when both are noexcept.

Definition at line 714 of file tpl_tdRbTreeRk.H.

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

◆ GenTdRbTreeRk() [2/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk ( const Compare &  __cmp)
inlineexplicitnoexcept

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.

Definition at line 728 of file tpl_tdRbTreeRk.H.

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

◆ GenTdRbTreeRk() [3/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk ( GenTdRbTreeRk< NodeType, Key, Compare > &&  other)
inlinenoexcept

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

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

Parameters
[in,out]otherthe 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 other 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 other keeps its nodes. Nothing when they are noexcept.

Definition at line 753 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.

◆ GenTdRbTreeRk() [4/4]

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

◆ ~GenTdRbTreeRk()

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

Member Function Documentation

◆ colorRootAsRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::colorRootAsRed ( )
inlineprivatenoexcept

◆ equals()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
bool Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals ( const Key &  a,
const Key &  b 
) const
inlineprivatenoexcept

◆ find_position()

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

Find position of a key (even if not in tree).

Parameters
keyKey to search for.
Returns
Pair of (position, node pointer).
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 998 of file tpl_tdRbTreeRk.H.

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

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

◆ findPredAndSwap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findPredAndSwap ( Node *  p,
Node *&  fp 
)
inlinestaticprivatenoexcept

◆ findSuccAndSwap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findSuccAndSwap ( Node *  p,
Node *&  fp 
)
inlinestaticprivatenoexcept

◆ flipColors()

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

◆ get_compare() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
const Compare & Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::get_compare ( ) const
inlinenoexcept

◆ get_compare() [2/2]

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

Get comparator.

Definition at line 819 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.

◆ getRoot() [1/2]

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

◆ getRoot() [2/2]

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

Get root pointer.

Definition at line 958 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.

◆ gotoLeftAndColorRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed ( Node *  fp,
Node *&  ffp 
)
inlinestaticprivatenoexcept

◆ gotoRightAndColorRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed ( Node *  fp,
Node *&  ffp 
)
inlinestaticprivatenoexcept

◆ init()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init ( )
inlineprivatenoexcept

◆ insert()

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

Insert a node.

Parameters
pNode to insert (must be red with null children).
Returns
Pointer to inserted node, or nullptr if duplicate.
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 832 of file tpl_tdRbTreeRk.H.

References COLOR, Aleph::COUNT(), RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert().

Referenced by TEST(), TEST(), TEST(), and TEST_F().

◆ insert_dup()

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

Insert a node allowing duplicates.

Parameters
pNode to insert (must be red with null children).
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 855 of file tpl_tdRbTreeRk.H.

References COLOR, Aleph::COUNT(), RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().

◆ is_empty()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
bool Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::is_empty ( ) const
inlinenoexcept

Check if empty.

Definition at line 816 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.

◆ less()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
bool Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::less ( const Key &  a,
const Key &  b 
) const
inlineprivatenoexcept

Returns true if a < b according to comparator; it throws what the comparator throws.

Definition at line 119 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
GenTdRbTreeRk & Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::operator= ( GenTdRbTreeRk< NodeType, Key, Compare > &&  other)
inlinenoexcept

Takes the nodes and the comparison criteria of other, which is left empty.

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

Definition at line 773 of file tpl_tdRbTreeRk.H.

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

◆ position()

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

Find position of a key.

Parameters
keyKey to search for.
Returns
Pair of (position, node pointer). 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 981 of file tpl_tdRbTreeRk.H.

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

◆ remove()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenTdRbTreeRk< NodeType, 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 recolorings and rotations done on the way down leave a valid red-black tree with right counters, and the node is unlinked after the last comparison, so the tree keeps its keys.
Note
Count update uses stack collected during search - O(log n) amortized, but may need full recalc after complex swaps.
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 929 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), KEY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::PATH_STACK_CAPACITY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::removeAndRendLeafRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountRec().

Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove_pos(), and TEST().

◆ remove_pos()

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

Remove node at position i.

Parameters
iZero-based position.
Returns
Pointer to removed node.

Definition at line 1011 of file tpl_tdRbTreeRk.H.

References KEY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::select().

◆ removeAndRendLeafRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::removeAndRendLeafRed ( Node *  p,
Node *  fp 
)
inlinestaticprivatenoexcept

◆ reset()

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

Reset tree (does not free nodes)

Definition at line 790 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.

◆ restoreRedCondition()

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

◆ rotate_to_left_rk()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_left_rk ( Node *  p,
Node *  pp 
)
inlinestaticprivatenoexcept

◆ rotate_to_right_rk()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_right_rk ( Node *  p,
Node *  pp 
)
inlinestaticprivatenoexcept

◆ search()

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

Search for a key.

Parameters
keyKey to search for.
Returns
Pointer to node, 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 905 of file tpl_tdRbTreeRk.H.

References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), KEY, LLINK, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.

Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search_or_insert(), TEST(), and TEST_F().

◆ search_or_insert()

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

Search or insert.

Parameters
pNode to search or insert (must be red with null children).
Returns
Inserted node or existing node with same key.
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 878 of file tpl_tdRbTreeRk.H.

References COLOR, Aleph::COUNT(), KEY, RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert().

◆ searchAndColorRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed ( const Key &  key,
Node *&  fp,
Node **  stack,
size_t &  stack_len 
)
inlineprivatenoexcept

◆ searchFlipColorsAndInsert()

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

◆ searchFlipColorsAndInsertDup()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup ( Node *  q)
inlineprivatenoexcept

◆ select()

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

Select i-th node in order.

Parameters
iZero-based position.
Returns
Pointer to i-th node.
Exceptions
out_of_rangeif i >= size().

Definition at line 968 of file tpl_tdRbTreeRk.H.

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

Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove_pos(), TEST(), and TEST().

◆ size()

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

◆ split_pos()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos ( size_t  pos,
GenTdRbTreeRk< NodeType, Key, Compare > &  t1,
GenTdRbTreeRk< NodeType, Key, Compare > &  t2 
)
inlinenoexcept

Split tree by position.

Parameters
posSplit position.
t1Receives nodes [0, pos).
t2Receives nodes [pos, size).
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
It stays noexcept because it inserts the nodes one by one in t1 and t2, which compares: a comparison that threw in the middle would leave nodes out of every tree.

Definition at line 1029 of file tpl_tdRbTreeRk.H.

References Aleph::count(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::size(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos_inorder().

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ split_pos_inorder()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos_inorder ( Node *  p,
size_t  pos,
GenTdRbTreeRk< NodeType, Key, Compare > &  t1,
GenTdRbTreeRk< NodeType, Key, Compare > &  t2,
size_t &  count 
)
inlineprivatenoexcept

◆ swap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::swap ( GenTdRbTreeRk< NodeType, Key, Compare > &  other)
inlinenoexcept

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

Parameters
[in,out]otherthe 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 802 of file tpl_tdRbTreeRk.H.

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

◆ updateCountRec()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static size_t Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountRec ( Node *  p)
inlinestaticprivatenoexcept

◆ updateCountsFromStack()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountsFromStack ( Node **  stack,
size_t  len 
)
inlinestaticprivatenoexcept

Update counts for nodes in stack (bottom-up) - O(log n) After rotations, nodes may have moved but their counts can be recalculated from their current children.

Definition at line 395 of file tpl_tdRbTreeRk.H.

References Aleph::COUNT(), LLINK, and RLINK.

Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().

◆ verify()

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

Member Data Documentation

◆ cmp

◆ fHead

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node* Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::fHead
private

◆ head

◆ headNode

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::headNode
private

Sentinel header node (parent of root)

Definition at line 110 of file tpl_tdRbTreeRk.H.

◆ headParent

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::headParent
private

Sentinel grandparent node.

Definition at line 111 of file tpl_tdRbTreeRk.H.

◆ PATH_STACK_CAPACITY

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
constexpr size_t Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::PATH_STACK_CAPACITY = 128
staticconstexpr

◆ root

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node*& Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root
private

Reference to root (right child of head)

Definition at line 114 of file tpl_tdRbTreeRk.H.

Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::colorRootAsRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::find_position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::getRoot(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::getRoot(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert_dup(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::is_empty(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::operator=(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::reset(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search_or_insert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::select(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::size(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::swap(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::verify().


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