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

Red-black tree with rank support (select/position operations). More...

#include <tpl_rbRk.H>

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

Classes

class  Iterator
 Iterator on nodes of the tree. More...
 

Public Types

typedef NodeType< Key > Node
 
typedef Key key_type
 

Public Member Functions

Compare & key_comp () noexcept
 
Compare & get_compare () noexcept
 
 Gen_Rb_Tree_Rk () 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.
 
 Gen_Rb_Tree_Rk (Compare cmp_arg) 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_arg.
 
void swap (Gen_Rb_Tree_Rk &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swaps in constant time the nodes and the comparison criteria of this and tree.
 
 Gen_Rb_Tree_Rk (Gen_Rb_Tree_Rk &&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.
 
Gen_Rb_Tree_Rk & operator= (Gen_Rb_Tree_Rk &&tree) noexcept(std::is_nothrow_move_assignable_v< Compare >)
 Takes the nodes and the comparison criteria of tree, which is left empty.
 
virtual ~Gen_Rb_Tree_Rk ()=default
 
Node * search (const Key &key)
 
Node *& getRoot () noexcept
 
bool is_empty () const noexcept
 
size_t size () const noexcept
 
Node * insert (Node *p)
 
Node * search_or_insert (Node *p)
 
Node * insert_dup (Node *p)
 
bool verify () const
 
Node * remove (const Key &key)
 
Node * select (const size_t i) const
 Return the i-th node in order sense.
 
std::pair< long, Node * > position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
 Compute the inorder position of a key.
 
std::pair< long, Node * > find_position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
 Find the inorder position of a key in the tree.
 
void join_exclusive (Gen_Rb_Tree_Rk &t) noexcept
 Join this tree exclusively with another tree.
 
Node * split_key (const Key &key, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
 Split tree by key.
 
void split_key_dup (const Key &key, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
 Split tree by key including duplicates.
 
void split_pos (size_t pos, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
 Split tree by inorder position.
 

Private Types

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

Private Member Functions

Node * search_and_stack_rb (const Key &key, signed char &cmp_result, Path &path)
 Search for key and stack ancestors (optimistic duplicate detection).
 
Node * search_dup_and_stack_rb (const Key &key, signed char &cmp_result, Path &path)
 
Node * rotate_to_right_rk (Node *p, Node *pp) noexcept
 
Node * rotate_to_left_rk (Node *p, Node *pp) noexcept
 
void fix_red_condition (Node *p, Path &path)
 
void find_succ_and_swap (Node *p, Node *&pp, Path &path)
 
void fix_black_condition (Node *p, Path &path)
 
void update_counters_after_insertion (const Path &path) noexcept
 
void update_counters_after_deletion (const Path &path) noexcept
 
Node * split_key_rec_rb (Node *p, const Key &key, Node *&t1, Node *&t2) noexcept(nothrow_compare_v< Compare, Key >)
 
void split_key_dup_rec_rb (Node *p, const Key &key, Node *&t1, Node *&t2) noexcept(nothrow_compare_v< Compare, Key >)
 
void split_pos_rec_rb (Node *p, size_t pos, Node *&t1, Node *&t2) noexcept
 

Static Private Member Functions

static size_t black_height (Node *p) noexcept
 
static Node * rotate_right_simple (Node *p) noexcept
 
static Node * rotate_left_simple (Node *p) noexcept
 
static void fix_red_violation (Node *&subtree_root) noexcept
 
static Node * extract_min_rb (Node *&p) noexcept
 
static Node * extract_max_rb (Node *&p) noexcept
 
static Node * join_with_pivot_rb (Node *t1, size_t bh1, Node *pivot, Node *t2, size_t bh2) noexcept
 
static Node * join_right_rb (Node *t1, size_t bh1, Node *pivot, Node *t2, size_t bh2) noexcept
 
static Node * join_left_rb (Node *t1, size_t bh1, Node *pivot, Node *t2, size_t bh2) noexcept
 
static Node * join_exclusive_rec_rb (Node *t1, size_t bh1, Node *t2, size_t bh2) noexcept
 

Private Attributes

Node head_node
 
Node * head
 
Node *& root
 
Compare cmp
 

Static Private Attributes

static constexpr signed char CmpLess = -1
 
static constexpr signed char CmpEqual = 0
 
static constexpr signed char CmpGreater = 1
 

Detailed Description

template<template< typename > class NodeType, typename Key, class Compare>
requires StrictWeakOrder<Compare, Key>
class Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >

Red-black tree with rank support (select/position operations).

This class extends the standard red-black tree with subtree size counts, enabling efficient O(log n) rank-based operations:

  • select(i): Get the i-th smallest element (0-indexed)
  • position(key): Get the rank/position of a key
  • find_position(key): Get insertion position even if key doesn't exist
  • split_pos(pos, t1, t2): Split tree at a position
  • remove_pos(i): Remove element at position i
How it works:
Each node stores a count field representing the number of nodes in its subtree (including itself). Rotations update these counts to maintain the invariant. This adds O(1) overhead per rotation but enables O(log n) ranked operations.
Complexity:
  • All basic operations (search, insert, remove): O(log n)
  • Rank operations (select, position): O(log n)
  • Space: O(n) + O(log n) for stack during operations
Example:
for (int i = 0; i < 100; ++i)
// Get 50th smallest element
auto node = tree.select(49); // 0-indexed, returns node with key 49
// Get position of key 42
auto [pos, found] = tree.position(42); // pos = 42, found points to node
Node * select(const size_t i) const
Return the i-th node in order sense.
Definition tpl_rbRk.H:715
std::pair< long, Node * > position(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Compute the inorder position of a key.
Definition tpl_rbRk.H:730
Node * insert(Node *p)
Definition tpl_rbRk.H:589
NodeType< Key > Node
Definition tpl_rbRk.H:113
Red-Black binary search tree with nodes without virtual destructor and with subtree counters for sele...
Definition tpl_rbRk.H:1653
Template Parameters
NodeTypeNode template (RbNodeRk or RbNodeRkVtl).
KeyThe type of keys stored in the tree.
CompareComparison functor for ordering keys.
See also
Gen_Rb_Tree Basic red-black tree without rank support.
GenTdRbTreeRk Top-down red-black with rank.

Definition at line 109 of file tpl_rbRk.H.

Member Typedef Documentation

◆ key_type

template<template< typename > class NodeType, typename Key , class Compare >
typedef Key Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::key_type

Definition at line 469 of file tpl_rbRk.H.

◆ Node

template<template< typename > class NodeType, typename Key , class Compare >
typedef NodeType<Key> Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Node

Definition at line 113 of file tpl_rbRk.H.

◆ Path

template<template< typename > class NodeType, typename Key , class Compare >
using Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Path = InlineStack<Node *, Node::MaxHeight + 1>
private

Definition at line 129 of file tpl_rbRk.H.

Constructor & Destructor Documentation

◆ Gen_Rb_Tree_Rk() [1/3]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Gen_Rb_Tree_Rk ( )
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 488 of file tpl_rbRk.H.

◆ Gen_Rb_Tree_Rk() [2/3]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Gen_Rb_Tree_Rk ( Compare  cmp_arg)
inlinenoexcept

Builds an empty tree with the comparison criteria cmp_arg.

Parameters
[in]cmp_argthe comparison criteria, which the tree copies.
Exceptions
whatthe default construction of the key of a header node or the copy of cmp_arg 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 505 of file tpl_rbRk.H.

◆ Gen_Rb_Tree_Rk() [3/3]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Gen_Rb_Tree_Rk ( Gen_Rb_Tree_Rk< NodeType, 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 the header node is built by default when that cannot throw; else it is that of the 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 the header node throws, with a key whose move may throw too. Then tree keeps its nodes. Nothing when they are noexcept.

Definition at line 544 of file tpl_rbRk.H.

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

◆ ~Gen_Rb_Tree_Rk()

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

Member Function Documentation

◆ black_height()

template<template< typename > class NodeType, typename Key , class Compare >
static size_t Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::black_height ( Node *  p)
inlinestaticprivatenoexcept

◆ extract_max_rb()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::extract_max_rb ( Node *&  p)
inlinestaticprivatenoexcept

◆ extract_min_rb()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::extract_min_rb ( Node *&  p)
inlinestaticprivatenoexcept

◆ find_position()

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

Find the inorder position of a key in the tree.

Parameters
[in]keyto be searched
Returns
a pair with the position and the 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 750 of file tpl_rbRk.H.

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

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

◆ find_succ_and_swap()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::find_succ_and_swap ( Node *  p,
Node *&  pp,
Path &  path 
)
inlineprivate

◆ fix_black_condition()

◆ fix_red_condition()

◆ fix_red_violation()

template<template< typename > class NodeType, typename Key , class Compare >
static void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::fix_red_violation ( Node *&  subtree_root)
inlinestaticprivatenoexcept

◆ get_compare()

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

◆ getRoot()

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

Definition at line 583 of file tpl_rbRk.H.

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

Referenced by TEST().

◆ insert()

◆ insert_dup()

◆ is_empty()

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

◆ join_exclusive()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_exclusive ( Gen_Rb_Tree_Rk< NodeType, Key, Compare > &  t)
inlinenoexcept

Join this tree exclusively with another tree.

All keys in this tree must be less than all keys in t. After the operation, t becomes empty and this tree contains all nodes.

Parameters
[in,out]ttree to join with (will be empty after)
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
O(m log(n+m)) time complexity where m is size of t
It stays noexcept because it inserts the nodes of t one by one: a comparison that threw in the middle would leave nodes out of both trees.

Definition at line 1420 of file tpl_rbRk.H.

References Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::insert(), Aleph::InlineStack< T, N >::is_empty(), LLINK, Aleph::InlineStack< T, N >::pop(), Aleph::InlineStack< T, N >::push(), RLINK, and Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::root.

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

◆ join_exclusive_rec_rb()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_exclusive_rec_rb ( Node *  t1,
size_t  bh1,
Node *  t2,
size_t  bh2 
)
inlinestaticprivatenoexcept

◆ join_left_rb()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_left_rb ( Node *  t1,
size_t  bh1,
Node *  pivot,
Node *  t2,
size_t  bh2 
)
inlinestaticprivatenoexcept

◆ join_right_rb()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_right_rb ( Node *  t1,
size_t  bh1,
Node *  pivot,
Node *  t2,
size_t  bh2 
)
inlinestaticprivatenoexcept

◆ join_with_pivot_rb()

◆ key_comp()

template<template< typename > class NodeType, typename Key , class Compare >
Compare & Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::key_comp ( )
inlinenoexcept

◆ operator=()

template<template< typename > class NodeType, typename Key , class Compare >
Gen_Rb_Tree_Rk & Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::operator= ( Gen_Rb_Tree_Rk< NodeType, Key, Compare > &&  tree)
inlinenoexcept

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

Parameters
[in,out]treethe 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 562 of file tpl_rbRk.H.

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

◆ position()

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

Compute the inorder position of a key.

Parameters
[in]keyto be searched
Returns
a pair with the inorder position and the node pointer. If key is not found, position is -1.
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 730 of file tpl_rbRk.H.

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

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

◆ remove()

◆ rotate_left_simple()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::rotate_left_simple ( Node *  p)
inlinestaticprivatenoexcept

◆ rotate_right_simple()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::rotate_right_simple ( Node *  p)
inlinestaticprivatenoexcept

◆ rotate_to_left_rk()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::rotate_to_left_rk ( Node *  p,
Node *  pp 
)
inlineprivatenoexcept

◆ rotate_to_right_rk()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::rotate_to_right_rk ( Node *  p,
Node *  pp 
)
inlineprivatenoexcept

◆ search()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search ( const Key &  key)
inline

◆ search_and_stack_rb()

◆ search_dup_and_stack_rb()

◆ search_or_insert()

◆ select()

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

Return the i-th node in order sense.

Parameters
[in]iinorder position of node to be selected
Returns
a pointer to the i-th node inorder sense
Exceptions
out_of_rangeif i is greater or equal than the number of nodes of tree

Definition at line 715 of file tpl_rbRk.H.

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

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

◆ size()

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

◆ split_key()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key ( const Key &  key,
Gen_Rb_Tree_Rk< NodeType, Key, Compare > &  t1,
Gen_Rb_Tree_Rk< NodeType, Key, Compare > &  t2 
)
inlinenoexcept

Split tree by key.

After the operation:

  • t1 contains all keys < key
  • t2 contains all keys > key
  • This tree becomes empty
Parameters
[in]keythe splitting key
[out]t1tree to receive keys < key
[out]t2tree to receive keys > key
Returns
pointer to node containing key, or nullptr if not found
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
O(n) time complexity (simple iterative implementation)
It stays noexcept because it moves the nodes one by one: a comparison that threw in the middle would leave nodes out of every tree.

Definition at line 1473 of file tpl_rbRk.H.

References Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::InlineStack< T, N >::is_empty(), KEY, LLINK, Aleph::InlineStack< T, N >::pop(), Aleph::InlineStack< T, N >::push(), RLINK, and Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::root.

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

◆ split_key_dup()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key_dup ( const Key &  key,
Gen_Rb_Tree_Rk< NodeType, Key, Compare > &  t1,
Gen_Rb_Tree_Rk< NodeType, Key, Compare > &  t2 
)
inlinenoexcept

Split tree by key including duplicates.

After the operation:

  • t1 contains all keys <= key
  • t2 contains all keys > key
  • This tree becomes empty
Parameters
[in]keythe splitting key
[out]t1tree to receive keys <= key
[out]t2tree to receive keys > key
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
O(n) time complexity (simple iterative implementation)
It stays noexcept because it moves the nodes one by one: a comparison that threw in the middle would leave nodes out of every tree.

Definition at line 1526 of file tpl_rbRk.H.

References Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::InlineStack< T, N >::is_empty(), KEY, LLINK, Aleph::InlineStack< T, N >::pop(), Aleph::InlineStack< T, N >::push(), RLINK, and Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::root.

Referenced by TEST().

◆ split_key_dup_rec_rb()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key_dup_rec_rb ( Node *  p,
const Key &  key,
Node *&  t1,
Node *&  t2 
)
inlineprivatenoexcept

◆ split_key_rec_rb()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key_rec_rb ( Node *  p,
const Key &  key,
Node *&  t1,
Node *&  t2 
)
inlineprivatenoexcept

◆ split_pos()

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

Split tree by inorder position.

After the operation:

  • t1 contains nodes at positions [0, pos)
  • t2 contains nodes at positions [pos, size)
  • This tree becomes empty
Parameters
[in]posthe splitting position (0-based)
[out]t1tree to receive positions [0, pos)
[out]t2tree to receive positions [pos, size)
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
O(n) time complexity (simple iterative implementation)
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 1573 of file tpl_rbRk.H.

References Aleph::count(), Aleph::InlineStack< T, N >::is_empty(), LLINK, Aleph::InlineStack< T, N >::pop(), Aleph::InlineStack< T, N >::push(), RLINK, Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::root, and Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::size().

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

◆ split_pos_rec_rb()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_pos_rec_rb ( Node *  p,
size_t  pos,
Node *&  t1,
Node *&  t2 
)
inlineprivatenoexcept

◆ swap()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::swap ( Gen_Rb_Tree_Rk< NodeType, 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 519 of file tpl_rbRk.H.

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

◆ update_counters_after_deletion()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::update_counters_after_deletion ( const Path &  path)
inlineprivatenoexcept

Definition at line 460 of file tpl_rbRk.H.

References Aleph::COUNT().

Referenced by Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::remove().

◆ update_counters_after_insertion()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::update_counters_after_insertion ( const Path &  path)
inlineprivatenoexcept

◆ verify()

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

Member Data Documentation

◆ cmp

◆ CmpEqual

◆ CmpGreater

template<template< typename > class NodeType, typename Key , class Compare >
constexpr signed char Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::CmpGreater = 1
staticconstexprprivate

◆ CmpLess

◆ head

template<template< typename > class NodeType, typename Key , class Compare >
Node* Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::head
private

◆ head_node

template<template< typename > class NodeType, typename Key , class Compare >
Node Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::head_node
private

Definition at line 117 of file tpl_rbRk.H.

◆ root

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

Definition at line 119 of file tpl_rbRk.H.

Referenced by Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::Gen_Rb_Tree_Rk(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::find_position(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::fix_black_condition(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::fix_red_condition(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::is_empty(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::operator=(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::position(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_and_stack_rb(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_dup_and_stack_rb(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::select(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::size(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_pos(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::swap(), and Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::verify().


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