|
ADS
Algorithms and Data Structures
|
The wavelet matrix of Claude, Navarro and Ordóñez: a static sequence \( S[ 0 .. n - 1 ] \) of integers of \( w \) bits, i.e., on the alphabet \( [ 0 , 2^w ) \), in \( n w \) bits plus the directories of rank and select [see RankSelect.h], with access, rank and select of any symbol in \( O( w ) \) time, and the queries on a range of places that a sequence of integers needs (the \( k \)-th smallest item of a range, the items below a value), also in \( O( w ) \) time. More...
#include "ADS/Contract.h"#include "ADS/parallel/Executor.h"#include "ADS/succinct/BitVector.h"#include "ADS/succinct/RankSelect.h"#include <algorithm>#include <bit>#include <cstddef>#include <cstdint>#include <memory>#include <span>#include <string_view>#include <type_traits>#include <utility>#include <vector>#include "ADS/succinct/impl/WaveletMatrix.tpp"Go to the source code of this file.
Classes | |
| class | ADS::WaveletMatrix |
| a static sequence of integers of \( w \) bits with access, rank, select and the range quantiles in \( O( w ) \) time More... | |
Namespaces | |
| namespace | ADS |
The wavelet matrix of Claude, Navarro and Ordóñez: a static sequence \( S[ 0 .. n - 1 ] \) of integers of \( w \) bits, i.e., on the alphabet \( [ 0 , 2^w ) \), in \( n w \) bits plus the directories of rank and select [see RankSelect.h], with access, rank and select of any symbol in \( O( w ) \) time, and the queries on a range of places that a sequence of integers needs (the \( k \)-th smallest item of a range, the items below a value), also in \( O( w ) \) time.
The level \( \ell = 0 , \ldots , w - 1 \) is a vector of bits \( B_\ell \) that holds the bit \( w - 1 - \ell \) (from the most significant one) of each item, in the order that the levels above leave: \( B_0 \) is in the order of \( S \), and the items go to the next level stably sorted by the bit, the \( Z_\ell \) ones with a 0 first and those with a 1 after them. Hence the item at the place \( i \) of a level is at the place \( \mathrm{rank}_0( i ) \) of the next one if its bit is 0, and at \( Z_\ell + \mathrm{rank}_1( i ) \) if it is 1, and the items equal to \( c \), in the order of \( S \), are consecutive at the last level, at a place that the bits of \( c \) alone determine:
Unlike the wavelet tree of Grossi, Gupta and Vitter, whose nodes split the alphabet in halves and need a pointer or an offset each, the matrix keeps one vector of \( n \) bits per level and no tree, at the same costs: it is the form of choice for the large alphabets (Claude, Navarro and Ordóñez), and the base of the compressed indices of the integers and of the r-index. A wavelet tree shaped by the code of Huffman (Mäkinen and Navarro) takes \( n ( H_0 + 1 ) \) bits instead of \( n w \) and is faster on a skewed alphabet [see HuffmanWaveletTree.h]; the matrix here is the form for the alphabets of integers with no known distribution. Each level carries the directory of RankSelect [see RankSelect.h], so that the matrix takes about \( 1.5 \, n w \) bits, and a query of rank \( 2 w \) ranks of one load and one sideways sum each.
The contracts [see Contract.h]: the items fit in \( w \) bits, \( 1 \le w \le 64 \), the places are in the sequence, \( i \le j \) for a range, and \( k \) counts from 1 for select and from 0 for the quantile, below the number of the items; the audit of the construction is that access() gives back each item. The functions are defined in WaveletMatrix.tpp.