ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::LAVector Class Reference

a non-decreasing sequence of integers of 64 bits as the segments of an optimal piecewise linear approximation and the corrections of the items More...

#include <ADS/succinct/LAVector.h>

Public types

using value_type = std::uint64_t
 the type of an item
using size_type = std::size_t
 the type of a size
using difference_type = std::ptrdiff_t
 the type of the distance of two places
using reference = std::uint64_t
 an item, returned by value
using const_reference = std::uint64_t
 an item, returned by value
using const_iterator = SubscriptIterator< LAVector , std::uint64_t >
 the constant iterator, random access
using iterator = const_iterator
 the same as const_iterator

Public member functions

 LAVector (void)=default
 the empty sequence
 LAVector (const std::vector< std::uint64_t > &x, int c=7)
 the sequence \( x \) with corrections of \( c \) bits, i.e., the error \( \epsilon = 2^{c-1} - 1 \) (0 for \( c \le 1 \))
std::size_t size (void) const
 the number of items, \( n \)
bool empty (void) const
 whether there is no item
int correctionBits (void) const
 the bits \( c \) of the corrections asked for
std::size_t segments (void) const
 the number of segments, \( m \)
std::uint64_t access (std::size_t i) const
 the item \( i \)
std::uint64_t operator[] (std::size_t i) const
 the item \( i \), as access()
std::uint64_t select (std::size_t k) const
 the \( k \)-th smallest item, i.e., access( k - 1 ), the select of the vector of bits whose 1s are the items
std::size_t nextGEQ (std::uint64_t x) const
 the place of the first item \( \ge x \), size() if there is none, i.e., the number of items \( < x \), the rank of the vector of bits whose 1s are the items
std::size_t rank (std::uint64_t x) const
 the number of items \( < x \), as nextGEQ()
bool contains (std::uint64_t x) const
 whether \( x \) is an item, by nextGEQ()
std::size_t correctionsInBits (void) const
 the bits of the corrections
std::size_t sizeInBits (void) const
 all the bits: the corrections, the segments and the tables
std::vector< std::uint64_t > decode (void) const
 the items, decoded in \( O( n ) \) time
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]
const_iterator begin (void) const
 the iterator on the first item
const_iterator end (void) const
 the iterator past the last item
const_iterator cbegin (void) const
 the same as begin()
const_iterator cend (void) const
 the same as end()

Static public member functions

static LAVector tuned (const std::vector< std::uint64_t > &x)
 the sequence \( x \) with the \( c \) of the fewest bits, among the odd ones up to \( c_{\mathrm{max}} \) of widest() and the two around the best of them

Static public attributes

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

Detailed description

a non-decreasing sequence of integers of 64 bits as the segments of an optimal piecewise linear approximation and the corrections of the items

Member typedef documentation

◆ const_iterator

the constant iterator, random access

◆ const_reference

using ADS::LAVector::const_reference = std::uint64_t

an item, returned by value

◆ difference_type

using ADS::LAVector::difference_type = std::ptrdiff_t

the type of the distance of two places

◆ iterator

◆ reference

using ADS::LAVector::reference = std::uint64_t

an item, returned by value

◆ size_type

using ADS::LAVector::size_type = std::size_t

the type of a size

◆ value_type

using ADS::LAVector::value_type = std::uint64_t

the type of an item

Constructor and destructor documentation

◆ LAVector() [1/2]

ADS::LAVector::LAVector ( void )
default

the empty sequence

◆ LAVector() [2/2]

ADS::LAVector::LAVector ( const std::vector< std::uint64_t > & x,
int c = 7 )
explicit

the sequence \( x \) with corrections of \( c \) bits, i.e., the error \( \epsilon = 2^{c-1} - 1 \) (0 for \( c \le 1 \))

In pseudocode (Boffa, Ferragina and Vinciguerra, beyond the book), \( T( v ) \) the integer part of \( v \ge 0 \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( x , c ) \cr 2 & \quad \textbf{foreach}\ \text{segment } j \text{ of } \mathrm{approximate}( ( i , x_i ) , \epsilon )\ \textbf{do}\quad \triangleright\ \text{see } \mathrm{PGMIndex} \cr 3 & \qquad \textbf{for}\ i \gets p_j\ \textbf{to}\ p_{j+1} - 1 \ \textbf{do}\ d_i \gets x_i - x_{p_j} - T( \alpha_j ( i - p_j ) ) \cr 4 & \qquad \beta_j \gets x_{p_j} + \min_i d_i;\ w_j \gets \lceil \log_2( \max_i d_i - \min_i d_i + 1 ) \rceil \cr 5 & \qquad \textbf{for}\ i \gets p_j\ \textbf{to}\ p_{j+1} - 1 \ \textbf{do}\ \mathrm{append}( C , d_i - \min_i d_i , w_j ) \cr 6 & \quad \text{fill the table of the segment of every } 2^t \text{-th place and the table on the high bits of the first items} \end{array}} \]

Precondition
\( x \) is non-decreasing (an audit), \( n < 2^{32} \) and \( 0 \le c \le 63 \)

Member function documentation

◆ access()

std::uint64_t ADS::LAVector::access ( std::size_t i) const
nodiscard

the item \( i \)

