49#ifndef __ADS_MeasuredSearchTree
50 #define __ADS_MeasuredSearchTree
81template< std::totally_ordered K ,
class V >
109 : f_root( other.f_root ) , f_size( other.f_size ) {
110 other.f_root =
nullptr;
118 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
137 void insert(
const K & k ,
const V & v );
166 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
172 [[nodiscard]] std::optional< Measures >
measures(
const K & k )
const;
176 [[nodiscard]] std::optional< std::pair< K , V > >
182 [[nodiscard]]
const K *
findKey(
const K & k )
const;
192 [[nodiscard]] std::vector< std::pair< K , V > >
getLE(
const K & x )
const;
205 Node * left =
nullptr;
206 Node * right =
nullptr;
207 Node * parent =
nullptr;
208 std::size_t
size = 1;
209 std::size_t depth = 0;
220 static auto root(
const auto & o ) {
return( o.f_root ); }
222 static auto left(
const auto * n ) {
return( n->left ); }
224 static auto right(
const auto * n ) {
return( n->right ); }
226 static auto read(
const auto * n ) {
260 Node * findLast(
const K & k )
const;
263 static long fresh(
const Node * u ) {
264 return( 1 + std::max( u->left ? u->left->height : -1L ,
265 u->right ? u->right->height : -1L ) );
269 [[nodiscard]]
bool valid(
void )
const;
272 Node * f_root =
nullptr;
273 std::size_t f_size = 0;
285#include "ADS/tree/impl/MeasuredSearchTree.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...
MeasuredSearchTree(MeasuredSearchTree &&other) noexcept
the nodes of other, which is left empty
Definition MeasuredSearchTree.h:108
const_iterator iterator
the constant iterator
Definition MeasuredSearchTree.h:243
const_iterator end(void) const
the iterator past the largest key
Definition MeasuredSearchTree.h:250
const_iterator cbegin(void) const
as begin()
Definition MeasuredSearchTree.h:254
std::optional< Measures > measures(const K &k) const
the measures of the node of , or nothing, read in it
V Value
the type of the values
Definition MeasuredSearchTree.h:88
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
void insert(const K &k, const V &v)
associates to , in time
const_iterator cend(void) const
as end()
Definition MeasuredSearchTree.h:256
std::size_t size(void) const
the number of keys
Definition MeasuredSearchTree.h:166
~MeasuredSearchTree()
frees the nodes
std::size_t size_type
the type of the sizes
Definition MeasuredSearchTree.h:237
K Key
the type of the keys
Definition MeasuredSearchTree.h:87
MeasuredSearchTree & operator=(const MeasuredSearchTree &)=delete
no copy, since the nodes are linked by pointers
MeasuredSearchTree(const MeasuredSearchTree &)=delete
no copy, since the nodes are linked by pointers
PathIterator< MeasuredSearchTree, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition MeasuredSearchTree.h:242
const_iterator begin(void) const
the iterator on the smallest key
Definition MeasuredSearchTree.h:246
PairRef< const K &, const V & > reference
references, by value
Definition MeasuredSearchTree.h:239
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...
MeasuredSearchTree(void)=default
the empty tree
long height(void) const
the height, if empty, read at the root in
V mapped_type
the type of the values
Definition MeasuredSearchTree.h:236
bool contains(const K &k) const
true if is there
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...
void remove(const K &k)
removes , if it is there, in time
std::vector< std::pair< K, V > > getLE(const K &x) const
the pairs whose keys are not larger than , in increasing order, by lessOrEqual(), in time for pairs...
reference const_reference
the same
Definition MeasuredSearchTree.h:240
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),...
std::ptrdiff_t difference_type
the type of the distances
Definition MeasuredSearchTree.h:238
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition MeasuredSearchTree.h:232
std::optional< V > lookup(const K &k) const
the value of , or nothing, in time
K key_type
the type of the keys
Definition MeasuredSearchTree.h:234
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 measures of a node
Definition MeasuredSearchTree.h:92
std::size_t depth
the edges from the root to it
Definition MeasuredSearchTree.h:94
long height
the height of its subtree, 0 for a leaf
Definition MeasuredSearchTree.h:95
std::size_t size
the nodes of its subtree
Definition MeasuredSearchTree.h:93
the shape of the tree, for PathIterator
Definition MeasuredSearchTree.h:218
static auto right(const auto *n)
the right child of the node n
Definition MeasuredSearchTree.h:224
static auto left(const auto *n)
the left child of the node n
Definition MeasuredSearchTree.h:222
static auto read(const auto *n)
the pair of the node n
Definition MeasuredSearchTree.h:226
static auto root(const auto &o)
the root of the tree o
Definition MeasuredSearchTree.h:220