ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PackedArray< B, Saturate > Class Template Reference

\( n \) unsigned fields of \( B \) bits, \( 64 / B \) to a word, the values above \( 2^B - 1 \) clamped to it if Saturate More...

#include <ADS/succinct/PackedArray.h>

Public types

using Word = std::uint64_t
 the type of the words

Public member functions

 PackedArray (void)=default
 the empty array
 PackedArray (std::size_t n, Word v=0)
 \( n \) fields of the value \( v \)
template<Executor E, class F>
 PackedArray (E &ex, std::size_t n, F &&f)
 the fields f( i ) for \( i \in [ 0 , n ) \), filled by blocks of whole words on the threads of ex, \( O( n / p + \log n ) \) time on \( p \) threads
 PackedArray (std::span< const Word > w, std::size_t n)
 the \( n \) fields of the words \( w \), the field \( i \) in the bits from \( ( i \bmod 64 / B ) B \) of the word \( \lfloor i B / 64 \rfloor \), as in words() (and in the int_vector of sdsl-lite); the bits past the last field are cleared
std::size_t size (void) const
 the number of fields, \( n \)
bool empty (void) const
 whether there is no field
Word get (std::size_t i) const
 the value of the field \( i \), the bits \( ( i \bmod 64 / B ) B \) on of the word \( \lfloor i B / 64 \rfloor \)
Word operator[] (std::size_t i) const
 as get( i )
bool set (std::size_t i, Word v)
 the field \( i \) set to \( v \), or to \( 2^B - 1 \) if \( v \) is larger and Saturate; true if \( v \) was clamped
void push_back (Word v)
 appends a field of the value \( v \), clamped if Saturate
std::size_t clamped (void) const
 the values clamped by the constructors, by set() and by push_back(), 0 unless Saturate
const std::vector< Word > & words (void) const
 the words, the field \( i \) in the word \( \lfloor i B / 64 \rfloor \), the bits past the last field 0
std::size_t bytes (void) const
 the memory of the fields, in bytes
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 width of the fields, in a file

Static public attributes

static constexpr std::size_t PER = 64 / B
 the fields in a word
static constexpr Word MAX = ( Word( 1 ) << B ) - 1
 the largest value of a field, \( 2^B - 1 \)
static constexpr std::string_view persistName = "PackedArray"
 the name of the structure in a file [see Persistence.h]

Friends

bool operator== (const PackedArray &a, const PackedArray &b)
 whether the two arrays have the same fields

Detailed description

template<unsigned B, bool Saturate = false>
class ADS::PackedArray< B, Saturate >

\( n \) unsigned fields of \( B \) bits, \( 64 / B \) to a word, the values above \( 2^B - 1 \) clamped to it if Saturate

Member typedef documentation

◆ Word

template<unsigned B, bool Saturate = false>
using ADS::PackedArray< B, Saturate >::Word = std::uint64_t

the type of the words

Constructor and destructor documentation

◆ PackedArray() [1/4]

template<unsigned B, bool Saturate = false>
ADS::PackedArray< B, Saturate >::PackedArray ( void )
default

the empty array

◆ PackedArray() [2/4]

template<unsigned B, bool Saturate = false>
ADS::PackedArray< B, Saturate >::PackedArray ( std::size_t n,
Word v = 0 )
explicit

\( n \) fields of the value \( v \)

Precondition
\( v \le 2^B - 1 \) unless Saturate

◆ PackedArray() [3/4]

template<unsigned B, bool Saturate = false>
template<Executor E, class F>
ADS::PackedArray< B, Saturate >::PackedArray ( E & ex,
std::size_t n,
F && f )

the fields f( i ) for \( i \in [ 0 , n ) \), filled by blocks of whole words on the threads of ex, \( O( n / p + \log n ) \) time on \( p \) threads

In pseudocode (beyond the book), the words of \( W \) split in blocks by parallelForBlocks():

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( \mathit{ex} , n , f ) \cr 2 & \quad \textbf{foreach}\ \text{block } [ a , b ) \text{ of the } \text{words, in parallel}\ \textbf{do} \cr 3 & \qquad \textbf{for}\ w \gets a\ \textbf{to}\ b - 1\ \textbf{do} \cr 4 & \qquad\quad x \gets 0 \cr 5 & \qquad\quad \textbf{for}\ j \gets 0\ \textbf{to}\ \min\{ 64 / B , n - 64 w / B \} - 1\ \textbf{do} \cr 6 & \qquad\qquad x \gets x \vee ( \min\{ f( 64 w / B + j ) , 2^B - 1 \} \ll j B ) \cr 7 & \qquad\quad W[ w ] \gets x \end{array}} \]

Precondition
f( i ) is at most \( 2^B - 1 \) unless Saturate, and it may be called on any thread

