|
| | 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
|
template<std::totally_ordered K>
class ADS::BlockBTree< K >
a B-tree of keys whose nodes are the blocks of a BlockStore
template<std::totally_ordered K>
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
template<std::totally_ordered K>
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}}
\]
template<std::totally_ordered K>
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