74#ifndef __ADS_BPlusTree
75 #define __ADS_BPlusTree
108template< std::totally_ordered K ,
class V >
153 [[nodiscard]] std::optional< V >
lookup(
const K & x )
const;
192 void insert(
const K & x ,
const V & v );
232 [[nodiscard]]
const K *
findKey(
const K & k )
const;
241 [[nodiscard]] std::vector< std::pair< K , V > >
findRange(
const K & x ,
245 [[nodiscard]] std::size_t
size(
void )
const;
248 [[nodiscard]]
int order(
void )
const;
271 [[nodiscard]] std::vector< std::pair< K , V > >
range(
const K & A ,
277 [[nodiscard]] std::vector< std::vector< std::vector< K > > >
290 explicit Node(
bool l ) : is_leaf( l ) { }
293 std::vector< Node * > p;
295 Node * parent =
nullptr;
296 Node * prev =
nullptr;
297 Node * next =
nullptr;
327 : f_t( t ) , f_f( f ) , f_i( i ) { }
331 return(
reference( f_f->k[ f_i ] , f_f->v[ f_i ] ) );
336 if( ++f_i < f_f->k.size() )
340 while( f_f && f_f->k.empty() )
347 if( f_f && ( f_i > 0 ) ) {
351 f_f = f_f ? f_f->prev : f_t->lastLeaf();
352 while( f_f->k.empty() )
354 f_i = f_f->k.size() - 1;
374 return( ( f_f == o.f_f ) && ( f_i == o.f_i ) );
379 const Node * f_f =
nullptr;
398 const Node * f = firstLeaf();
399 while( f && f->k.empty() )
416 [[nodiscard]]
const Node * firstLeaf(
void )
const {
417 const Node * x = f_root;
418 while( x && ! x->is_leaf )
423 [[nodiscard]]
const Node * lastLeaf(
void )
const {
424 const Node * x = f_root;
425 while( x && ! x->is_leaf )
431 Node * leaf(
const K & x )
const;
436 void up( Node * f , Node * g ,
const K & s );
442 [[nodiscard]]
bool shaped(
void )
const;
446 [[nodiscard]]
bool shaped(
const Node * u ,
const K * lo ,
const K * hi ,
448 int & depth ,
const Node *& last )
const;
451 static void destroy( Node * u );
456 Node * fix( Node * u );
460 std::size_t f_size = 0;
472#include "ADS/tree/impl/BPlusTree.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 iterator on the pairs by increasing keys, a leaf and a place in it
Definition BPlusTree.h:308
std::pair< K, V > value_type
the pairs, by value
Definition BPlusTree.h:314
std::bidirectional_iterator_tag iterator_concept
the category of the iterator for the concepts of C++20, bidirectional
Definition BPlusTree.h:317
std::input_iterator_tag iterator_category
input for the older algorithms, since *it is a value
Definition BPlusTree.h:319
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 BPlusTree.h:312
reference operator*(void) const
the pair of the place
Definition BPlusTree.h:330
bool operator==(const const_iterator &o) const
equal on the same place of the same leaf
Definition BPlusTree.h:373
const_iterator & operator--(void)
to the previous pair, from the end to the last pair
Definition BPlusTree.h:346
const_iterator operator++(int)
to the next pair, returning the iterator before the step
Definition BPlusTree.h:359
std::ptrdiff_t difference_type
the type of the distances
Definition BPlusTree.h:315
const_iterator operator--(int)
to the previous pair, returning the iterator before the step
Definition BPlusTree.h:366
const_iterator(const BPlusTree *t, const Node *f, std::size_t i)
on the place of the leaf of the tree , the end if is nil
Definition BPlusTree.h:326
const_iterator & operator++(void)
to the next pair, along the list of the leaves
Definition BPlusTree.h:335
const_iterator(void)=default
an iterator on no tree
std::ptrdiff_t difference_type
the type of the distances
Definition BPlusTree.h:390
reference const_reference
the same
Definition BPlusTree.h:393
const_iterator cend(void) const
as end()
Definition BPlusTree.h:412
std::pair< K, V > value_type
the pairs ( key , value ) by value, which own their copies
Definition BPlusTree.h:384
std::vector< std::pair< K, V > > findRange(const K &x, const K &y) const
the pairs with keys in , the findRange( x , y ) of exercise 14.8 of Morin's book: range() with the fi...
std::vector< std::pair< K, V > > range(const K &A, const K &B) const
the pairs with keys in , read along the list of the leaves, for pairs
std::optional< V > lookup(const K &x) const
the value of the key , or nothing
~BPlusTree()
frees the nodes
void insert(const K &x, const V &v)
associates the value to the key
BPlusTree & operator=(const BPlusTree &)=delete
no copy, since the nodes are linked by pointers
const K * lowerBound(const K &x) const
the smallest key , nil if none (the find( x ) of exercise 14.8 of Morin's book), in nodes
std::size_t size(void) const
the number of keys
BPlusTree(int m)
an empty B+-tree of order , the root a leaf
const_iterator begin(void) const
the iterator on the smallest key
Definition BPlusTree.h:397
const_iterator cbegin(void) const
as begin()
Definition BPlusTree.h:409
V mapped_type
the type of the values
Definition BPlusTree.h:388
const K * findKey(const K &k) const
the address of the key , nil if absent, in nodes: the find( x ) of a USet of Morin [see DictionarySe...
K key_type
the type of the keys
Definition BPlusTree.h:386
K Key
the type of the keys
Definition BPlusTree.h:114
int order(void) const
the order
const_iterator iterator
the constant iterator
Definition BPlusTree.h:394
const K * lowerBoundKey(const K &k) const
the address of the smallest key not smaller than , nil if none, in nodes: the find( x ) of an SSet o...
V Value
the type of the values
Definition BPlusTree.h:115
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 ...
typename const_iterator::reference reference
references, by value
Definition BPlusTree.h:392
const_iterator end(void) const
the iterator past the largest key
Definition BPlusTree.h:404
void remove(const K &x)
removes the key , if it is there, in time
bool contains(const K &x) const
true if the key is there
void check(void) const
checks the shape [see shaped()] whatever the level of the contracts; it throws contract_violation if ...
BPlusTree(const BPlusTree &)=delete
no copy, since the nodes are linked by pointers
std::size_t size_type
the type of the sizes
Definition BPlusTree.h:389
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