ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PGMIndex< K, E, R > Class Template Reference

the PGM-index on a sorted array of arithmetic keys K, with the error \( \epsilon = E \) at the last level and \( \epsilon_r = R \) at the others More...

#include <ADS/search/PGMIndex.h>

Public types

using Item = K
 the type of the items

Public member functions

 PGMIndex (void)=default
 an empty index
 PGMIndex (const std::vector< K > &A)
 the index on the sorted items of \( A \), a level of segments of error \( \epsilon \) on the distinct keys and their first places and the levels of error \( \epsilon_r \) above it
std::size_t lowerBound (const K &v) const
 the first place of an item not smaller than \( v \), size() if none
bool contains (const K &v) const
 true if \( v \) is an item, by lowerBound( v )
const K & operator[] (std::size_t i) const
 the item of place \( i \)
std::size_t size (void) const
 the number \( n \) of the items
bool empty (void) const
 true if there are no items
std::size_t segments (void) const
 the segments of the last level
int height (void) const
 the levels of segments
std::size_t bytes (void) const
 the bytes of the index, the items aside
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]

Static public member functions

static constexpr std::uint64_t persistTag (void)
 the type of the keys and the errors, in a file

Static public attributes

static constexpr std::string_view persistName = "PGMIndex"
 the name of the structure in a file [see Persistence.h]

Detailed description

template<class K, std::size_t E = 64, std::size_t R = 4>
requires std::is_arithmetic_v< K >
class ADS::PGMIndex< K, E, R >

the PGM-index on a sorted array of arithmetic keys K, with the error \( \epsilon = E \) at the last level and \( \epsilon_r = R \) at the others

Member typedef documentation

◆ Item

template<class K, std::size_t E = 64, std::size_t R = 4>
using ADS::PGMIndex< K, E, R >::Item = K

the type of the items

Constructor and destructor documentation

◆ PGMIndex() [1/2]

template<class K, std::size_t E = 64, std::size_t R = 4>
ADS::PGMIndex< K, E, R >::PGMIndex ( void )
default

an empty index

◆ PGMIndex() [2/2]

template<class K, std::size_t E = 64, std::size_t R = 4>
ADS::PGMIndex< K, E, R >::PGMIndex ( const std::vector< K > & A)
explicit

the index on the sorted items of \( A \), a level of segments of error \( \epsilon \) on the distinct keys and their first places and the levels of error \( \epsilon_r \) above it

