113#ifndef __ADS_BlockBTree
114 #define __ADS_BlockBTree
154template< std::totally_ordered K >
191 [[nodiscard]] std::optional< K >
lowerBound(
const K & x )
const;
253 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
256 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
259 [[nodiscard]]
int order(
void )
const {
return( f_B ); }
268 [[nodiscard]] std::uint64_t
reads(
void )
const {
return( f_bs.reads() ); }
271 [[nodiscard]] std::uint64_t
writes(
void )
const {
return( f_bs.writes() ); }
277 [[nodiscard]] std::size_t
nodes(
void )
const {
return( f_bs.blocks() ); }
281 return( f_splits + f_merges + f_borrows );
285 [[nodiscard]] std::size_t
splits(
void )
const {
return( f_splits ); }
288 [[nodiscard]] std::size_t
merges(
void )
const {
return( f_merges ); }
291 [[nodiscard]] std::size_t
borrows(
void )
const {
return( f_borrows ); }
294 [[nodiscard]] std::size_t
peakNodes(
void )
const {
return( f_peak ); }
297 [[nodiscard]] std::size_t
peakPath(
void )
const {
return( f_peakPath ); }
301 [[nodiscard]] std::vector< std::vector< std::vector< K > > >
307 void assign(
const std::vector< std::vector< std::vector< K > > > & L );
318 std::vector< K > keys;
319 std::vector< std::size_t > kids;
320 bool operator==(
const Node & )
const =
default;
331 explicit Held(
const BlockBTree * tree , Node n = Node() );
334 Held(
const Held & ) =
delete;
335 Held & operator=(
const Held & ) =
delete;
339 [[nodiscard]] std::size_t maxKeys(
void )
const;
342 [[nodiscard]] std::size_t minKeys(
void )
const {
343 return( std::size_t( f_B - 1 ) );
347 [[nodiscard]]
static std::size_t place(
const Node & u ,
const K & x );
373 void deal( Node & p , std::size_t f , std::size_t k , std::size_t c ,
374 const Node & known , D && decide );
411 void fixOverflow( Node & p , std::size_t i ,
const Node & u );
415 void fixUnderflow( Node & p , std::size_t i ,
const Node & u ,
bool root );
419 [[nodiscard]] std::size_t lowKeys(
bool twoLeaves )
const;
423 [[nodiscard]]
bool valid( std::size_t u ,
const K * lo ,
const K * hi ,
425 int & h , std::size_t & n )
const;
429 [[nodiscard]]
bool consistent(
void )
const;
432 void path( std::size_t len )
const;
439 std::size_t f_splits = 0;
440 std::size_t f_merges = 0;
441 std::size_t f_borrows = 0;
442 mutable std::size_t f_held = 0;
443 mutable std::size_t f_peak = 0;
444 mutable std::size_t f_peakPath = 0;
456#include "ADS/external/impl/BlockBTree.tpp"
The store of blocks of section 14.1 of Morin's book, beyond the book: a disk simulated in memory,...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
a B-tree of keys whose nodes are the blocks of a BlockStore
Definition BlockBTree.h:156
bool remove(const K &x)
removes ; true if it was there, in I/Os
std::size_t borrows(void) const
the borrows so far
Definition BlockBTree.h:291
BlockBTree(int B, BTreePolicy p=BTreePolicy::STANDARD, TwoLevelMemory *mem=nullptr)
the empty tree of the parameter and of the policy p, whose I/Os are also counted by mem,...
std::size_t internalNodes(void) const
the number of internal nodes
K Key
the type of the keys
Definition BlockBTree.h:160
bool contains(const K &x) const
true if is there, in I/Os
std::optional< K > lowerBound(const K &x) const
the smallest key , or nothing, in I/Os: a copy, since the blocks of the external memory are copied i...
bool insert(const K &x)
adds ; true if it was not there, in I/Os
std::size_t peakPath(void) const
the longest path kept by an operation, in pairs of indices
Definition BlockBTree.h:297
std::size_t peakNodes(void) const
the most nodes held in memory at once by an operation
Definition BlockBTree.h:294
void assign(const std::vector< std::vector< std::vector< K > > > &L)
the tree of the levels , as levels() gives them, in place of this one (the trees of the figures of th...
int height(void) const
the number of levels, 1 for a root that is a leaf
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,...
std::size_t splits(void) const
the splits so far
Definition BlockBTree.h:285
std::uint64_t writes(void) const
the writes of blocks so far
Definition BlockBTree.h:271
std::size_t nodes(void) const
the number of blocks in use, the nodes
Definition BlockBTree.h:277
std::size_t restructures(void) const
the splits, the merges and the borrows so far
Definition BlockBTree.h:280
K Item
the items of the sorted set, the keys
Definition BlockBTree.h:161
std::size_t merges(void) const
the merges so far
Definition BlockBTree.h:288
int order(void) const
the parameter
Definition BlockBTree.h:259
void resetCounters(void)
the counters of the I/Os back to 0
Definition BlockBTree.h:274
void forEach(F &&f) const
f( x ) on the keys in increasing order, with no I/O
std::size_t size(void) const
the number of keys
Definition BlockBTree.h:253
std::uint64_t reads(void) const
the reads of blocks so far
Definition BlockBTree.h:268
bool empty(void) const
true if there are no keys
Definition BlockBTree.h:256
the parameters and of the model, the counters of the I/Os and the occupation of the internal memory
Definition TwoLevelMemory.h:94
BTreePolicy
how a BlockBTree keeps its nodes within their bounds
Definition BlockBTree.h:146
@ THREE
the book's bounds but in a tree of two leaves, by three
Definition BlockBTree.h:149
@ STANDARD
to keys, the book's rules
Definition BlockBTree.h:147
@ WIDE
to keys (exercise 14.6)
Definition BlockBTree.h:148