71#ifndef __ADS_HuffmanWaveletTree
72 #define __ADS_HuffmanWaveletTree
110template<
class RS = RankSelect >
151 bool withSelect =
true );
181 template< Executor E >
183 bool withSelect =
true );
186 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
189 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
192 [[nodiscard]] std::size_t
sigma(
void )
const {
return( f_len.size() ); }
196 [[nodiscard]] std::uint32_t
access( std::size_t i )
const;
199 [[nodiscard]] std::uint32_t
operator[]( std::size_t i )
const {
222 [[nodiscard]] std::pair< std::uint32_t , std::size_t >
245 [[nodiscard]] std::size_t
rank( std::uint32_t c , std::size_t i )
const;
251 [[nodiscard]] std::pair< std::size_t , std::size_t >
252 rank( std::uint32_t c , std::size_t i , std::size_t j )
const;
276 [[nodiscard]] std::size_t
select( std::uint32_t c , std::size_t k )
const;
281 return( c < f_len.size() ? f_len[ c ] : 0 );
291 static constexpr std::string_view
persistName =
"HuffmanWaveletTree";
294 [[nodiscard]]
static constexpr std::uint64_t
persistTag(
void ) {
295 return( detail::persistHash( RS::persistName ) );
310 std::uint64_t off = 0 ,
312 std::int32_t child[ 2 ] = { 0 , 0 };
316 void persist( A & a ) {
317 a( off , ones , child );
322 [[nodiscard]]
static RS directory( BitVector b ,
bool withSelect ) {
323 if constexpr( std::is_same_v< RS , RankSelect > )
327 return( RS( std::move( b ) ) );
332 template< Executor E >
333 [[nodiscard]]
static RS directory( E & ex , BitVector b ,
bool withSelect ) {
334 if constexpr( std::is_same_v< RS , RankSelect > )
335 return( RS( ex , std::move( b ) ,
338 else if constexpr( std::is_same_v< RS , CompactRankSelect > )
339 return( RS( ex , std::move( b ) ) );
341 return( directory( std::move( b ) , withSelect ) );
345#ifndef ADS_WAVELET_SLICE
346 static constexpr std::size_t kSlice = std::size_t( 1 ) << 16;
348 static constexpr std::size_t kSlice = ADS_WAVELET_SLICE;
353 void sequential( std::span< const std::uint32_t > x ,
bool withSelect );
357 [[nodiscard]] std::uint64_t layout(
const std::vector< std::uint64_t > & f );
360 [[nodiscard]]
bool bit( std::uint32_t c ,
int d )
const {
361 return( ( f_code[ c ] >> ( f_len[ c ] - 1 - d ) ) & 1 );
365 std::vector< std::uint64_t > f_code;
366 std::vector< std::uint8_t > f_len;
367 std::vector< Node > f_node;
380#include "ADS/succinct/impl/HuffmanWaveletTree.tpp"
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
Rank and select on a static vector of bits of bits in 3.125% of bits more for the rank and less th...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
Rank and select on a static vector of bits of bits with 1s (chapter 15, Compressed Data Structures...
int codeLength(std::uint32_t c) const
the length of the code of , 0 if is not in the sequence
Definition HuffmanWaveletTree.h:280
std::size_t select(std::uint32_t c, std::size_t k) const
the place of the -th occurrence of
std::size_t size(void) const
the number of items
Definition HuffmanWaveletTree.h:186
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,...
std::size_t rank(std::uint32_t c, std::size_t i) const
the occurrences of in
bool empty(void) const
whether there is no item
Definition HuffmanWaveletTree.h:189
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition HuffmanWaveletTree.h:291
HuffmanWaveletTree(void)=default
the empty sequence
static constexpr std::uint64_t persistTag(void)
the directory of the bits, in a file
Definition HuffmanWaveletTree.h:294
std::size_t sigma(void) const
the bound of the symbols, which are below it
Definition HuffmanWaveletTree.h:192
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 in and in , by one descent that moves both places as rank() above moves one
std::pair< std::uint32_t, std::size_t > accessRank(std::size_t i) const
the item and its occurrences in , by one descent
std::uint32_t access(std::size_t i) const
the item , by accessRank()
HuffmanWaveletTree(std::span< const std::uint32_t > x, bool withSelect=true)
the sequence , of symbols below its largest one plus 1, with select if asked for (else the directory ...
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t sizeInBits(void) const
the bits of the tree: its vector with the directory, the nodes and the codes
std::uint32_t operator[](std::size_t i) const
the item , by access()
Definition HuffmanWaveletTree.h:199
@ BOTH
select1() and select0()
Definition RankSelect.h:179
@ NONE
no select, the rank only
Definition RankSelect.h:176