ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::SPlusTree< T, Less, Bytes > Class Template Reference

the static B+-tree of Slotin on a sorted array, by the order less() More...

#include <ADS/search/StaticSearch.h>

Public types

using Item = T
 the type of the items

Public member functions

 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

Static public attributes

static constexpr std::size_t B
 the items of a node, a line of cache

Detailed description

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()

Member typedef documentation

◆ Item

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
using ADS::SPlusTree< T, Less, Bytes >::Item = T

the type of the items

Constructor and destructor documentation

◆ SPlusTree() [1/4]

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
ADS::SPlusTree< T, Less, Bytes >::SPlusTree ( void )
default

an empty tree

◆ SPlusTree() [2/4]

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)

◆ SPlusTree() [3/4]

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
ADS::SPlusTree< T, Less, Bytes >::SPlusTree ( const SPlusTree< T, Less, Bytes > & o)

a copy of the tree \( o \)

◆ SPlusTree() [4/4]

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
ADS::SPlusTree< T, Less, Bytes >::SPlusTree ( SPlusTree< T, Less, Bytes > && o)
defaultnoexcept

the tree \( o \), moved

Member function documentation

◆ contains()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
bool ADS::SPlusTree< T, Less, Bytes >::contains ( const T & v) const
nodiscard

true if \( v \) is an item, by lowerBound( v )

◆ empty()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
bool ADS::SPlusTree< T, Less, Bytes >::empty ( void ) const
nodiscard

true if there are no items

◆ height()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
int ADS::SPlusTree< T, Less, Bytes >::height ( void ) const
nodiscard

the levels, the leaves included

◆ lowerBound()

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 ] \)

◆ operator=()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
SPlusTree & ADS::SPlusTree< T, Less, Bytes >::operator= ( SPlusTree< T, Less, Bytes > o)
noexcept

the tree \( o \), assigned by a swap

◆ operator[]()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
const T & ADS::SPlusTree< T, Less, Bytes >::operator[] ( std::size_t i) const
nodiscard

the item of place \( i \), in the sorted order

Precondition
\( i < n \)

◆ size()

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
std::size_t ADS::SPlusTree< T, Less, Bytes >::size ( void ) const
nodiscard

the number \( n \) of the items

◆ upperBound()

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 ] \)

Member data documentation

◆ B

template<class T, class Less = std::less< T >, std::size_t Bytes = 64>
std::size_t ADS::SPlusTree< T, Less, Bytes >::B
staticconstexpr
Initial value:
=
sizeof( T ) <= Bytes ? std::max< std::size_t >( Bytes / sizeof( T ) , 2 )
: 2

the items of a node, a line of cache


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