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

AVL balanced binary search tree with rank (order statistics). More...

#include <tpl_avlRk.H>

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

Classes

class  Iterator
 Iterator over the nodes. More...
 

Public Types

using Node = NodeType< Key >
 
using key_type = Key
 

Public Member Functions

constexpr Compare & key_comp () noexcept
 The key type.
 
constexpr Compare & get_compare () noexcept
 See key_comp().
 
 Gen_Avl_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_Avl_Tree_Rk (Compare cmf_fct) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >)
 Builds an empty tree with the comparison criteria cmf_fct.
 
 Gen_Avl_Tree_Rk (const Gen_Avl_Tree_Rk &)=delete
 Not copyable: the tree does not own its nodes, and a copy would hold the same ones.
 
Gen_Avl_Tree_Rk & operator= (const Gen_Avl_Tree_Rk &)=delete
 Not copyable, for the same reason as the copy constructor.
 
 Gen_Avl_Tree_Rk (Gen_Avl_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.
 
void swap (Gen_Avl_Tree_Rk &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swap in constant time all the items of this with the items of tree.
 
virtual ~Gen_Avl_Tree_Rk () noexcept=default
 
constexpr Node *& getRoot () noexcept
 Return a modifiable reference to tree's root.
 
constexpr Node * getRoot () const noexcept
 Return a pointer to the tree's root.
 
size_t size () const noexcept
 Return the number of nodes in the tree.
 
constexpr bool is_empty () const noexcept
 Return true if tree is empty.
 
Node * search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
 Search a node containing key.
 
Node * insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert the node pointed by p in the tree.
 
Node * search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Search or insert a key.
 
Node * insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >)
 Insert the node p without testing for key duplicity.
 
Node * remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
 Remove from tree the node containing 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.
 
bool verify () const
 Return true if the tree is a valid AVL tree with correct counters and its keys are in order.
 
void join_exclusive (Gen_Avl_Tree_Rk &t) noexcept
 Join this tree exclusively with another tree.
 
Node * split_key (const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
 Split tree by key.
 
void split_key_dup (const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
 Split tree by key including duplicates.
 
void split_pos (const size_t pos, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
 Split tree by inorder position.
 

Private Types

enum  Rotation_Type { ROTATE_LEFT , ROTATE_RIGHT , DOUBLE_ROTATE_LEFT , DOUBLE_ROTATE_RIGHT }
 
using Path = InlineStack< Node *, Node::MaxHeight+1 >
 

Private Member Functions

Node * search_and_stack_avl (const Key &key, signed char &cmp_result, Path &path) noexcept(nothrow_compare_v< Compare, Key >)
 
Node * search_dup_and_stack_avl (const Key &key, signed char &cmp_result, Path &path) noexcept(nothrow_compare_v< Compare, Key >)
 
void restore_avl_after_insertion (Node *p, Path &path) noexcept
 
Node * swapWithSuccessor (Node *p, Node *&pp, Path &path) noexcept
 
void restore_avl_after_deletion (bool left_deficit, Path &path) noexcept
 
void update_counters_after_insertion (const Path &path) noexcept
 
void update_counters_after_deletion (const Path &path) noexcept
 
Node * split_key_rec (Node *p, const Key &key, Node *&t1, Node *&t2) noexcept(nothrow_compare_v< Compare, Key >)
 
void split_key_dup_rec (Node *p, const Key &key, Node *&t1, Node *&t2) noexcept(nothrow_compare_v< Compare, Key >)
 
void split_pos_rec (Node *p, size_t pos, Node *&t1, Node *&t2) noexcept
 

Static Private Member Functions

static bool at_head (const Path &path) noexcept
 true when path holds only the head node.
 
static Node * rotateLeft (Node *p) noexcept
 
static Node * rotateRight (Node *p) noexcept
 
static Node * doubleRotateLeft (Node *p) noexcept
 
static Node * doubleRotateRight (Node *p) noexcept
 
static Rotation_Type rotation_type (Node *p) noexcept
 
static Node * restore_avl (Node *p, Node *pp) noexcept
 
static size_t avl_height (Node *p) noexcept
 
static Node * extract_min (Node *&p) noexcept
 
static Node * extract_max (Node *&p) noexcept
 
static Node * join_exclusive_rec (Node *t1, size_t h1, Node *t2, size_t h2) noexcept
 
static Node * join_with_pivot (Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
 
static Node * join_right (Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
 
static Node * join_left (Node *t1, const size_t h1, Node *pivot, Node *t2, const size_t h2) noexcept
 

Private Attributes

Node head_node
 The type of node.
 
Node * head_ptr
 
Node *& root
 
Compare cmp
 

Detailed Description

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

AVL balanced binary search tree with rank (order statistics).

An AVL tree is a self-balancing binary search tree where the heights of the two child subtrees of any node differ by at most one. This guarantees O(log n) worst-case time complexity for search, insertion, and deletion operations.

The maximum height of an AVL tree with n nodes is bounded by: \( 1.4404 \lg{(n + 2)} - 0.3277 \)

This extended version maintains a count in each node representing the number of nodes in its subtree, enabling O(log n) operations for selecting by position and finding the position of a key.

Template Parameters
NodeTypeTemplate for the node type (typically AvlNodeRk).
KeyThe type of keys stored in the tree.
CompareComparison functor for ordering keys.
Complexity:
  • Search: O(log n) worst case
  • Insert: O(log n) worst case
  • Delete: O(log n) worst case
  • Select: O(log n) worst case
  • Position: O(log n) worst case
  • Space: O(n)
Example:
auto node = tree.select(0); // Get smallest element
auto [pos, found] = tree.position(42); // Get position of key 42
NodeType< Key > Node
Definition tpl_avlRk.H:111
Node * select(const size_t i) const
Return the i-th node in order sense.
Definition tpl_avlRk.H:823
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_avlRk.H:838
Node * insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert the node pointed by p in the tree.
Definition tpl_avlRk.H:673
Ranked AVL tree with nodes without a virtual destructor.
Definition tpl_avlRk.H:1592
Note
This is a low-level implementation that manages raw nodes. For automatic memory management, use DynSetAvlTreeRk instead.
See also
Avl_Tree_Rk Convenient typedef with default node type.
Avl_Tree_Rk_Vtl Version with virtual destructor nodes.
tpl_avl.H Base AVL tree without rank operations.

Definition at line 108 of file tpl_avlRk.H.

Member Typedef Documentation

◆ key_type

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

Definition at line 513 of file tpl_avlRk.H.

◆ Node

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

Definition at line 111 of file tpl_avlRk.H.

◆ Path

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

Definition at line 123 of file tpl_avlRk.H.

Member Enumeration Documentation

◆ Rotation_Type

template<template< typename > class NodeType, typename Key , class Compare >
enum Aleph::Gen_Avl_Tree_Rk::Rotation_Type
private
Enumerator
ROTATE_LEFT 
ROTATE_RIGHT 
DOUBLE_ROTATE_LEFT 
DOUBLE_ROTATE_RIGHT 

Definition at line 332 of file tpl_avlRk.H.

Constructor & Destructor Documentation

◆ Gen_Avl_Tree_Rk() [1/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::Gen_Avl_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 540 of file tpl_avlRk.H.

◆ Gen_Avl_Tree_Rk() [2/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::Gen_Avl_Tree_Rk ( Compare  cmf_fct)
inlinenoexcept

Builds an empty tree with the comparison criteria cmf_fct.

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

◆ Gen_Avl_Tree_Rk() [3/4]

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

Not copyable: the tree does not own its nodes, and a copy would hold the same ones.

The copy that the compiler wrote did worse: the copy used the header node of the tree that it copied, so that the two were one tree, and std::move() of a tree copied it too. Move the tree, which leaves the other one empty, or copy its nodes (copyRec()).

◆ Gen_Avl_Tree_Rk() [4/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::Gen_Avl_Tree_Rk ( Gen_Avl_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 595 of file tpl_avlRk.H.

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

◆ ~Gen_Avl_Tree_Rk()

template<template< typename > class NodeType, typename Key , class Compare >
virtual Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::~Gen_Avl_Tree_Rk ( )
virtualdefaultnoexcept

Member Function Documentation

◆ at_head()

template<template< typename > class NodeType, typename Key , class Compare >
static bool Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::at_head ( const Path &  path)
inlinestaticprivatenoexcept

◆ avl_height()

◆ doubleRotateLeft()

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

◆ doubleRotateRight()

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

◆ extract_max()

◆ extract_min()

◆ find_position()

template<template< typename > class NodeType, typename Key , class Compare >
std::pair< long, Node * > Aleph::Gen_Avl_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 858 of file tpl_avlRk.H.

References Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::BinTreeXt_Operation< Node, Cmp >::find_position(), r, and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root.

◆ get_compare()

template<template< typename > class NodeType, typename Key , class Compare >
constexpr Compare & Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::get_compare ( )
inlineconstexprnoexcept

◆ getRoot() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
constexpr Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::getRoot ( ) const
inlineconstexprnoexcept

Return a pointer to the tree's root.

Definition at line 630 of file tpl_avlRk.H.

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

◆ getRoot() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
constexpr Node *& Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::getRoot ( )
inlineconstexprnoexcept

Return a modifiable reference to tree's root.

Definition at line 624 of file tpl_avlRk.H.

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

Referenced by TEST().

◆ insert()

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

Insert the node pointed by p in the tree.

Parameters
[in]pthe node to be inserted
Returns
p if KEY(p) is not found in the tree, nullptr otherwise.
Exceptions
anythingthat the comparison throws; the tree changes only after the last comparison, so it is left as it was, without p.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 673 of file tpl_avlRk.H.

References Aleph::CmpEqual, Aleph::CmpGreater, Aleph::CmpLess, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::head_ptr, KEY, LLINK, Aleph::InlineStack< T, N >::push(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_insertion(), RLINK, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_and_stack_avl(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::update_counters_after_insertion().

Referenced by Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_exclusive(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ insert_dup()

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

Insert the node p without testing for key duplicity.

Parameters
[in]pthe node to be inserted
Returns
the pointer p
Exceptions
anythingthat the comparison throws; the tree changes only after the last comparison, so it is left as it was, without p.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 737 of file tpl_avlRk.H.

References Aleph::CmpEqual, Aleph::CmpLess, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::head_ptr, KEY, LLINK, Aleph::InlineStack< T, N >::push(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_insertion(), RLINK, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_dup_and_stack_avl(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::update_counters_after_insertion().

Referenced by TEST(), and TEST().

◆ is_empty()

template<template< typename > class NodeType, typename Key , class Compare >
constexpr bool Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::is_empty ( ) const
inlineconstexprnoexcept

Return true if tree is empty.

Definition at line 642 of file tpl_avlRk.H.

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

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

◆ join_exclusive()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_exclusive ( Gen_Avl_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 1345 of file tpl_avlRk.H.

References Aleph::COUNT(), DIFF, Aleph::Gen_Avl_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_Avl_Tree_Rk< NodeType, Key, Compare >::root.

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

◆ join_exclusive_rec()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_exclusive_rec ( Node *  t1,
size_t  h1,
Node *  t2,
size_t  h2 
)
inlinestaticprivatenoexcept

◆ join_left()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_left ( Node *  t1,
const size_t  h1,
Node *  pivot,
Node *  t2,
const size_t  h2 
)
inlinestaticprivatenoexcept

◆ join_right()

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_right ( Node *  t1,
const size_t  h1,
Node *  pivot,
Node *  t2,
const size_t  h2 
)
inlinestaticprivatenoexcept

◆ join_with_pivot()

◆ key_comp()

template<template< typename > class NodeType, typename Key , class Compare >
constexpr Compare & Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::key_comp ( )
inlineconstexprnoexcept

The key type.

Return a reference to the comparison criteria

Definition at line 516 of file tpl_avlRk.H.

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

Referenced by Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::get_compare().

◆ operator=()

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

Not copyable, for the same reason as the copy constructor.

◆ position()

template<template< typename > class NodeType, typename Key , class Compare >
std::pair< long, Node * > Aleph::Gen_Avl_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 the key is not found, the 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 838 of file tpl_avlRk.H.

References Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::BinTreeXt_Operation< Node, Cmp >::inorder_position(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root.

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

◆ remove()

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

Remove from tree the node containing key.

Parameters
[in]keythe key to remove
Returns
the removed node if the key is found; nullptr otherwise
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 766 of file tpl_avlRk.H.

References Aleph::CmpEqual, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::head_ptr, LLINK, Aleph::InlineStack< T, N >::push(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_deletion(), RLINK, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_and_stack_avl(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::swapWithSuccessor(), Aleph::InlineStack< T, N >::top(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::update_counters_after_deletion().

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

◆ restore_avl()

◆ restore_avl_after_deletion()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_deletion ( bool  left_deficit,
Path &  path 
)
inlineprivatenoexcept

◆ restore_avl_after_insertion()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_insertion ( Node *  p,
Path &  path 
)
inlineprivatenoexcept

◆ rotateLeft()

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

◆ rotateRight()

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

◆ rotation_type()

◆ search()

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

Search a node containing key.

Parameters
[in]keythe key to search
Returns
a pointer to the node containing key if it is found; otherwise nullptr
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 657 of file tpl_avlRk.H.

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

Referenced by TEST().

◆ search_and_stack_avl()

◆ search_dup_and_stack_avl()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_dup_and_stack_avl ( const Key &  key,
signed char &  cmp_result,
Path &  path 
)
inlineprivatenoexcept

◆ search_or_insert()

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

Search or insert a key.

Parameters
[in]pthe node whose key must be searched and eventually inserted
Returns
if p is inserted, this value is returned; otherwise, a pointer to the node containing KEY(p) is returned.
Exceptions
anythingthat the comparison throws; the tree changes only after the last comparison, so it is left as it was, without p.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 706 of file tpl_avlRk.H.

References Aleph::CmpEqual, Aleph::CmpGreater, Aleph::CmpLess, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::head_ptr, KEY, LLINK, Aleph::InlineStack< T, N >::push(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::restore_avl_after_insertion(), RLINK, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root, Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_and_stack_avl(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::update_counters_after_insertion().

Referenced by TEST().

◆ select()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Avl_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 823 of file tpl_avlRk.H.

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

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

◆ size()

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

◆ split_key()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::split_key ( const Key &  key,
Gen_Avl_Tree_Rk< NodeType, Key, Compare > &  t1,
Gen_Avl_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
Complexity: O(n log(n + m)), where n is the number of nodes processed from this tree and m is the initial total size of t1 and t2. Each processed node is inserted into a destination tree.
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 1402 of file tpl_avlRk.H.

References Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::COUNT(), DIFF, Aleph::InlineStack< T, N >::is_empty(), KEY, LLINK, Aleph::InlineStack< T, N >::pop(), Aleph::InlineStack< T, N >::push(), RLINK, and Aleph::Gen_Avl_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_Avl_Tree_Rk< NodeType, Key, Compare >::split_key_dup ( const Key &  key,
Gen_Avl_Tree_Rk< NodeType, Key, Compare > &  t1,
Gen_Avl_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
Complexity: O(n log(n + m)), where n is the number of nodes processed from this tree and m is the initial total size of t1 and t2. Each processed node is inserted into a destination tree.
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 1458 of file tpl_avlRk.H.

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

Referenced by TEST().

◆ split_key_dup_rec()

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

◆ split_key_rec()

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

◆ split_pos()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::split_pos ( const size_t  pos,
Gen_Avl_Tree_Rk< NodeType, Key, Compare > &  t1,
Gen_Avl_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
Complexity: O(n log(n + m)), where n is the number of nodes processed from this tree and m is the initial total size of t1 and t2. Boundary positions transfer the root in O(1).
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 1508 of file tpl_avlRk.H.

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

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

◆ split_pos_rec()

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

◆ swap()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::swap ( Gen_Avl_Tree_Rk< NodeType, Key, Compare > &  tree)
inlinenoexcept

Swap in constant time all the items of this with the items of tree.

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

Definition at line 613 of file tpl_avlRk.H.

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

◆ swapWithSuccessor()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::swapWithSuccessor ( Node *  p,
Node *&  pp,
Path &  path 
)
inlineprivatenoexcept

Definition at line 419 of file tpl_avlRk.H.

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

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

◆ update_counters_after_deletion()

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

Definition at line 505 of file tpl_avlRk.H.

References Aleph::COUNT().

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

◆ update_counters_after_insertion()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Avl_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_Avl_Tree_Rk< NodeType, Key, Compare >::verify ( ) const
inline

Return true if the tree is a valid AVL tree with correct counters and its keys are in order.

It throws what the comparator throws.

Definition at line 870 of file tpl_avlRk.H.

References Aleph::and, Aleph::check_bst(), Aleph::check_rank_tree(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::cmp, Aleph::is_avl_rk(), and Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::root.

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

Member Data Documentation

◆ cmp

◆ head_node

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

The type of node.

Definition at line 114 of file tpl_avlRk.H.

◆ head_ptr

◆ root

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

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