ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::BlockBTree< K > Class Template Reference

a B-tree of keys whose nodes are the blocks of a BlockStore More...

#include <ADS/external/BlockBTree.h>

Public types

using Key = K
 the type of the keys
using Item = K
 the items of the sorted set, the keys

Public member functions

 BlockBTree (int B, BTreePolicy p=BTreePolicy::STANDARD, TwoLevelMemory *mem=nullptr)
 the empty tree of the parameter \( B \) and of the policy p, whose I/Os are also counted by mem, if given
std::optional< K > lowerBound (const K &x) const
 the smallest key \( \ge x \), or nothing, in \( O( \log_B n ) \) I/Os: a copy, since the blocks of the external memory are copied into the internal one, not pointed to
bool contains (const K &x) const
 true if \( x \) is there, in \( O( \log_B n ) \) I/Os
bool insert (const K &x)
 adds \( x \); true if it was not there, in \( O( \log_B n ) \) I/Os
bool remove (const K &x)
 removes \( x \); true if it was there, in \( O( \log_B n ) \) I/Os
std::size_t size (void) const
 the number \( n \) of keys
bool empty (void) const
 true if there are no keys
int order (void) const
 the parameter \( B \)
int height (void) const
 the number of levels, 1 for a root that is a leaf
std::size_t internalNodes (void) const
 the number of internal nodes
std::uint64_t reads (void) const
 the reads of blocks so far
std::uint64_t writes (void) const
 the writes of blocks so far
void resetCounters (void)
 the counters of the I/Os back to 0
std::size_t nodes (void) const
 the number of blocks in use, the nodes
std::size_t restructures (void) const
 the splits, the merges and the borrows so far
std::size_t splits (void) const
 the splits so far
std::size_t merges (void) const
 the merges so far
std::size_t borrows (void) const
 the borrows so far
std::size_t peakNodes (void) const
 the most nodes held in memory at once by an operation
std::size_t peakPath (void) const
 the longest path kept by an operation, in pairs of indices
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, with no I/O
void assign (const std::vector< std::vector< std::vector< K > > > &L)
 the tree of the levels \( L \), as levels() gives them, in place of this one (the trees of the figures of the book)
template<class F>
void forEach (F &&f) const
 f( x ) on the keys in increasing order, with no I/O

Detailed description

template<std::totally_ordered K>
class ADS::BlockBTree< K >

a B-tree of keys whose nodes are the blocks of a BlockStore

Member typedef documentation

◆ Item

template<std::totally_ordered K>
using ADS::BlockBTree< K >::Item = K

the items of the sorted set, the keys

◆ Key

template<std::totally_ordered K>
using ADS::BlockBTree< K >::Key = K

the type of the keys

Constructor and destructor documentation

◆ BlockBTree()

template<std::totally_ordered K>
ADS::BlockBTree< K >::BlockBTree ( int B,
BTreePolicy p = BTreePolicy::STANDARD,
TwoLevelMemory * mem = nullptr )
explicit

the empty tree of the parameter \( B \) and of the policy p, whose I/Os are also counted by mem, if given

Precondition
\( B \ge 2 \)

Member function documentation

◆ assign()

template<std::totally_ordered K>
void ADS::BlockBTree< K >::assign ( const std::vector< std::vector< std::vector< K > > > & L)

the tree of the levels \( L \), as levels() gives them, in place of this one (the trees of the figures of the book)

Precondition
\( L \) is a B-tree of the bounds of the policy

◆ borrows()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::borrows ( void ) const
inlinenodiscard

the borrows so far

◆ contains()

template<std::totally_ordered K>
bool ADS::BlockBTree< K >::contains ( const K & x) const
nodiscard

true if \( x \) is there, in \( O( \log_B n ) \) I/Os

◆ empty()

template<std::totally_ordered K>
bool ADS::BlockBTree< K >::empty ( void ) const
inlinenodiscard

true if there are no keys

◆ forEach()

template<std::totally_ordered K>
template<class F>
void ADS::BlockBTree< K >::forEach ( F && f) const

f( x ) on the keys in increasing order, with no I/O

◆ height()

template<std::totally_ordered K>
int ADS::BlockBTree< K >::height ( void ) const
nodiscard

the number of levels, 1 for a root that is a leaf

◆ insert()

template<std::totally_ordered K>
bool ADS::BlockBTree< K >::insert ( const K & x)

adds \( x \); true if it was not there, in \( O( \log_B n ) \) I/Os