In pseudocode (Boffa, Ferragina and Vinciguerra, beyond the book), \( J \) the table of the segment of every \( 2^t \)-th place:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{access}( i ) \cr 2 & \quad j \gets J[ \lfloor i / 2^t \rfloor ] \cr 3 & \quad \textbf{while}\ p_{j+1} \le i\ \textbf{do}\ j \gets j + 1 \cr 4 & \quad \textbf{return}\ \beta_j + T( \alpha_j ( i - p_j ) ) + C[ i ] \end{array}} \]

Precondition
\( i < \) size()

◆ begin()

const_iterator ADS::LAVector::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ cbegin()

const_iterator ADS::LAVector::cbegin ( void ) const
inlinenodiscard

the same as begin()

◆ cend()

const_iterator ADS::LAVector::cend ( void ) const
inlinenodiscard

the same as end()

◆ contains()

bool ADS::LAVector::contains ( std::uint64_t x) const
nodiscard

whether \( x \) is an item, by nextGEQ()

◆ correctionBits()

int ADS::LAVector::correctionBits ( void ) const
nodiscard

the bits \( c \) of the corrections asked for

◆ correctionsInBits()

std::size_t ADS::LAVector::correctionsInBits ( void ) const
nodiscard

the bits of the corrections

◆ decode()

std::vector< std::uint64_t > ADS::LAVector::decode ( void ) const
nodiscard

the items, decoded in \( O( n ) \) time

◆ empty()

bool ADS::LAVector::empty ( void ) const
nodiscard

whether there is no item

◆ end()

const_iterator ADS::LAVector::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ nextGEQ()

std::size_t ADS::LAVector::nextGEQ ( std::uint64_t x) const
nodiscard

the place of the first item \( \ge x \), size() if there is none, i.e., the number of items \( < x \), the rank of the vector of bits whose 1s are the items

In pseudocode (Boffa, Ferragina and Vinciguerra, beyond the book), \( V \) the table of the first segment of each bucket of the high bits and \( \ell \) the low bits left out:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{nextGEQ}( x ) \cr 2 & \quad \textbf{if}\ n = 0\ \textbf{or}\ x \le x_0\ \textbf{then return} \ 0 \cr 3 & \quad \textbf{if}\ x > x_{n-1}\ \textbf{then return}\ n \cr 4 & \quad h \gets \lfloor ( x - x_0 ) / 2^\ell \rfloor \cr 5 & \quad j \gets \text{the last segment in } [ V[ h ] - 1 , V[ h + 1 ] ] \text{ with } x_{p_j} < x\text{, by a binary search} \cr 6 & \quad a \gets p_j + \lfloor ( x - \beta_j - 2^{w_j} ) / \alpha_j \rfloor - 1;\ b \gets p_j + \lceil ( x - \beta_j + 1 ) / \alpha_j \rceil + 1 \cr 7 & \quad \textbf{if}\ \text{not}\ x_{a-1} < x \le x_b\ \textbf{then} \ ( a , b ) \gets ( p_j , p_{j+1} ) \cr 8 & \quad \textbf{return}\ \text{the first } i \in [ a , b ] \text{ with } x_i \ge x \text{, by a binary search} \end{array}} \]

Postcondition
the items before it are \( < x \), the one at it is \( \ge x \)

◆ operator[]()

std::uint64_t ADS::LAVector::operator[] ( std::size_t i) const
nodiscard

the item \( i \), as access()

Precondition
\( i < \) size()

◆ persist()

template<class A>
void ADS::LAVector::persist ( A & a)

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

◆ rank()

std::size_t ADS::LAVector::rank ( std::uint64_t x) const
nodiscard

the number of items \( < x \), as nextGEQ()

◆ segments()

std::size_t ADS::LAVector::segments ( void ) const
nodiscard

the number of segments, \( m \)

◆ select()

std::uint64_t ADS::LAVector::select ( std::size_t k) const
nodiscard

the \( k \)-th smallest item, i.e., access( k - 1 ), the select of the vector of bits whose 1s are the items

Precondition
\( 1 \le k \le \) size()

◆ size()

std::size_t ADS::LAVector::size ( void ) const
nodiscard

the number of items, \( n \)

◆ sizeInBits()

std::size_t ADS::LAVector::sizeInBits ( void ) const
nodiscard

all the bits: the corrections, the segments and the tables

◆ tuned()

LAVector ADS::LAVector::tuned ( const std::vector< std::uint64_t > & x)
staticnodiscard

the sequence \( x \) with the \( c \) of the fewest bits, among the odd ones up to \( c_{\mathrm{max}} \) of widest() and the two around the best of them

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{tuned}( x ) \cr 2 & \quad b \gets \mathrm{build}( x , 1 );\ t \gets c_{\mathrm{max}} \cr 3 & \quad \textbf{for}\ c \gets 3\ \textbf{to}\ t\ \textbf{step}\ 2 \ \textbf{do} \cr 4 & \qquad v \gets \mathrm{build}( x , c );\ \textbf{if}\ v \text{ takes} \text{ fewer bits than } b\ \textbf{then}\ b \gets v \cr 5 & \quad \textbf{foreach}\ c \in \{ c_b - 1 , c_b + 1 \}\ \textbf{do} \ \text{the same} \cr 6 & \quad \textbf{return}\ b \end{array}} \]

Precondition
as for the constructor

Member data documentation

◆ persistName

std::string_view ADS::LAVector::persistName = "LAVector"
staticconstexpr

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


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