83#ifndef __ADS_PartialRebuildingTree
84 #define __ADS_PartialRebuildingTree
103#include <type_traits>
127template< std::totally_ordered K ,
class V , RebuildPolicy P >
152 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
177 void insert(
const K & k ,
const V & v );
190 [[nodiscard]] std::size_t
size(
void )
const {
191 return( f_root ? f_root->s : 0 );
199 [[nodiscard]] std::optional< std::pair< K , V > >
205 [[nodiscard]]
const K *
findKey(
const K & k )
const;
217 [[nodiscard]] std::size_t
rebuilds(
void )
const {
return( f_rebuilds ); }
220 [[nodiscard]] std::size_t
rebuiltNodes(
void )
const {
return( f_work ); }
237 : std::conditional_t< P == RebuildPolicy::COUNTDOWN , Timer , NoTimer >
241 Node * left =
nullptr;
242 Node * right =
nullptr;
245 Node(
const K & k ,
const V & v ) : key( k ) , value( v ) { }
255 static auto root(
const auto & o ) {
return( o.f_root ); }
257 static auto left(
const auto * n ) {
return( n->left ); }
259 static auto right(
const auto * n ) {
return( n->right ); }
261 static auto read(
const auto * n ) {
294 static std::size_t sz(
const Node * u ) {
return( u ? u->s : 0 ); }
298 void rebalance(
void );
301 void rebuild( std::size_t i );
304 [[nodiscard]]
bool valid(
void )
const;
307 Node * f_root =
nullptr;
308 std::vector< Node * > f_path;
309 std::vector< Node * > f_buf;
311 std::size_t f_rebuilds = 0;
312 std::size_t f_work = 0;
317template< std::totally_ordered K ,
class V >
322template< std::totally_ordered K ,
class V >
327template< std::totally_ordered K ,
class V >
338#include "ADS/tree/impl/PartialRebuildingTree.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 engineered random numbers, beyond the book: generators of 64 bits that cost a few instructions an...
Hashing with random tables, beyond the book:
The scapegoat tree of Galperin and Rivest, the general balanced tree of Andersson (section 8....
a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P
Definition PartialRebuildingTree.h:129
void remove(const K &k)
removes , if it is there, in amortized time (for DynamiteTree, expected, the height),...
V Value
the type of the values
Definition PartialRebuildingTree.h:134
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition PartialRebuildingTree.h:267
PathIterator< PartialRebuildingTree, Shape > const_iterator
the constant iterator by increasing key, along the path from the root
Definition PartialRebuildingTree.h:277
PartialRebuildingTree(const PartialRebuildingTree &)=delete
no copy, since the nodes are linked by pointers
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...
PartialRebuildingTree(std::uint64_t seed=1)
the empty tree, its random choices (if any) drawn from the seed
Definition PartialRebuildingTree.h:137
PartialRebuildingTree(PartialRebuildingTree &&other) noexcept
the nodes of other, which is left empty
PartialRebuildingTree & operator=(const PartialRebuildingTree &)=delete
no copy, since the nodes are linked by pointers
std::ptrdiff_t difference_type
the type of the distances
Definition PartialRebuildingTree.h:273
K Key
the type of the keys
Definition PartialRebuildingTree.h:133
bool contains(const K &k) const
true if is there
V mapped_type
the type of the values
Definition PartialRebuildingTree.h:271
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...
PairRef< const K &, const V & > reference
references, by value
Definition PartialRebuildingTree.h:274
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)
const_iterator iterator
the constant iterator
Definition PartialRebuildingTree.h:278
std::size_t size(void) const
the number of keys
Definition PartialRebuildingTree.h:190
std::size_t rebuilds(void) const
the number of rebuilds so far
Definition PartialRebuildingTree.h:217
reference const_reference
the same
Definition PartialRebuildingTree.h:275
K key_type
the type of the keys
Definition PartialRebuildingTree.h:269
const_iterator end(void) const
the iterator past the largest key
Definition PartialRebuildingTree.h:285
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
std::optional< V > lookup(const K &k) const
the value of , or nothing, in time
const_iterator begin(void) const
the iterator on the smallest key
Definition PartialRebuildingTree.h:281
~PartialRebuildingTree()
frees the nodes
std::size_t size_type
the type of the sizes
Definition PartialRebuildingTree.h:272
long height(void) const
the height, if empty, in
const_iterator cbegin(void) const
as begin()
Definition PartialRebuildingTree.h:289
void insert(const K &k, const V &v)
associates to , in amortized time (for DynamiteTree, expected after insertions only,...
std::size_t rebuiltNodes(void) const
the nodes of all the rebuilds so far, the work they took
Definition PartialRebuildingTree.h:220
const_iterator cend(void) const
as end()
Definition PartialRebuildingTree.h:291
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
PartialRebuildingTree< K, V, RebuildPolicy::WEIGHT > WeightRebuildTree
the tree of exercise 8.8 of Morin, balanced by weight by rebuilds
Definition PartialRebuildingTree.h:318
RebuildPolicy
the rules that select the subtree to rebuild
Definition PartialRebuildingTree.h:115
PartialRebuildingTree< K, V, RebuildPolicy::COUNTDOWN > CountdownTree
the CountdownTree of exercise 8.9 of Morin
Definition PartialRebuildingTree.h:323
PartialRebuildingTree< K, V, RebuildPolicy::DYNAMITE > DynamiteTree
the DynamiteTree of exercise 8.10 of Morin
Definition PartialRebuildingTree.h:328
@ DYNAMITE
an explosion with probability
Definition PartialRebuildingTree.h:118
@ COUNTDOWN
a timer set to that runs out
Definition PartialRebuildingTree.h:117
@ WEIGHT
Definition PartialRebuildingTree.h:116
the shape of the tree, for PathIterator
Definition PartialRebuildingTree.h:253
static auto left(const auto *n)
the left child of the node n
Definition PartialRebuildingTree.h:257
static auto root(const auto &o)
the root of the tree o
Definition PartialRebuildingTree.h:255
static auto read(const auto *n)
the pair of the node n
Definition PartialRebuildingTree.h:261
static auto right(const auto *n)
the right child of the node n
Definition PartialRebuildingTree.h:259