95template< std::totally_ordered K ,
class V ,
class Policy = NoObservers >
116 using Subject =
typename Policy::template bind< modifications , BTree >;
121 template<
class... O >
122 explicit BTree(
int t = 3 , O &... o );
143 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
185 void insert(
const K & k ,
const V & v );
253 [[nodiscard]] std::optional< std::pair< K , V > >
259 [[nodiscard]]
const K *
findKey(
const K & k )
const;
267 [[nodiscard]] std::size_t
size(
void )
const;
270 [[nodiscard]]
bool empty(
void )
const;
278 [[nodiscard]] std::vector< std::vector< std::vector< K > > >
308 std::vector< std::unique_ptr< Node > > c;
310 [[nodiscard]]
bool leaf(
void )
const {
return( c.empty() ); }
325 requires( Subject::dynamic )
327 return( f_sub.attach( o ) );
333 requires( Subject::dynamic )
367 if( x && ! x->k.empty() )
373 const auto & [ x , i ] = f_path.back();
374 return(
reference( x->k[ i ] , x->v[ i ] ) );
395 auto & [ x , i ] = f_path.back();
396 if( ! x->c.empty() ) {
398 leftmost( x->c[ i ].get() );
401 if( ++i < x->k.size() )
404 while( ! f_path.empty() &&
405 ( f_path.back().second >= f_path.back().first->k.size() ) )
419 return( f_path.empty() ? o.f_path.empty()
420 : ( ! o.f_path.empty() &&
421 ( f_path.back() == o.f_path.back() ) ) );
426 void leftmost(
const Node * x ) {
427 for( ; ! x->c.empty() ; x = x->c[ 0 ].get() )
428 f_path.emplace_back( x , 0 );
429 f_path.emplace_back( x , 0 );
433 std::vector< std::pair< const Node * , std::size_t > > f_path;
467 void insertPlain(
const K & key ,
const V & val );
470 [[nodiscard]] std::pair< Node * , std::size_t > slot(
const K & key )
const;
473 void insertTold(
const K & key ,
const V & val );
477 bool removeTold(
const K & key );
480 ADS_COLD_PATH void insertCold(
const K & key ,
const V & val ) {
481 insertTold( key , val );
484 return( removeTold( key ) );
488 static std::size_t place(
const Node * x ,
const K & key );
491 void split( Node * x , std::size_t i );
495 static void merge( Node * x , std::size_t j );
499 std::size_t fill( Node * x , std::size_t i );
502 bool remove( Node * x ,
const K & key );
507 static void visit(
const Node * x , F & f );
510 bool valid(
const Node * x ,
const K * lo ,
const K * hi ,
int d ,
511 int & leafDepth ,
bool root )
const;
515 [[nodiscard]] std::pair< const Node * , std::size_t >
516 lowerBoundPlace(
const K & key )
const;
519 std::unique_ptr< Node > f_root;
520 std::size_t f_size = 0;
533#include "ADS/tree/impl/BTree.tpp"
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 typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
the iterator on the pairs by increasing keys, with the path from the root
Definition BTree.h:348
const_iterator(const Node *x)
on the first key below , or at the end if is nil or empty
Definition BTree.h:366
std::pair< K, V > value_type
the pairs, by value
Definition BTree.h:354
PairRef< const K &, typename std::vector< V >::const_reference, K, V > reference
a pair of constant references, the key and its value (that of the vector of the values,...
Definition BTree.h:352
const_iterator operator++(int)
to the next key, returning the iterator before the step
Definition BTree.h:411
const_iterator & operator++(void)
to the next key, amortized and at most
Definition BTree.h:394
std::forward_iterator_tag iterator_concept
the category of the iterator for the concepts of C++20, forward
Definition BTree.h:357
reference operator*(void) const
the pair of the key at the end of the path
Definition BTree.h:372
std::ptrdiff_t difference_type
the type of the distances
Definition BTree.h:355
bool operator==(const const_iterator &o) const
equal on the same place of the same node, or both at the end
Definition BTree.h:418
const_iterator(void)=default
the end
std::input_iterator_tag iterator_category
input for the older algorithms, since *it is a value
Definition BTree.h:359
typename Policy::template bind< modifications, BTree > Subject
the subject
Definition BTree.h:116
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition BTree.h:437
std::vector< std::vector< std::vector< K > > > levels(void) const
the keys of the nodes, level by level from the root, each level from left to right: the shape of the ...
reference const_reference
the same
Definition BTree.h:446
V Value
the type of the values
Definition BTree.h:102
K Key
the type of the keys
Definition BTree.h:101
const_iterator cbegin(void) const
as begin()
Definition BTree.h:460
void forEach(F &&f) const
f( k , v ) on the pairs by increasing keys
const_iterator iterator
the constant iterator
Definition BTree.h:447
K key_type
the type of the keys
Definition BTree.h:439
int attach(O &o)
attaches the observer and gives its number
Definition BTree.h:324
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 begin(void) const
the iterator on the smallest key
Definition BTree.h:450
const Subject & subject(void) const
the subject
Definition BTree.h:319
std::size_t size(void) const
the number of keys
std::optional< V > lookup(const K &k) const
the value of the key , or nothing
std::ptrdiff_t difference_type
the type of the distances
Definition BTree.h:443
const_iterator end(void) const
the iterator past the largest key
Definition BTree.h:455
void remove(const K &k)
removes the key , if there, in one pass down from the root
bool empty(void) const
true if there is no key
int height(void) const
the height, 0 for a single leaf, -1 if empty
typename const_iterator::reference reference
references, by value
Definition BTree.h:445
void clear(void)
removes all the keys, in time
const_iterator cend(void) const
as end()
Definition BTree.h:463
bool contains(const K &k) const
whether the key is there, lookup() above
BTree(int t=3, O &... o)
the empty B-tree of minimum degree , the static observers o...
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...
mod::Inserted< K, K, V > Inserted
an insertion of a key, the key its handle
Definition BTree.h:105
void insert(const K &k, const V &v)
gives the key the value , in one pass down from the root
mod::Erased< K, K, V > Erased
an erasure of a key, told before the removal
Definition BTree.h:107
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 DictionarySe...
void detach(int id)
detaches the observer number
Definition BTree.h:332
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition BTree.h:317
mod::Assigned< K, V > Assigned
a change of the value of a key
Definition BTree.h:109
mod::list< Inserted, Erased, Assigned, mod::Cleared, mod::Rebuilt > modifications
the events: a key inserted or erased with its value, its value changed, the tree emptied or rebuilt
Definition BTree.h:113
std::size_t size_type
the type of the sizes
Definition BTree.h:442
V mapped_type
the type of the values
Definition BTree.h:441
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
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
the item of handle , key and value inserted
Definition Modification.h:536
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482