|
| | SPlusTree (void)=default |
| | an empty tree
|
| | SPlusTree (const std::vector< T > &A, Less less=Less()) |
| | the tree on the sorted items of \( A \), in \( O( n ) \)
|
| | SPlusTree (const SPlusTree &o) |
| | a copy of the tree \( o \)
|
| | SPlusTree (SPlusTree &&o) noexcept=default |
| | the tree \( o \), moved
|
| SPlusTree & | operator= (SPlusTree o) noexcept |
| | the tree \( o \), assigned by a swap
|
| std::size_t | lowerBound (const T &v) const |
| | the first place of an item not smaller than \( v \), size() if none
|
| std::size_t | upperBound (const T &v) const |
| | the first place of an item larger than \( v \), size() if none
|
| bool | contains (const T &v) const |
| | true if \( v \) is an item, by lowerBound( v )
|
| const T & | operator[] (std::size_t i) const |
| | the item of place \( i \), in the sorted order
|
| std::size_t | size (void) const |
| | the number \( n \) of the items
|
| bool | empty (void) const |
| | true if there are no items
|
| int | height (void) const |
| | the levels, the leaves included
|
template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
requires std::is_trivially_copyable_v< T >
class ADS::SPlusTree< T, Less, Bytes >
the static B+-tree of Slotin on a sorted array, by the order less()
template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
| ADS::SPlusTree< T, Less, Bytes >::SPlusTree |
( |
const std::vector< T > & | A, |
|
|
Less | less = Less() ) |
|
explicit |
the tree on the sorted items of \( A \), in \( O( n ) \)
In pseudocode (the layout of Slotin, beyond the book), the levels numbered from the root, \( 0 \), to the leaves, \( H - 1 \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{layout}( A ) \cr
2 & \quad s_{H-1} \gets \lceil n / B \rceil;\ \textbf{while}\ s_\ell > 1
\ \textbf{do}\ s_{\ell-1} \gets \lceil s_\ell / ( B + 1 ) \rceil \cr
3 & \quad \text{fill all the nodes with the largest value};\ \text{copy }
A \text{ into the leaves} \cr
4 & \quad \textbf{foreach}\ \text{level } h < H - 1 \text{, node } k
\text{ and key } j\ \textbf{do} \cr
5 & \qquad c \gets k ( B + 1 ) + j + 1\quad \triangleright\ \text{the }
\text{child after the key} \cr
6 & \qquad \textbf{if}\ c < s_{h+1}\ \textbf{then}\ \text{key } j
\text{ of } k \gets A[ c ( B + 1 )^{H - h - 2} B ]
\end{array}}
\]
- Precondition
- \( A \) is sorted (audit)
template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
| std::size_t ADS::SPlusTree< T, Less, Bytes >::lowerBound |
( |
const T & | v | ) |
const |
|
nodiscard |
the first place of an item not smaller than \( v \), size() if none
In pseudocode (Slotin, beyond the book), \( \mathrm{count}( k , v ) \) the keys of the node \( k \) smaller than \( v \), with no branch on the arithmetic keys [see CountLess.h]:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lowerBound}( v ) \cr
2 & \quad k \gets 0 \cr
3 & \quad \textbf{for}\ h \gets 0\ \textbf{to}\ H - 2\ \textbf{do}\ k
\gets k ( B + 1 ) + \mathrm{count}( \text{node } k \text{ of level }
h , v ) \cr
4 & \quad \textbf{return}\ \min\{ n , k B + \mathrm{count}( \text{leaf }
k , v ) \}
\end{array}}
\]
- Postcondition
- \( A[ r - 1 ] < v \le A[ r ] \)
template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
| std::size_t ADS::SPlusTree< T, Less, Bytes >::upperBound |
( |
const T & | v | ) |
const |
|
nodiscard |
the first place of an item larger than \( v \), size() if none
It is lowerBound() above with the keys not larger than \( v \) counted, \( n \) at once if \( v \) is not smaller than the padding.
- Postcondition
- \( A[ r - 1 ] \le v < A[ r ] \)