In pseudocode (the optimal approximation of O'Rourke as engineered by Xie et al., beyond the book), for the points \( ( x_i , y_i ) \) of a level:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{approximate}( x , y , e ) \cr 2 & \quad L \gets \text{an empty level};\ \text{start a segment at } ( x_0 , y_0 ) \cr 3 & \quad \textbf{foreach}\ i \ge 1\ \textbf{do} \cr 4 & \qquad u \gets ( x_i , y_i + e );\ d \gets ( x_i , y_i - e ) \cr 5 & \qquad \textbf{if}\ \text{no line between the hulls passes } \text{between } u \text{ and } d\ \textbf{then} \cr 6 & \qquad\quad \text{close the segment into } L;\ \text{start one at } ( x_i , y_i );\ \textbf{continue} \cr 7 & \qquad \text{update the lines of least and of largest slope} \text{ with } u \text{ and } d \cr 8 & \qquad \text{add } u \text{ to the lower hull of the ups and } d \text{ to the upper hull of the downs} \cr 9 & \quad \text{close the last segment into } L;\ \textbf{return}\ L \cr 10 & \textbf{procedure}\ \mathrm{build}( A ) \cr 11 & \quad ( x , y ) \gets \text{the distinct keys of } A \text{ and } \text{their first places} \cr 12 & \quad L_0 \gets \mathrm{approximate}( x , y , \epsilon ) \cr 13 & \quad \textbf{while}\ L_h \text{ has more than one segment} \ \textbf{do} \cr 14 & \qquad L_{h+1} \gets \mathrm{approximate}( \text{the first keys } \text{of } L_h , 0 , 1 , 2 , \ldots , \epsilon_r ) \end{array}} \]

where closing a segment keeps the line through the crossing of the two extreme lines with the average of their slopes, not negative.

Precondition
\( A \) is sorted (audit), \( n < 2^{32} \)

Member function documentation

◆ bytes()

template<class K, std::size_t E = 64, std::size_t R = 4>
std::size_t ADS::PGMIndex< K, E, R >::bytes ( void ) const
nodiscard

the bytes of the index, the items aside

◆ contains()

template<class K, std::size_t E = 64, std::size_t R = 4>
bool ADS::PGMIndex< K, E, R >::contains ( const K & v) const
nodiscard

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

◆ empty()

template<class K, std::size_t E = 64, std::size_t R = 4>
bool ADS::PGMIndex< K, E, R >::empty ( void ) const
nodiscard

true if there are no items

◆ height()

template<class K, std::size_t E = 64, std::size_t R = 4>
int ADS::PGMIndex< K, E, R >::height ( void ) const
nodiscard

the levels of segments

◆ lowerBound()

template<class K, std::size_t E = 64, std::size_t R = 4>
std::size_t ADS::PGMIndex< K, E, R >::lowerBound ( const K & v) const
nodiscard

the first place of an item not smaller than \( v \), size() if none

In pseudocode (Ferragina and Vinciguerra, beyond the book), the levels \( L_{H-1} , \ldots , L_0 \) from the top, \( \mathrm{predict}( L , s , x ) \) the line of the segment \( s \) of \( L \) at \( x \), clamped to its range, and the places near \( p \) those in \( [ p - \epsilon_r - 2 , p + \epsilon_r + 2 ] \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lowerBound}( v ) \cr 2 & \quad \textbf{if}\ n = 0 \text{ or } v < A[ 0 ] \ \textbf{then return}\ 0 \cr 3 & \quad s \gets 0 \cr 4 & \quad \textbf{for}\ h \gets H - 1\ \textbf{downto}\ 1\ \textbf{do} \cr 5 & \qquad p \gets \mathrm{predict}( L_h , s , v ) \cr 6 & \qquad s \gets \text{the last segment of } L_{h-1} \text{ near } p \text{ with first key not larger than } v \cr 7 & \quad p \gets \mathrm{predict}( L_0 , s , v ) \cr 8 & \quad r \gets \mathrm{lowerBound}( A , v , p - \epsilon - 2 , p + \epsilon + 3 )\quad \triangleright\ \text{prefetched, no branch} \cr 9 & \quad \textbf{if}\ r \text{ is an end of the window and not the } \text{answer}\ \textbf{then} \cr 10 & \qquad r \gets \text{the answer by galloping out of the window} \cr 11 & \quad \textbf{return}\ r \end{array}} \]

Postcondition
\( A[ r - 1 ] < v \le A[ r ] \)

◆ operator[]()

template<class K, std::size_t E = 64, std::size_t R = 4>
const K & ADS::PGMIndex< K, E, R >::operator[] ( std::size_t i) const
nodiscard

the item of place \( i \)

Precondition
\( i < n \)

◆ persist()

template<class K, std::size_t E = 64, std::size_t R = 4>
template<class A>
void ADS::PGMIndex< K, E, R >::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ persistTag()

template<class K, std::size_t E = 64, std::size_t R = 4>
constexpr std::uint64_t ADS::PGMIndex< K, E, R >::persistTag ( void )
inlinestaticnodiscardconstexpr

the type of the keys and the errors, in a file

◆ segments()

template<class K, std::size_t E = 64, std::size_t R = 4>
std::size_t ADS::PGMIndex< K, E, R >::segments ( void ) const
nodiscard

the segments of the last level

◆ size()

template<class K, std::size_t E = 64, std::size_t R = 4>
std::size_t ADS::PGMIndex< K, E, R >::size ( void ) const
nodiscard

the number \( n \) of the items

Member data documentation

◆ persistName

template<class K, std::size_t E = 64, std::size_t R = 4>
std::string_view ADS::PGMIndex< K, E, R >::persistName = "PGMIndex"
staticconstexpr

the name of the structure in a file [see Persistence.h]


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