In pseudocode (section 14.2.2 of Morin's book, with the path kept instead of the nodes):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x ) \cr 2 & \quad P \gets \text{the blocks and the children from the root to } \text{the leaf } u \text{ of } x \cr 3 & \quad \textbf{if}\ x \text{ was met}\ \textbf{then return false} \cr 4 & \quad \text{add } x \text{ to } u;\ \text{write } u \cr 5 & \quad \textbf{while}\ u \text{ has too many keys}\ \textbf{do} \cr 6 & \qquad ( p , i ) \gets \mathrm{pop}( P ) \text{, or a new root } \text{with the only child } u \cr 7 & \qquad \text{read } p;\ \text{deal the keys of the child } i \text{ (and of its siblings, by the policy) to one node more} \cr 8 & \qquad \text{write } p;\ u \gets p \cr 9 & \quad \textbf{return true} \end{array}} \]

Postcondition
\( x \) is there

◆ internalNodes()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::internalNodes ( void ) const
nodiscard

the number of internal nodes

◆ levels()

template<std::totally_ordered K>
std::vector< std::vector< std::vector< K > > > ADS::BlockBTree< K >::levels ( void ) const
nodiscard

the keys of the nodes level by level, from the root, each level from left to right, with no I/O

◆ lowerBound()

template<std::totally_ordered K>
std::optional< K > ADS::BlockBTree< K >::lowerBound ( const K & x) const
nodiscard

the smallest key \( \ge x \), or nothing, in \( O( \log_B n ) \) I/Os: a copy, since the blocks of the external memory are copied into the internal one, not pointed to

In pseudocode (section 14.2.1 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr 2 & \quad u \gets \mathit{root};\ z \gets \textbf{nil} \cr 3 & \quad \textbf{loop} \cr 4 & \qquad \text{read } u;\ i \gets \text{the first place with } u.\mathit{keys}[ i ] \ge x \cr 5 & \qquad \textbf{if}\ i < |u.\mathit{keys}| \textbf{ and } u.\mathit{keys}[ i ] = x\ \textbf{then return}\ x \cr 6 & \qquad \textbf{if}\ i < |u.\mathit{keys}|\ \textbf{then}\ z \gets u.\mathit{keys}[ i ] \cr 7 & \qquad \textbf{if}\ u \text{ is a leaf}\ \textbf{then return}\ z \cr 8 & \qquad u \gets u.\mathit{children}[ i ] \end{array}} \]

◆ merges()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::merges ( void ) const
inlinenodiscard

the merges so far

◆ nodes()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::nodes ( void ) const
inlinenodiscard

the number of blocks in use, the nodes

◆ order()

template<std::totally_ordered K>
int ADS::BlockBTree< K >::order ( void ) const
inlinenodiscard

the parameter \( B \)

◆ peakNodes()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::peakNodes ( void ) const
inlinenodiscard

the most nodes held in memory at once by an operation

◆ peakPath()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::peakPath ( void ) const
inlinenodiscard

the longest path kept by an operation, in pairs of indices

◆ reads()

template<std::totally_ordered K>
std::uint64_t ADS::BlockBTree< K >::reads ( void ) const
inlinenodiscard

the reads of blocks so far

◆ remove()

template<std::totally_ordered K>
bool ADS::BlockBTree< K >::remove ( const K & x)

removes \( x \); true if it was there, in \( O( \log_B n ) \) I/Os

In pseudocode (section 14.2.3 of Morin's book, with the path kept instead of the nodes):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( x ) \cr 2 & \quad P \gets \text{the path to } x \text{ and, if } x \text{ is } \text{in an internal node } t \text{, on to the leftmost leaf of } \text{its right subtree} \cr 3 & \quad \textbf{if}\ x \text{ was not met}\ \textbf{then return false} \cr 4 & \quad \text{take } x \text{, or the first key } y \text{ of the } \text{leaf, out of the leaf } u;\ \text{write } u \cr 5 & \quad \textbf{while}\ u \text{ has too few keys}\ \textbf{do} \cr 6 & \qquad ( p , i ) \gets \mathrm{pop}( P );\ \text{read } p ;\ \textbf{if}\ p = t\ \textbf{then}\ \text{put } y \text{ in place of } x \cr 7 & \qquad \text{deal the keys of the child } i \text{ and of its } \text{siblings to as many nodes or one fewer} \cr 8 & \qquad \text{write } p;\ u \gets p \cr 9 & \quad \textbf{if}\ t \text{ was not reached}\ \textbf{then} \ \text{read } t \text{, put } y \text{ in place of } x \text{, write } t \cr 10 & \quad \textbf{if}\ \text{the root has no key and a child} \ \textbf{then}\ \text{the child becomes the root} \cr 11 & \quad \textbf{return true} \end{array}} \]

Postcondition
\( x \) is not there

◆ resetCounters()

template<std::totally_ordered K>
void ADS::BlockBTree< K >::resetCounters ( void )
inline

the counters of the I/Os back to 0

◆ restructures()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::restructures ( void ) const
inlinenodiscard

the splits, the merges and the borrows so far

◆ size()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::size ( void ) const
inlinenodiscard

the number \( n \) of keys

◆ splits()

template<std::totally_ordered K>
std::size_t ADS::BlockBTree< K >::splits ( void ) const
inlinenodiscard

the splits so far

◆ writes()

template<std::totally_ordered K>
std::uint64_t ADS::BlockBTree< K >::writes ( void ) const
inlinenodiscard

the writes of blocks so far


The documentation for this class was generated from the following file: