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

Top-down red-black binary search tree implementation. More...

#include <tpl_tdRbTree.H>

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

Classes

struct  Iterator
 Iterator over tree nodes in sorted order. More...
 

Public Types

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

Public Member Functions

 GenTdRbTree () 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.
 
 GenTdRbTree (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.
 
 GenTdRbTree (GenTdRbTree &&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.
 
GenTdRbTree & operator= (GenTdRbTree &&other) noexcept(std::is_nothrow_move_assignable_v< Compare >)
 Takes the nodes and the comparison criteria of other, which is left empty.
 
 GenTdRbTree (const GenTdRbTree &)=delete
 Deleted copy constructor (use explicit copy if needed)
 
GenTdRbTree & operator= (const GenTdRbTree &)=delete
 Deleted copy assignment.
 
void reset () noexcept
 Reset tree to empty state (does not free nodes)
 
void swap (GenTdRbTree &other) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swaps in constant time the nodes and the comparison criteria of this and other.
 
virtual ~GenTdRbTree ()=default
 
size_t size () const noexcept
 Get number of nodes in tree (O(1))
 
bool is_empty () const noexcept
 Check if tree is empty.
 
Compare & get_compare () noexcept
 Get reference to comparator.
 
const Compare & get_compare () const noexcept
 
Node * insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert a node into the tree.
 
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 for key or insert if not found.
 
Node * search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
 Search for a key in the tree.
 
Node * remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
 Remove and return node with given key.
 
Node *& getRoot () noexcept
 Get reference to root pointer.
 
Node * getRoot () const noexcept
 Get const root pointer

 
bool verifyRedBlack () const noexcept
 Verify that tree satisfies all red-black properties.
 
bool verify () const
 Verify the red-black properties and the order of the keys.
 

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 creates two consecutive reds.
 
Node * searchFlipColorsAndInsert (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 Search for insertion point, flipping colors proactively to maintain balance.
 
Node * searchFlipColorsAndInsertDup (Node *q) noexcept(nothrow_compare_v< Compare, Key >)
 Search for insertion point allowing duplicates.
 
void colorRootAsRed () noexcept
 Color root red if safe (both children black)
 
Node * searchAndColorRed (const Key &key, Node *&fp) noexcept(nothrow_compare_v< Compare, Key >)
 Search for key while coloring nodes red for deletion.
 
void init () noexcept
 Initialize header nodes.
 

Static Private Member Functions

static Node * getSibling (Node *p, Node *fp) noexcept
 Get sibling of node p whose parent is fp.
 
static void flipColors (Node *p) noexcept
 Flip colors: black parent with two red children becomes red with two black children.
 
static Node * gotoLeftAndColorRed (Node *fp, Node *&ffp) noexcept
 Descend to left child, ensuring current node is red for deletion.
 
static Node * gotoRightAndColorRed (Node *fp, Node *&ffp) noexcept
 Descend to right child, ensuring current node is red for deletion.
 
static void findSuccAndSwap (Node *p, Node *&fp) noexcept
 Find successor and swap with node p for deletion.
 
static void findPredAndSwap (Node *p, Node *&fp) noexcept
 Find predecessor and swap with node p for deletion.
 
static void removeAndRendLeafRed (Node *p, Node *fp) noexcept
 Remove node p and ensure it becomes 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.
 
size_t num_nodes
 Number of nodes in tree.
 

Detailed Description

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

Top-down red-black binary search tree implementation.

This class implements the top-down (single-pass) red-black tree algorithm as described by Guibas and Sedgewick. Unlike the bottom-up approach that requires backtracking after insertion/deletion, this algorithm performs all necessary rotations and color changes while descending the tree.

Advantages over bottom-up:
  • No stack needed for ancestor path (saves O(log n) space)
  • Better cache locality (single pass through tree)
  • Potentially faster due to reduced memory traffic
Disadvantages:
  • More complex code
  • May perform more color flips than strictly necessary
Complexity:
  • Search: O(log n) worst case
  • Insert: O(log n) worst case, at most 2 rotations
  • Delete: O(log n) worst case, at most 3 rotations
  • Size: O(1)
Template Parameters
NodeTypeNode template (typically RbNode or RbNodeVtl).
KeyThe type of keys stored in the tree.
CompareComparison functor for ordering keys (default: Aleph::less<Key>).
See also
Gen_Rb_Tree Bottom-up red-black tree implementation.
Avl_Tree Alternative balanced tree with stricter balance.

Definition at line 98 of file tpl_tdRbTree.H.

Member Typedef Documentation

◆ compare_type

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

Definition at line 103 of file tpl_tdRbTree.H.

◆ key_type

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

Definition at line 102 of file tpl_tdRbTree.H.

◆ Node

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

Definition at line 101 of file tpl_tdRbTree.H.

Constructor & Destructor Documentation

◆ GenTdRbTree() [1/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTree< NodeType, Key, Compare >::GenTdRbTree ( )
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 643 of file tpl_tdRbTree.H.

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

◆ GenTdRbTree() [2/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTree< NodeType, Key, Compare >::GenTdRbTree ( 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 657 of file tpl_tdRbTree.H.

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

◆ GenTdRbTree() [3/4]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenTdRbTree< NodeType, Key, Compare >::GenTdRbTree ( GenTdRbTree< 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 682 of file tpl_tdRbTree.H.

References BLACK, COLOR, Aleph::GenTdRbTree< NodeType, Key, Compare >::fHead, Aleph::GenTdRbTree< NodeType, Key, Compare >::head, RLINK, and Aleph::GenTdRbTree< NodeType, Key, Compare >::root.

◆ GenTdRbTree() [4/4]

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

Deleted copy constructor (use explicit copy if needed)

◆ ~GenTdRbTree()

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

Member Function Documentation

◆ colorRootAsRed()

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

Color root red if safe (both children black)

Definition at line 562 of file tpl_tdRbTree.H.

References Aleph::and, BLACK, COLOR, LLINK, RED, RLINK, and Aleph::GenTdRbTree< NodeType, Key, Compare >::root.

Referenced by Aleph::GenTdRbTree< NodeType, Key, Compare >::searchAndColorRed().

◆ equals()

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

◆ findPredAndSwap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenTdRbTree< 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::GenTdRbTree< 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::GenTdRbTree< NodeType, Key, Compare >::flipColors ( Node *  p)
inlinestaticprivatenoexcept

Flip colors: black parent with two red children becomes red with two black children.

Definition at line 184 of file tpl_tdRbTree.H.

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

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

◆ get_compare() [1/2]

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

Definition at line 759 of file tpl_tdRbTree.H.

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

◆ get_compare() [2/2]

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

Get reference to comparator.

Definition at line 758 of file tpl_tdRbTree.H.

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

◆ getRoot() [1/2]

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

Get const root pointer

Definition at line 899 of file tpl_tdRbTree.H.

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

◆ getRoot() [2/2]

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

Get reference to root pointer.

Definition at line 896 of file tpl_tdRbTree.H.

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

Referenced by TEST().

◆ getSibling()

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

Get sibling of node p whose parent is fp.

Definition at line 131 of file tpl_tdRbTree.H.

References LLINK, and RLINK.

◆ gotoLeftAndColorRed()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenTdRbTree< 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::GenTdRbTree< NodeType, Key, Compare >::gotoRightAndColorRed ( Node *  fp,
Node *&  ffp 
)
inlinestaticprivatenoexcept

◆ init()

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

◆ insert()

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

Insert a node into the tree.

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

Definition at line 772 of file tpl_tdRbTree.H.

References Aleph::and, COLOR, LLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes, RED, RLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::root, and Aleph::GenTdRbTree< NodeType, Key, Compare >::searchFlipColorsAndInsert().

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

◆ insert_dup()

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

Insert a node, allowing duplicates.

Parameters
pNode to insert.
Returns
Pointer to inserted node (always succeeds).
Exceptions
anythingthat the comparison throws; then the tree is a valid red-black tree with its keys and size, 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 798 of file tpl_tdRbTree.H.

References Aleph::and, COLOR, LLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes, RED, RLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::root, and Aleph::GenTdRbTree< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().

Referenced by TEST(), and TEST().

◆ is_empty()

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

Check if tree is empty.

Definition at line 755 of file tpl_tdRbTree.H.

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

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

◆ less()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
bool Aleph::GenTdRbTree< 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 116 of file tpl_tdRbTree.H.

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

◆ operator=() [1/2]

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

Deleted copy assignment.

◆ operator=() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
GenTdRbTree & Aleph::GenTdRbTree< NodeType, Key, Compare >::operator= ( GenTdRbTree< 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 705 of file tpl_tdRbTree.H.

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

◆ remove()

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

Remove and return 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, and the node is unlinked after the last comparison, so the tree keeps its keys and size.
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_tdRbTree.H.

References Aleph::GenTdRbTree< NodeType, Key, Compare >::equals(), KEY, Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes, Aleph::GenTdRbTree< NodeType, Key, Compare >::removeAndRendLeafRed(), Aleph::GenTdRbTree< NodeType, Key, Compare >::root, and Aleph::GenTdRbTree< NodeType, Key, Compare >::searchAndColorRed().

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

◆ removeAndRendLeafRed()

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

◆ reset()

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

Reset tree to empty state (does not free nodes)

Definition at line 727 of file tpl_tdRbTree.H.

References Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes, and Aleph::GenTdRbTree< NodeType, Key, Compare >::root.

◆ restoreRedCondition()

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

◆ search()

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

Search for a key in the tree.

Parameters
keyKey to search for.
Returns
Pointer to node containing 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 855 of file tpl_tdRbTree.H.

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

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

◆ search_or_insert()

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

Search for key or insert if not found.

Parameters
pNode to search or insert.
Returns
Pointer to p if inserted, or pointer to existing node with same key.
Exceptions
anythingthat the comparison throws; then the tree is a valid red-black tree with its keys and size, 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 824 of file tpl_tdRbTree.H.

References Aleph::and, COLOR, KEY, LLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes, RED, RLINK, Aleph::GenTdRbTree< NodeType, Key, Compare >::root, Aleph::GenTdRbTree< NodeType, Key, Compare >::search(), and Aleph::GenTdRbTree< NodeType, Key, Compare >::searchFlipColorsAndInsert().

Referenced by TEST(), and TEST().

◆ searchAndColorRed()

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

◆ searchFlipColorsAndInsert()

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

◆ searchFlipColorsAndInsertDup()

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

◆ size()

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

Get number of nodes in tree (O(1))

Definition at line 752 of file tpl_tdRbTree.H.

References Aleph::GenTdRbTree< NodeType, Key, Compare >::num_nodes.

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

◆ swap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenTdRbTree< NodeType, Key, Compare >::swap ( GenTdRbTree< 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 740 of file tpl_tdRbTree.H.

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

◆ verify()

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

Verify the red-black properties and the order of the keys.

Returns
true if the tree is a valid red-black binary search tree.
Exceptions
whatthe comparator throws.

Definition at line 920 of file tpl_tdRbTree.H.

References Aleph::and, Aleph::check_bst(), Aleph::GenTdRbTree< NodeType, Key, Compare >::cmp, Aleph::GenTdRbTree< NodeType, Key, Compare >::root, and Aleph::GenTdRbTree< NodeType, Key, Compare >::verifyRedBlack().

Referenced by TEST().

◆ verifyRedBlack()

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

Verify that tree satisfies all red-black properties.

Checks every node: valid colors, no red node with a red child, and the same number of black nodes on every path down to Node::NullPtr. It does not look at the keys; verify() does.

Returns
true if tree is valid, false otherwise.

Definition at line 910 of file tpl_tdRbTree.H.

References is_red_black_tree(), and Aleph::GenTdRbTree< NodeType, Key, Compare >::root.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and Aleph::GenTdRbTree< NodeType, Key, Compare >::verify().

Member Data Documentation

◆ cmp

◆ fHead

◆ head

◆ headNode

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

Sentinel header node (parent of root)

Definition at line 106 of file tpl_tdRbTree.H.

◆ headParent

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

Sentinel grandparent node.

Definition at line 107 of file tpl_tdRbTree.H.

◆ num_nodes

◆ root


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