ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::DynamicPGMIndex< K, V, E, B, I > Class Template Reference

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 More...

#include <ADS/search/DynamicPGMIndex.h>

Public types

using key_type = K
 the type of the keys
using mapped_type = V
 the type of the values

Public member functions

 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

Static public attributes

static constexpr std::size_t kBuffer = 128
 the pairs in the buffer, \( b_0 \)
static constexpr std::size_t kIndexed = I
 the least capacity of a level with a PGM-index, \( I \), the smaller ones being searched by a binary search with no branch
static constexpr std::size_t kFiltered = std::size_t( 1 ) << 12
 the least capacity of a level with a filter of its keys

Detailed description

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

Member typedef documentation

◆ key_type

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
using ADS::DynamicPGMIndex< K, V, E, B, I >::key_type = K

the type of the keys

◆ mapped_type

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
using ADS::DynamicPGMIndex< K, V, E, B, I >::mapped_type = V

the type of the values

Constructor and destructor documentation

◆ DynamicPGMIndex() [1/2]

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
ADS::DynamicPGMIndex< K, V, E, B, I >::DynamicPGMIndex ( void )
default

an empty map

◆ DynamicPGMIndex() [2/2]

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
ADS::DynamicPGMIndex< K, V, E, B, I >::DynamicPGMIndex ( const std::vector< std::pair< K, V > > & P)
explicit

the map of the pairs \( P \), put in the one level that holds them

Precondition
\( P \) sorted by key, no key twice (an audit)

Member function documentation

◆ contains()

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
bool ADS::DynamicPGMIndex< K, V, E, B, I >::contains ( const K & k) const
nodiscard

whether \( k \) is there, by find()

◆ entries()

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::size_t ADS::DynamicPGMIndex< K, V, E, B, I >::entries ( void ) const
nodiscard

the pairs stored, the tombstones and the pairs hidden by newer ones included

◆ erase()

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
void ADS::DynamicPGMIndex< K, V, E, B, I >::erase ( const K & k)

removes \( k \), if there, by the insertion of a tombstone

◆ find()

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
const V * ADS::DynamicPGMIndex< K, V, E, B, I >::find ( const K & k) const
nodiscard

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

◆ forEach()

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>
void ADS::DynamicPGMIndex< K, V, E, B, I >::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()

◆ insert()

template<class K, class V, std::size_t E = 16, std::size_t B = 8, std::size_t I = ( std::size_t( 1 ) << 24 )>
void ADS::DynamicPGMIndex< K, V, E, B, I >::insert ( const K & k,
const V & v )

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

◆ levels()

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::size_t ADS::DynamicPGMIndex< K, V, E, B, I >::levels ( void ) const
nodiscard

the levels below the buffer, empty or not

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

Member data documentation

◆ kBuffer

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::size_t ADS::DynamicPGMIndex< K, V, E, B, I >::kBuffer = 128
staticconstexpr

the pairs in the buffer, \( b_0 \)

◆ kFiltered

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::size_t ADS::DynamicPGMIndex< K, V, E, B, I >::kFiltered = std::size_t( 1 ) << 12
staticconstexpr

the least capacity of a level with a filter of its keys

◆ kIndexed

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::size_t ADS::DynamicPGMIndex< K, V, E, B, I >::kIndexed = I
staticconstexpr

the least capacity of a level with a PGM-index, \( I \), the smaller ones being searched by a binary search with no branch


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