◆ PackedArray() [4/4]

template<unsigned B, bool Saturate = false>
ADS::PackedArray< B, Saturate >::PackedArray ( std::span< const Word > w,
std::size_t n )

the \( n \) fields of the words \( w \), the field \( i \) in the bits from \( ( i \bmod 64 / B ) B \) of the word \( \lfloor i B / 64 \rfloor \), as in words() (and in the int_vector of sdsl-lite); the bits past the last field are cleared

Precondition
\( w \) holds \( \lceil n B / 64 \rceil \) words at least

Member function documentation

◆ bytes()

template<unsigned B, bool Saturate = false>
std::size_t ADS::PackedArray< B, Saturate >::bytes ( void ) const
inlinenodiscard

the memory of the fields, in bytes

◆ clamped()

template<unsigned B, bool Saturate = false>
std::size_t ADS::PackedArray< B, Saturate >::clamped ( void ) const
inlinenodiscard

the values clamped by the constructors, by set() and by push_back(), 0 unless Saturate

◆ empty()

template<unsigned B, bool Saturate = false>
bool ADS::PackedArray< B, Saturate >::empty ( void ) const
inlinenodiscard

whether there is no field

◆ get()

template<unsigned B, bool Saturate = false>
Word ADS::PackedArray< B, Saturate >::get ( std::size_t i) const
nodiscard

the value of the field \( i \), the bits \( ( i \bmod 64 / B ) B \) on of the word \( \lfloor i B / 64 \rfloor \)

Precondition
\( i < n \)

◆ operator[]()

template<unsigned B, bool Saturate = false>
Word ADS::PackedArray< B, Saturate >::operator[] ( std::size_t i) const
inlinenodiscard

as get( i )

Precondition
\( i < n \)

◆ persist()

template<unsigned B, bool Saturate = false>
template<class A>
void ADS::PackedArray< B, Saturate >::persist ( A & a)

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

◆ persistTag()

template<unsigned B, bool Saturate = false>
constexpr std::uint64_t ADS::PackedArray< B, Saturate >::persistTag ( void )
inlinestaticnodiscardconstexpr

the width of the fields, in a file

◆ push_back()

template<unsigned B, bool Saturate = false>
void ADS::PackedArray< B, Saturate >::push_back ( Word v)

appends a field of the value \( v \), clamped if Saturate

Precondition
\( v \le 2^B - 1 \) unless Saturate

◆ set()

template<unsigned B, bool Saturate = false>
bool ADS::PackedArray< B, Saturate >::set ( std::size_t i,
Word v )

the field \( i \) set to \( v \), or to \( 2^B - 1 \) if \( v \) is larger and Saturate; true if \( v \) was clamped

In pseudocode (beyond the book), \( s = ( i \bmod 64 / B ) B \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{set}( i , v ) \cr 2 & \quad c \gets v > 2^B - 1;\ v \gets \min\{ v , 2^B - 1 \} \cr 3 & \quad W[ \lfloor i B / 64 \rfloor ] \gets ( W[ \lfloor i B / 64 \rfloor ] \wedge \neg( ( 2^B - 1 ) \ll s ) ) \vee ( v \ll s ) \cr 4 & \quad \textbf{return}\ c \end{array}} \]

Precondition
\( i < n \), and \( v \le 2^B - 1 \) unless Saturate
Postcondition
get( i ) is \( \min\{ v , 2^B - 1 \} \)

◆ size()

template<unsigned B, bool Saturate = false>
std::size_t ADS::PackedArray< B, Saturate >::size ( void ) const
inlinenodiscard

the number of fields, \( n \)

◆ words()

template<unsigned B, bool Saturate = false>
const std::vector< Word > & ADS::PackedArray< B, Saturate >::words ( void ) const
inlinenodiscard

the words, the field \( i \) in the word \( \lfloor i B / 64 \rfloor \), the bits past the last field 0

◆ operator==

template<unsigned B, bool Saturate = false>
bool operator== ( const PackedArray< B, Saturate > & a,
const PackedArray< B, Saturate > & b )
friend

whether the two arrays have the same fields

Member data documentation

◆ MAX

template<unsigned B, bool Saturate = false>
Word ADS::PackedArray< B, Saturate >::MAX = ( Word( 1 ) << B ) - 1
staticconstexpr

the largest value of a field, \( 2^B - 1 \)

◆ PER

template<unsigned B, bool Saturate = false>
std::size_t ADS::PackedArray< B, Saturate >::PER = 64 / B
staticconstexpr

the fields in a word

◆ persistName

template<unsigned B, bool Saturate = false>
std::string_view ADS::PackedArray< B, Saturate >::persistName = "PackedArray"
staticconstexpr

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


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