|
ADS
Algorithms and Data Structures
|
a static sequence of integers of \( w \) bits with access, rank, select and the range quantiles in \( O( w ) \) time More...
#include <ADS/succinct/WaveletMatrix.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 a distance | |
| using | reference = std::uint64_t |
| an item, by value | |
| using | const_reference = std::uint64_t |
| an item, by value | |
| using | const_iterator = SubscriptIterator< WaveletMatrix , std::uint64_t > |
| an iterator on the items, by access() | |
| using | iterator = const_iterator |
| the items are read only | |
Public member functions | |
| WaveletMatrix (void)=default | |
| the empty sequence | |
| WaveletMatrix (std::span< const std::uint64_t > x, int w=0) | |
| the sequence \( x \), its items of \( w \) bits (0: the bits of the largest one), built by the passes of up to 8 levels of the constructor below on the calling thread, the levels those of a stable partition by each bit, from the most significant one (see Lemma 7 of Parallel construction) | |
| template<Executor E> | |
| WaveletMatrix (E &ex, std::span< const std::uint64_t > x, int w=0) | |
| the matrix of WaveletMatrix( x , w ) above, the same levels and directories, built on the threads of the executor ex by up to 8 levels at a time (see Parallel construction) | |
| template<class U> requires ( std::is_same_v< U , std::uint8_t > || std::is_same_v< U , std::uint16_t > || std::is_same_v< U , std::uint32_t > ) | |
| WaveletMatrix (std::span< const U > x, int w=0) | |
| the sequence \( x \) of items of 8, 16 or 32 bits, which the construction reads as they are, as WaveletMatrix( x , w ) above | |
| template<Executor E, class U> requires ( std::is_same_v< U , std::uint8_t > || std::is_same_v< U , std::uint16_t > || std::is_same_v< U , std::uint32_t > ) | |
| WaveletMatrix (E &ex, std::span< const U > x, int w=0) | |
| the sequence \( x \) of items of 8, 16 or 32 bits on the threads of ex, as WaveletMatrix( ex , x , w ) above | |
| std::size_t | size (void) const |
| the number of items | |
| bool | empty (void) const |
| whether there is no item | |
| int | width (void) const |
| the bits of an item | |
| std::uint64_t | access (std::size_t i) const |
| the item \( i \) | |
| std::uint64_t | operator[] (std::size_t i) const |
| the item \( i \), by access() | |
| std::size_t | rank (std::uint64_t c, std::size_t i) const |
| the number of \( c \) in the places \( [ 0 , i ) \) | |
| std::size_t | select (std::uint64_t c, std::size_t k) const |
| the place of the \( k \)-th \( c \) | |
| std::uint64_t | quantile (std::size_t i, std::size_t j, std::size_t k) const |
| the \( k \)-th smallest item of the places \( [ i , j ) \), from \( k = 0 \) | |
| std::size_t | countLess (std::size_t i, std::size_t j, std::uint64_t c) const |
| the number of the items below \( c \) in the places \( [ i , j ) \) | |
| std::size_t | sizeInBits (void) const |
| the bits of the levels and of their directories | |
| 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 first item | |
| const_iterator | end (void) const |
| one past the last item | |
| const_iterator | cbegin (void) const |
| the first item | |
| const_iterator | cend (void) const |
| one past the last item | |
Static public attributes | |
| static constexpr std::string_view | persistName = "WaveletMatrix" |
| the name of the structure in a file [see Persistence.h] | |
a static sequence of integers of \( w \) bits with access, rank, select and the range quantiles in \( O( w ) \) time
| using ADS::WaveletMatrix::const_iterator = SubscriptIterator< WaveletMatrix , std::uint64_t > |
an iterator on the items, by access()
| using ADS::WaveletMatrix::const_reference = std::uint64_t |
an item, by value
| using ADS::WaveletMatrix::difference_type = std::ptrdiff_t |
the type of a distance
the items are read only
| using ADS::WaveletMatrix::reference = std::uint64_t |
an item, by value
| using ADS::WaveletMatrix::size_type = std::size_t |
the type of a size
| using ADS::WaveletMatrix::value_type = std::uint64_t |
the type of an item
|
default |
the empty sequence
|
explicit |
the sequence \( x \), its items of \( w \) bits (0: the bits of the largest one), built by the passes of up to 8 levels of the constructor below on the calling thread, the levels those of a stable partition by each bit, from the most significant one (see Lemma 7 of Parallel construction)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{build}( x , w ) \cr 2 & \quad \textbf{return}\ \mathrm{build}( \text{the calling thread} , x , w ) \end{array}} \]
| ADS::WaveletMatrix::WaveletMatrix | ( | E & | ex, |
| std::span< const std::uint64_t > | x, | ||
| int | w = 0 ) |
the matrix of WaveletMatrix( x , w ) above, the same levels and directories, built on the threads of the executor ex by up to 8 levels at a time (see Parallel construction)
In pseudocode (the stable sorts by the prefixes of the bits, beyond the book), \( x \) cut into slices \( X_0 , \ldots , X_{q-1} \), the levels \( [ \ell , \ell + k ) \) of a pass, \( b_j( c ) \) the bit \( w - 1 - \ell - j \) of \( c \) and \( \kappa_j( c ) = \sum_{i < j} 2^i b_i( c ) \), the key by which the level \( \ell + j \) is the stable sort of the level \( \ell \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{build}( \mathit{ex} , x , w ) \cr 2 & \quad C \gets x;\ \ell \gets 0 \cr 3 & \quad \textbf{while}\ \ell < w\ \textbf{do} \cr 4 & \qquad k \gets \text{the levels of the pass, at most 8} \cr 5 & \qquad \textbf{foreach}\ \text{slice } X_s \text{ of } C \ \textbf{do in parallel}\ h_s[ a ] \gets | \{ c \in X_s : \kappa_k( c ) = a \} | \cr 6 & \qquad \textbf{for}\ j \gets 0\ \textbf{to}\ k\ \textbf{do} \ P_{j , s}[ a ] \gets \text{the items of } C \text{ with } \kappa_j < a \cr & \qquad\quad \text{or with } \kappa_j = a \text{ in the slices } \text{before } X_s \text{, by the sums of the } h \cr 7 & \qquad Z_{\ell + j} \gets \text{the items with } b_j = 0 \text{, for } j < k \cr 8 & \qquad \textbf{foreach}\ \text{slice } X_s\ \textbf{do in} \ \textbf{parallel} \cr 9 & \qquad\quad Q_{j , s}[ a ] \gets \text{the items of } X_s \text{ with } \kappa_j < a\quad \triangleright\ \text{places in} \text{ the slice} \cr 10 & \qquad\quad \textbf{foreach}\ c \in X_s \text{ in order} \ \textbf{do} \cr 11 & \qquad\qquad \textbf{for}\ j \gets 0\ \textbf{to}\ k - 1 \ \textbf{do}\ L_{s , j}[ Q_{j , s}[ \kappa_j( c ) ] ] \gets b_j( c );\ Q_{j , s}[ \kappa_j( c ) ] \gets Q_{j , s}[ \kappa_j( c ) ] + 1 \cr 12 & \qquad\qquad C'[ P_{k , s}[ \kappa_k( c ) ] ] \gets c; \ P_{k , s}[ \kappa_k( c ) ] \gets P_{k , s}[ \kappa_k( c ) ] + 1 \cr 13 & \qquad \textbf{foreach}\ \text{block of words of each } B_{\ell + j}\ \textbf{do in parallel} \cr 14 & \qquad\quad \text{copy into it the runs of the } L_{s , j} \text{ that fall in it, each at its place } P_{j , s} \cr 15 & \qquad C \gets C';\ \ell \gets \ell + k \cr 16 & \quad \textbf{return}\ \text{the levels } B_\ell \text{ with } \text{their directories, built on } \mathit{ex} \text{, and the } Z_\ell \end{array}} \]
|
explicit |
the sequence \( x \) of items of 8, 16 or 32 bits, which the construction reads as they are, as WaveletMatrix( x , w ) above
| ADS::WaveletMatrix::WaveletMatrix | ( | E & | ex, |
| std::span< const U > | x, | ||
| int | w = 0 ) |
the sequence \( x \) of items of 8, 16 or 32 bits on the threads of ex, as WaveletMatrix( ex , x , w ) above
|
nodiscard |
the item \( i \)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{access}( i ) \cr 2 & \quad c \gets 0 \cr 3 & \quad \textbf{for}\ \ell \gets 0\ \textbf{to}\ w - 1\ \textbf{do} \cr 4 & \qquad b \gets B_\ell[ i ];\ c \gets 2 c + b \cr 5 & \qquad \textbf{if}\ b = 1\ \textbf{then}\ i \gets Z_\ell + \mathrm{rank}_1( B_\ell , i )\ \textbf{else}\ i \gets \mathrm{rank}_0( B_\ell , i ) \cr 6 & \quad \textbf{return}\ c \end{array}} \]
|
inlinenodiscard |
the first item
|
inlinenodiscard |
the first item
|
inlinenodiscard |
one past the last item
|
nodiscard |
the number of the items below \( c \) in the places \( [ i , j ) \)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book), the range following the bits of \( c \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{countLess}( i , j , c ) \cr 2 & \quad \textbf{if}\ c \ge 2^w\ \textbf{then return}\ j - i \cr 3 & \quad r \gets 0 \cr 4 & \quad \textbf{for}\ \ell \gets 0\ \textbf{to}\ w - 1\ \textbf{while} \ i < j\ \textbf{do} \cr 5 & \qquad i_1 \gets \mathrm{rank}_1( B_\ell , i );\ j_1 \gets \mathrm{rank}_1( B_\ell , j ) \cr 6 & \qquad \textbf{if}\ c_\ell = 1\ \textbf{then}\ r \gets r + ( j - j_1 ) - ( i - i_1 );\ i \gets Z_\ell + i_1;\ j \gets Z_\ell + j_1 \cr 7 & \qquad \textbf{else}\ i \gets i - i_1;\ j \gets j - j_1 \cr 8 & \quad \textbf{return}\ r \end{array}} \]
|
inlinenodiscard |
whether there is no item
|
inlinenodiscard |
one past the last item
|
inlinenodiscard |
the item \( i \), by access()
| void ADS::WaveletMatrix::persist | ( | A & | a | ) |
the members written to, or read from, the archive \( a \) [see Persistence.h]
|
nodiscard |
the \( k \)-th smallest item of the places \( [ i , j ) \), from \( k = 0 \)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{quantile}( i , j , k ) \cr 2 & \quad c \gets 0 \cr 3 & \quad \textbf{for}\ \ell \gets 0\ \textbf{to}\ w - 1\ \textbf{do} \cr 4 & \qquad i_1 \gets \mathrm{rank}_1( B_\ell , i );\ j_1 \gets \mathrm{rank}_1( B_\ell , j );\ z \gets ( j - j_1 ) - ( i - i_1 ) \cr 5 & \qquad \textbf{if}\ k < z\ \textbf{then}\ c \gets 2 c;\ i \gets i - i_1;\ j \gets j - j_1\quad \triangleright\ \text{to the 0s} \cr 6 & \qquad \textbf{else}\ c \gets 2 c + 1;\ k \gets k - z;\ i \gets Z_\ell + i_1;\ j \gets Z_\ell + j_1 \cr 7 & \quad \textbf{return}\ c \end{array}} \]
|
nodiscard |
the number of \( c \) in the places \( [ 0 , i ) \)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book), with \( c_\ell \) the bit \( w - 1 - \ell \) of \( c \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank}( c , i ) \cr 2 & \quad \textbf{if}\ c \ge 2^w\ \textbf{then return}\ 0 \cr 3 & \quad s \gets 0 \cr 4 & \quad \textbf{for}\ \ell \gets 0\ \textbf{to}\ w - 1\ \textbf{do} \cr 5 & \qquad \textbf{if}\ c_\ell = 1\ \textbf{then}\ s \gets Z_\ell + \mathrm{rank}_1( B_\ell , s );\ i \gets Z_\ell + \mathrm{rank}_1( B_\ell , i ) \cr 6 & \qquad \textbf{else}\ s \gets \mathrm{rank}_0( B_\ell , s );\ i \gets \mathrm{rank}_0( B_\ell , i ) \cr 7 & \quad \textbf{return}\ i - s \end{array}} \]
|
nodiscard |
the place of the \( k \)-th \( c \)
In pseudocode (Claude, Navarro and Ordóñez, beyond the book), down to the start of the items equal to \( c \) at the last level, as rank() does with \( s \), and back up, the ranks of select counted from 1:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{select}( c , k ) \cr 2 & \quad p \gets \text{the place of } c \text{ at the last level} + k - 1 \cr 3 & \quad \textbf{for}\ \ell \gets w - 1\ \textbf{downto}\ 0 \ \textbf{do} \cr 4 & \qquad \textbf{if}\ c_\ell = 1\ \textbf{then}\ p \gets \mathrm{select}_1( B_\ell , p - Z_\ell + 1 )\ \textbf{else}\ p \gets \mathrm{select}_0( B_\ell , p + 1 ) \cr 5 & \quad \textbf{return}\ p \end{array}} \]
|
inlinenodiscard |
the number of items
|
nodiscard |
the bits of the levels and of their directories
|
inlinenodiscard |
the bits of an item
|
staticconstexpr |
the name of the structure in a file [see Persistence.h]