|
ADS
Algorithms and Data Structures
|
The directly addressable codes of Brisaboa, Ladra and Navarro (DACs): a sequence \( x_0 , \ldots , x_{n-1} \) of integers of variable length in little more than the bits of their binary codes, with access to any item in time proportional to its length rather than to its place, which the codes of the integers [see IntegerCodes.h] read one after the other do not give. More...
#include "ADS/Contract.h"#include "ADS/succinct/BitVector.h"#include "ADS/succinct/RankSelect.h"#include <array>#include <bit>#include <cstddef>#include <cstdint>#include <cstring>#include <span>#include <vector>#include "ADS/compression/impl/DirectAccessCodes.tpp"Go to the source code of this file.
Classes | |
| class | ADS::DirectAccessCodes |
| a static sequence of integers of variable length with direct access More... | |
Namespaces | |
| namespace | ADS |
The directly addressable codes of Brisaboa, Ladra and Navarro (DACs): a sequence \( x_0 , \ldots , x_{n-1} \) of integers of variable length in little more than the bits of their binary codes, with access to any item in time proportional to its length rather than to its place, which the codes of the integers [see IntegerCodes.h] read one after the other do not give.
The bits of an integer are cut into chunks, the low \( b_0 \) bits, the next \( b_1 \) and so on; the level \( \ell \) holds, for each integer that has bits beyond the first \( s_\ell = b_0 + \cdots + b_{\ell - 1} \), its chunk \( \ell \) in \( b_\ell \) bits, in an array \( A_\ell \) of fixed width, and a bit of \( B_\ell \) telling whether it continues past the level (none on the last level). The integer of place \( i \) at a level is at the place \( \mathrm{rank}_1( B_\ell , i ) \) of the next one, among those that continue [see RankSelect.h, with no select], so that
\[ x_i = \sum_{\ell} A_\ell[ i_\ell ] \, 2^{s_\ell} , \quad i_0 = i , \quad i_{\ell + 1} = \mathrm{rank}_1( B_\ell , i_\ell ) , \]
over the levels that it reaches: \( O( 1 + \text{the levels of } x_i ) \) time. With \( n_k \) the integers of more than \( k \) bits (\( n_0 = n \)), the level of the chunk \( [ s , s + b ) \) costs \( n_s ( b + 1 ) \) bits (\( n_s b \) on the last), plus 25% of the continuation bits for their ranks (one load and one sideways sum), and the widths \( b_0 , b_1 , \ldots \) that minimize the sum are found by the dynamic program of the authors over the places of a cut,
\[ C( s ) = \min_{s < s' \le w} \big( n_s ( s' - s ) + [ s' < w ] \, n_s ( 1 + 0.25 ) + C( s' ) \big) , \quad C( w ) = 0 , \]
\( w \) the bits of the largest integer, in \( O( w^2 ) \) steps on the counts \( n_s \). Each level past the first costs an access a rank and a branch on its continuation bit, which is hard to predict, and the optimum often takes many levels of 1 or 2 bits; so the program is by default bounded to \( h = 3 \) levels, \( C_h( s ) \) the least cost from \( s \) in at most \( h \) levels,
\[ C_1( s ) = n_s ( w - s ) , \quad C_h( s ) = \min\big( C_1( s ) , \min_{s < s' < w} \big( n_s ( s' - s + 1.25 ) + C_{h - 1}( s' ) \big) \big) , \]
in \( O( h w^2 ) \) steps, a few bits more for a bounded worst case of the access, as the authors propose; Levels::UNCAPPED asks for the unbounded program. A fixed width \( b \) for every level trades bits for fewer levels, i.e., fewer ranks per access. A chunk of 8 or 16 bits is read as its byte or its pair of bytes, one load that stays in its line of the cache. The construction packs the chunks and the continuation bits of a level in order, a field of 64 bits at a time. The chunks of one width are a code with a fixed alphabet, the variable-byte code of chapter 11, Integer Coding, of Ferragina's book when every \( b_\ell = 7 \), the continuation bits moved to their own vector with rank.
The contracts [see Contract.h]: the places asked for are in the sequence; the audit of the construction is that access() gives back each item. The functions are defined in DirectAccessCodes.tpp.