|
| | DynamicPGMIndex (void)=default |
| | an empty map
|
| | DynamicPGMIndex (const std::vector< std::pair< K, V > > &P) |
| | the map of the pairs \( P \), put in the one level that holds them
|
| void | insert (const K &k, const V &v) |
| | maps \( k \) to \( v \), whether \( k \) was there or not
|
| void | erase (const K &k) |
| | removes \( k \), if there, by the insertion of a tombstone
|
| const V * | find (const K &k) const |
| | the value of \( k \), nullptr if absent; valid until the next insertion or removal
|
| bool | contains (const K &k) const |
| | whether \( k \) is there, by find()
|
| std::optional< std::pair< K, V > > | lowerBound (const K &k) const |
| | the pair of the least key \( \ge k \), none if there is none
|
| template<class F> |
| void | forEach (const K &lo, const K &hi, F &&f) const |
| | calls \( f( k , v ) \) on the pairs with \( lo \le k < hi \), by increasing key, by the merge of lowerBound()
|
| std::size_t | entries (void) const |
| | the pairs stored, the tombstones and the pairs hidden by newer ones included
|
| std::size_t | levels (void) const |
| | the levels below the buffer, empty or not
|
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
requires std::is_arithmetic_v< K >
class ADS::DynamicPGMIndex< K, V, E, B, I >
the ordered map from the arithmetic keys K to the values V of the dynamic PGM-index, with the error \( \epsilon = E \) in the levels, the ratio \( B \) of the sizes of two levels and the least capacity \( I \) of a level with a PGM-index
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
the value of \( k \), nullptr if absent; valid until the next insertion or removal
In pseudocode (the logarithmic method of Bentley and Saxe, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{find}( k ) \cr
2 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ \text{the last level}
\ \textbf{do}\quad \triangleright\ \text{the newest first} \cr
3 & \qquad \textbf{if}\ L_i \text{ has a filter that rules out } k
\ \textbf{then continue} \cr
4 & \qquad r \gets \mathrm{lowerBound}( L_i , k )\quad \triangleright
\ \text{by the PGM-index of } L_i \text{, if it has one} \cr
5 & \qquad \textbf{if}\ L_i[ r ] \text{ has the key } k\ \textbf{then}
\cr
6 & \qquad\quad \textbf{return}\ \textbf{nil}\ \text{if it is a }
\text{tombstone, else its value} \cr
7 & \quad \textbf{return}\ \textbf{nil}
\end{array}}
\]
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
template<class F>
calls \( f( k , v ) \) on the pairs with \( lo \le k < hi \), by increasing key, by the merge of lowerBound()
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
maps \( k \) to \( v \), whether \( k \) was there or not
In pseudocode (the logarithmic method of Bentley and Saxe, beyond the book), \( \| L \| \) the pairs of a level and \( c_i = b_0 B^i \) the capacity of \( L_i \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr
2 & \quad \textbf{if}\ k \text{ is in } L_0\ \textbf{then}\ \text{set }
\text{its value to } v;\ \textbf{return} \cr
3 & \quad \textbf{if}\ \| L_0 \| < b_0\ \textbf{then}\ \text{insert }
( k , v ) \text{ in } L_0 \text{ in order};\ \textbf{return} \cr
4 & \quad s \gets \| L_0 \| + 1;\ t \gets 1 \cr
5 & \quad \textbf{while}\ L_t \text{ exists and } s > c_t - \| L_t \|
\ \textbf{do}\ s \gets s + \| L_t \|;\ t \gets t + 1 \cr
6 & \quad M \gets L_0 \text{ with } ( k , v ) \cr
7 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ t\ \textbf{do}\ M \gets
\mathrm{merge}( M , L_i )\quad \triangleright\ \text{the pair of }
M \text{ wins} \cr
8 & \quad \textbf{if}\ L_t \text{ is the last level}\ \textbf{then}
\ \text{drop the tombstones of } M \cr
9 & \quad L_0 , \ldots , L_{t-1} \gets \emptyset;\ L_t \gets M
\text{, with a PGM-index on its keys if } c_t \ge I
\end{array}}
\]
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
| std::optional< std::pair< K, V > > ADS::DynamicPGMIndex< K, V, E, B, I >::lowerBound |
( |
const K & | k | ) |
const |
|
nodiscard |
the pair of the least key \( \ge k \), none if there is none
In pseudocode (the logarithmic method of Bentley and Saxe, beyond the book), a place \( r_i \) per level:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lowerBound}( k ) \cr
2 & \quad \textbf{foreach}\ \text{level } i\ \textbf{do}\ r_i \gets
\mathrm{lowerBound}( L_i , k ) \cr
3 & \quad \textbf{loop} \cr
4 & \qquad \textbf{if}\ \text{every } r_i \text{ is past its level}
\ \textbf{then return}\ \textbf{nil} \cr
5 & \qquad \kappa \gets \min_i L_i[ r_i ].\mathit{key};\ j \gets
\text{the least } i \text{ with } L_i[ r_i ].\mathit{key} = \kappa \cr
6 & \qquad \textbf{if}\ L_j[ r_j ] \text{ is not a tombstone}
\ \textbf{then return}\ L_j[ r_j ] \cr
7 & \qquad \textbf{foreach}\ i \text{ with } L_i[ r_i ].\mathit{key} =
\kappa\ \textbf{do}\ r_i \gets r_i + 1
\end{array}}
\]
template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
the least capacity of a level with a PGM-index, \( I \), the smaller ones being searched by a binary search with no branch