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>
|
| using | Item = K |
| | the type of the items
|
|
| | 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 constexpr std::uint64_t | persistTag (void) |
| | the type of the keys and the errors, in a file
|
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
◆ Item
template<class K, std::size_t E = 64, std::size_t R = 4>
◆ PGMIndex() [1/2]
template<class K, std::size_t E = 64, std::size_t R = 4>
◆ PGMIndex() [2/2]
template<class K, std::size_t E = 64, std::size_t R = 4>
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} \)
◆ bytes()
template<class K, std::size_t E = 64, std::size_t R = 4>
the bytes of the index, the items aside
◆ contains()
template<class K, std::size_t E = 64, std::size_t R = 4>
true if \( v \) is an item, by lowerBound( v )
◆ empty()
template<class K, std::size_t E = 64, std::size_t R = 4>
true if there are no items
◆ height()
template<class K, std::size_t E = 64, std::size_t R = 4>
◆ 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>
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>
the segments of the last level
◆ size()
template<class K, std::size_t E = 64, std::size_t R = 4>
the number \( n \) of the items
◆ 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 documentation for this class was generated from the following file: