a static sequence of symbols in about \( H_0 + 1 \) bits each, with access, rank and select in time proportional to the length of a code; RS is the rank and select of its bits, RankSelect or CompactRankSelect
More...
#include <ADS/succinct/HuffmanWaveletTree.h>
|
| | HuffmanWaveletTree (void)=default |
| | the empty sequence
|
| | HuffmanWaveletTree (std::span< const std::uint32_t > x, bool withSelect=true) |
| | the sequence \( x \), of symbols below its largest one plus 1, with select if asked for (else the directory of RankSelect keeps no inventory)
|
| template<Executor E> |
| | HuffmanWaveletTree (E &ex, std::span< const std::uint32_t > x, bool withSelect=true) |
| | the tree of HuffmanWaveletTree( x , withSelect ) above, the same codes, nodes and bits, built on the threads of the executor ex (see Parallel construction)
|
| std::size_t | size (void) const |
| | the number of items
|
| bool | empty (void) const |
| | whether there is no item
|
| std::size_t | sigma (void) const |
| | the bound of the symbols, which are below it
|
| std::uint32_t | access (std::size_t i) const |
| | the item \( i \), by accessRank()
|
| std::uint32_t | operator[] (std::size_t i) const |
| | the item \( i \), by access()
|
| std::pair< std::uint32_t, std::size_t > | accessRank (std::size_t i) const |
| | the item \( i \) and its occurrences in \( [ 0 , i ) \), by one descent
|
| std::size_t | rank (std::uint32_t c, std::size_t i) const |
| | the occurrences of \( c \) in \( [ 0 , i ) \)
|
| std::pair< std::size_t, std::size_t > | rank (std::uint32_t c, std::size_t i, std::size_t j) const |
| | the occurrences of \( c \) in \( [ 0 , i ) \) and in \( [ 0 , j ) \), by one descent that moves both places as rank() above moves one
|
| std::size_t | select (std::uint32_t c, std::size_t k) const |
| | the place of the \( k \)-th occurrence of \( c \)
|
| int | codeLength (std::uint32_t c) const |
| | the length of the code of \( c \), 0 if \( c \) is not in the sequence
|
| std::size_t | sizeInBits (void) const |
| | the bits of the tree: its vector with the directory, the nodes and the codes
|
| 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 directory of the bits, in a file
|
|
| static constexpr std::string_view | persistName = "HuffmanWaveletTree" |
| | the name of the structure in a file [see Persistence.h]
|
template<class RS = RankSelect>
class ADS::HuffmanWaveletTree< RS >
a static sequence of symbols in about \( H_0 + 1 \) bits each, with access, rank and select in time proportional to the length of a code; RS is the rank and select of its bits, RankSelect or CompactRankSelect
◆ HuffmanWaveletTree() [1/3]
template<class RS = RankSelect>
◆ HuffmanWaveletTree() [2/3]
template<class RS = RankSelect>
the sequence \( x \), of symbols below its largest one plus 1, with select if asked for (else the directory of RankSelect keeps no inventory)
In pseudocode (Mäkinen and Navarro, beyond the book), the lengths of Huffman by the two queues of the sorted leaves and of the internal nodes, which are made in increasing weight:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{build}( x ) \cr
2 & \quad f_c \gets \text{the occurrences of each } c \text{ in } x;
\ \text{sort the symbols present by } f_c \cr
3 & \quad \textbf{repeat}\ \text{join the two lightest of the fronts of}
\text{ the two queues into a node at the tail of the second} \cr
4 & \quad \textbf{until}\ \text{one node is left};\ \ell_c \gets
\text{the depth of the leaf of } c \cr
5 & \quad \text{give the canonical codes, by length and then by symbol}
\cr
6 & \quad \text{build the trie of the codes};\ \mathit{items}[ v ] \gets
\text{the items whose code passes by } v \cr
7 & \quad \text{lay the nodes in } B \text{ by levels: } o_v \gets
\text{the sum of } \mathit{items} \text{ of the nodes before} \cr
8 & \quad \textbf{foreach}\ c \in x \text{, in order}\ \textbf{do} \cr
9 & \qquad \textbf{foreach}\ \text{node } v \text{ on the code of } c
\text{ and its bit } b \text{ there}\ \textbf{do} \cr
10 & \qquad\quad B[ \mathit{at}[ v ] ] \gets b;\ \mathit{at}[ v ] \gets
\mathit{at}[ v ] + 1 \cr
11 & \quad R_v \gets \mathrm{rank}_1( B , o_v ) \text{ for each node } v
\end{array}}
\]
- Precondition
- \( |x| < 2^{40} \)
◆ HuffmanWaveletTree() [3/3]
template<class RS = RankSelect>
template<Executor E>
| ADS::HuffmanWaveletTree< RS >::HuffmanWaveletTree |
( |
E & | ex, |
|
|
std::span< const std::uint32_t > | x, |
|
|
bool | withSelect = true ) |
the tree of HuffmanWaveletTree( x , withSelect ) above, the same codes, nodes and bits, built on the threads of the executor ex (see Parallel construction)
In pseudocode (the runs of the slices in the nodes, beyond the book), \( x \) cut into slices \( X_0 , \ldots , X_{q-1} \) of at least \( \sigma \) items:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{build}( \mathit{ex} , x ) \cr
2 & \quad \textbf{foreach}\ \text{slice } X_s\ \textbf{do in parallel}
\ h_s[ c ] \gets \text{the occurrences of each } c \text{ in } X_s
\cr
3 & \quad f_c \gets \sum_s h_s[ c ];\ \text{the codes, the trie and }
\text{the places } o_v \text{ as in } \mathrm{build}( x ) \cr
4 & \quad \mathit{at}_s[ v ] \gets o_v + \text{the items through } v
\text{ in the slices before } X_s \text{, by the } h \cr
5 & \quad \textbf{foreach}\ \text{slice } X_s\ \textbf{do in parallel}
\cr
6 & \qquad \textbf{foreach}\ c \in X_s \text{ in order and node } v
\text{ on the code of } c \text{, with its bit } b\ \textbf{do} \cr
7 & \qquad\quad B[ \mathit{at}_s[ v ] ] \gets b;\ \mathit{at}_s[ v ]
\gets \mathit{at}_s[ v ] + 1 \cr
8 & \quad \text{the directory of } B \text{ on } \mathit{ex};\ R_v
\gets \mathrm{rank}_1( B , o_v ) \text{ for each node } v
\end{array}}
\]
- Precondition
- \( |x| < 2^{40} \)
◆ access()
template<class RS = RankSelect>
the item \( i \), by accessRank()
- Precondition
- \( i < \mathrm{size}() \)
◆ accessRank()
template<class RS = RankSelect>
the item \( i \) and its occurrences in \( [ 0 , i ) \), by one descent
In pseudocode (Mäkinen and Navarro, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{accessRank}( i ) \cr
2 & \quad v \gets \text{the root} \cr
3 & \quad \textbf{loop} \cr
4 & \qquad b \gets B[ o_v + i ];\ r \gets \mathrm{rank}_1( B , o_v + i )
- R_v \cr
5 & \qquad \textbf{if}\ b = 1\ \textbf{then}\ i \gets r\ \textbf{else}
\ i \gets i - r \cr
6 & \qquad \textbf{if}\ \text{the child } b \text{ of } v \text{ is the}
\text{ leaf of } c\ \textbf{then return}\ ( c , i ) \cr
7 & \qquad v \gets \text{the child } b \text{ of } v
\end{array}}
\]
- Precondition
- \( i < \mathrm{size}() \)
◆ codeLength()
template<class RS = RankSelect>
the length of the code of \( c \), 0 if \( c \) is not in the sequence
◆ empty()
template<class RS = RankSelect>
◆ operator[]()
template<class RS = RankSelect>
◆ persist()
template<class RS = RankSelect>
template<class A>
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistTag()
template<class RS = RankSelect>
|
|
inlinestaticnodiscardconstexpr |
the directory of the bits, in a file
◆ rank() [1/2]
template<class RS = RankSelect>
the occurrences of \( c \) in \( [ 0 , i ) \)
In pseudocode (Mäkinen and Navarro, beyond the book), along the code \( b_0 \cdots b_{\ell_c - 1} \) of \( c \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{rank}( c , i ) \cr
2 & \quad \textbf{if}\ c \text{ is not in the sequence }\ \textbf{then
return}\ 0 \cr
3 & \quad v \gets \text{the root} \cr
4 & \quad \textbf{for}\ d \gets 0\ \textbf{to}\ \ell_c - 1\ \textbf{do}
\cr
5 & \qquad r \gets \mathrm{rank}_1( B , o_v + i ) - R_v \cr
6 & \qquad \textbf{if}\ b_d = 1\ \textbf{then}\ i \gets r
\ \textbf{else}\ i \gets i - r \cr
7 & \qquad v \gets \text{the child } b_d \text{ of } v \cr
8 & \quad \textbf{return}\ i
\end{array}}
\]
- Precondition
- \( i \le \mathrm{size}() \)
◆ rank() [2/2]
template<class RS = RankSelect>
| std::pair< std::size_t, std::size_t > ADS::HuffmanWaveletTree< RS >::rank |
( |
std::uint32_t | c, |
|
|
std::size_t | i, |
|
|
std::size_t | j ) const |
|
nodiscard |
the occurrences of \( c \) in \( [ 0 , i ) \) and in \( [ 0 , j ) \), by one descent that moves both places as rank() above moves one
- Precondition
- \( i \le j \le \mathrm{size}() \)
◆ select()
template<class RS = RankSelect>
the place of the \( k \)-th occurrence of \( c \)
In pseudocode (Mäkinen and Navarro, beyond the book), up from the leaf of \( c \), the ranks of select counted from 1:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{select}( c , k ) \cr
2 & \quad v_0 , \ldots , v_{\ell_c - 1} \gets \text{the nodes on the }
\text{code } b_0 \cdots b_{\ell_c - 1} \text{ of } c \cr
3 & \quad \textbf{for}\ d \gets \ell_c - 1\ \textbf{downto}\ 0
\ \textbf{do} \cr
4 & \qquad \textbf{if}\ b_d = 1\ \textbf{then}\ p \gets
\mathrm{select}_1( B , R_{v_d} + k ) \cr
5 & \qquad \textbf{else}\ p \gets \mathrm{select}_0( B , o_{v_d} -
R_{v_d} + k ) \cr
6 & \qquad k \gets p - o_{v_d} + 1 \cr
7 & \quad \textbf{return}\ k - 1
\end{array}}
\]
- Precondition
- \( 1 \le k \le \mathrm{rank}( c , \mathrm{size}() ) \), and select was asked for
- Postcondition
- the item at the place is \( c \)
◆ sigma()
template<class RS = RankSelect>
the bound of the symbols, which are below it
◆ size()
template<class RS = RankSelect>
◆ sizeInBits()
template<class RS = RankSelect>
the bits of the tree: its vector with the directory, the nodes and the codes
◆ persistName
template<class RS = RankSelect>
The documentation for this class was generated from the following file: