83template< std::totally_ordered K ,
class V >
87template< std::totally_ordered K ,
class V >
92template< std::totally_ordered K ,
class V >
106 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
138 void insert(
const K & k ,
const V & v );
172 [[nodiscard]] std::optional< std::pair< K , V > >
178 [[nodiscard]]
const K *
findKey(
const K & k )
const;
186 [[nodiscard]] std::size_t
size(
void )
const;
189 [[nodiscard]]
bool empty(
void )
const;
201 [[nodiscard]] std::pair< std::size_t , std::size_t >
204 std::pair< std::size_t , std::size_t >( f_rebalances , f_rotations ) );
216 std::unique_ptr< Node > left ,
230 static auto root(
const auto & o ) {
return( o.f_root.get() ); }
232 static auto left(
const auto * n ) {
return( n->left.get() ); }
234 static auto right(
const auto * n ) {
return( n->right.get() ); }
236 static auto read(
const auto * n ) {
269 using Ptr = std::unique_ptr< Node >;
271 static int h(
const Ptr & t ) {
return( t ? t->h : -1 ); }
272 static std::size_t sz(
const Ptr & t ) {
return( t ? t->s : 0 ); }
273 static void update( Ptr & t );
274 static void rotateRight( Ptr & t );
275 static void rotateLeft( Ptr & t );
276 void balance( Ptr & t );
277 bool insert( Ptr & t ,
const K & k ,
const V & v );
278 bool remove( Ptr & t ,
const K & k );
280 static void visit(
const Ptr & t , F & f );
284 static bool valid(
const Ptr & t ,
const K * lo ,
const K * hi );
288 std::size_t f_size = 0;
289 std::size_t f_rebalances = 0;
290 std::size_t f_rotations = 0;
302#include "ADS/tree/impl/AVLTree.tpp"
The classic problems on binary trees and on binary search trees, written once for any representation ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The balanced binary search trees whose only balancing operation is join, beyond the book,...
a DICTIONARY on an AVL tree, with the operations based on join [see Joinable]
Definition AVLTree.h:95
const_iterator cbegin(void) const
as begin()
Definition AVLTree.h:264
bool empty(void) const
true if there is no key
V mapped_type
the type of the values
Definition AVLTree.h:246
const_iterator end(void) const
the iterator past the largest key
Definition AVLTree.h:260
std::ptrdiff_t difference_type
the type of the distances
Definition AVLTree.h:248
V Value
the type of the values
Definition AVLTree.h:102
const_iterator begin(void) const
the iterator on the smallest key
Definition AVLTree.h:256
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
K Key
the type of the keys
Definition AVLTree.h:101
PathIterator< AVLTree, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition AVLTree.h:252
std::optional< V > lookup(const K &k) const
the value of , or nothing, by the descent of a binary search tree, in time
PairRef< const K &, const V & > reference
references, by value
Definition AVLTree.h:249
std::size_t size(void) const
the number of keys
const_iterator iterator
the constant iterator
Definition AVLTree.h:253
std::optional< std::pair< K, V > > lowerBound(const K &k) const
the smallest key not smaller than and its value, or nothing (the find( x ) of an SSet of Morin),...
int height(void) const
the height of the tree, -1 if it is empty
bool contains(const K &k) const
true if is there
const K * findKey(const K &k) const
the address of the key , nil if absent, in time: the find( x ) of a USet of Morin [see DictionarySet...
const_iterator cend(void) const
as end()
Definition AVLTree.h:266
std::pair< std::size_t, std::size_t > rebalancings(void) const
the rebalancings of insert() and remove() so far, i.e., the nodes found unbalanced on their paths and...
Definition AVLTree.h:202
const K * lowerBoundKey(const K &k) const
the address of the smallest key not smaller than , nil if none, in time: the find( x ) of an SSet of...
K key_type
the type of the keys
Definition AVLTree.h:244
void insert(const K &k, const V &v)
associates to , in time
reference const_reference
the same
Definition AVLTree.h:250
void remove(const K &k)
removes , if it is there, in time
std::size_t size_type
the type of the sizes
Definition AVLTree.h:247
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition AVLTree.h:242
the operations based on join of the tree T of keys Key and values Value, whose nodes A adapts [see Jo...
Definition JoinAlgorithms.h:860
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order,...
Definition Iterators.h:867
std::conditional_t< detail::plainPair< A, B, VA, VB >, std::pair< A, B >, detail::PairProxy< A, B, VA, VB > > PairRef
the pair that an iterator reads by value, in general two references into the container,...
Definition Iterators.h:648
the adaptor of the nodes of an AVLTree [see JoinAdaptor]
Definition AVLTree.h:88
the shape of the tree, for PathIterator
Definition AVLTree.h:228
static auto read(const auto *n)
the pair of the node n
Definition AVLTree.h:236
static auto left(const auto *n)
the left child of the node n
Definition AVLTree.h:232
static auto root(const auto &o)
the root of the tree o
Definition AVLTree.h:230
static auto right(const auto *n)
the right child of the node n
Definition AVLTree.h:234