ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
EliasFano.h File Reference

The Elias-Fano representation of a non-decreasing sequence \( x_0 \le \cdots \le x_{n-1} \) of integers in \( [ 0 , u ) \) (chapters 11, Integer Coding, and 15, Compressed Data Structures, of Ferragina's book): each item is split into its \( \ell = \lceil \log_2( u / n ) \rceil \) low bits, written one after the other in \( L \), and its high bits, the bucket \( x_i \gg \ell \), written in \( H \) as the unary counts of the buckets (\( 1^c 0 \) for a bucket of \( c \) items), so that the \( i \)-th 1 of \( H \) is at the place \( ( x_i \gg \ell ) + i \). More...

#include "ADS/Contract.h"
#include "ADS/combinatorial/Bitwise.h"
#include "ADS/succinct/BitVector.h"
#include "ADS/succinct/RankSelect.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <vector>
#include "ADS/succinct/impl/EliasFano.tpp"

Go to the source code of this file.

Classes

class  ADS::BasicEliasFano< Lazy >
 a non-decreasing sequence of integers in the Elias-Fano representation, the inventories of select of \( H \) built in the constructor if not Lazy and at the first select of each value if Lazy [see RankSelect.h] More...

Namespaces

namespace  ADS

Typedefs

using ADS::EliasFano = BasicEliasFano< false >
 Elias-Fano with the inventories of \( H \) built in the constructor, the fastest access() and nextGEQ().
using ADS::LazyEliasFano = BasicEliasFano< true >
 Elias-Fano with the inventories of \( H \) built at the first query that needs them, the fastest construction.

Detailed description

The Elias-Fano representation of a non-decreasing sequence \( x_0 \le \cdots \le x_{n-1} \) of integers in \( [ 0 , u ) \) (chapters 11, Integer Coding, and 15, Compressed Data Structures, of Ferragina's book): each item is split into its \( \ell = \lceil \log_2( u / n ) \rceil \) low bits, written one after the other in \( L \), and its high bits, the bucket \( x_i \gg \ell \), written in \( H \) as the unary counts of the buckets (\( 1^c 0 \) for a bucket of \( c \) items), so that the \( i \)-th 1 of \( H \) is at the place \( ( x_i \gg \ell ) + i \).

\( H \) has \( n \) 1s and at most \( n \) 0s, since \( 2^\ell \ge u / n \), and the sequence takes at most \( 2 n + n \lceil \log_2( u / n ) \rceil \) bits whatever its distribution, within 2 bits per item of the \( \log_2 \binom{u}{n} \) bits needed to tell \( n \) items of \( [ 0 , u ) \) apart.

With rank and select on \( H \) [see RankSelect.h] the sequence is not only decoded but searched in place:

  • access( i ), \( x_i \) in \( O( 1 ) \) time, as \( \mathrm{select}_1( i + 1 ) - i \) followed by the \( i \)-th field of \( L \);
  • nextGEQ( x ), the place of the first item \( \ge x \), which is the rank of \( x \) (the items \( < x \)) and gives the predecessor and the successor: \( \mathrm{select}_0 \) of the bucket of \( x \) gives the first item of that bucket, and the scan stops at its end, in \( O( 1 + c ) \) time for a bucket of \( c \) items, expected \( O( 1 ) \) since \( 2^\ell \approx u / n \); past 8 items (the clusters of a sequence fill some buckets) the end of the bucket is found by \( \mathrm{select}_0 \) too and its low bits, sorted, by a binary search, \( O( \log c ) \) time;
  • viewed as the places of the 1s of a vector of bits \( B \) of \( u \) bits with \( n \) 1s (as in chapter 15, Compressed Data Structures, of Ferragina's book), access( i ) is \( \mathrm{select}_1( i + 1 ) \) of \( B \) and nextGEQ( i ) is \( \mathrm{rank}_1( i ) \) of \( B \), in \( n ( 2 + \log( u / n ) ) + o( n ) \) bits rather than \( u + o( u ) \).

Ferragina's book computes the rank of \( B \) by a binary search on the select, in \( O( \log n ) \) time; the bucket found by \( \mathrm{select}_0 \) makes it \( O( 1 ) \) expected, the design of the quasi-succinct indices of Vigna and of the sdarray of Okanohara and Sadakane. \( H \) is written with the 1s for the items and the 0s for the buckets, as in its chapter 11 (its chapter 15 swaps them, which only swaps \( \mathrm{select}_0 \) and \( \mathrm{select}_1 \)). The representation ignores the regularities of the sequence: the partitioned Elias-Fano of Ottaviano and Venturini [see PartitionedEliasFano.h] splits it into chunks, each one coded at its own best, and comes within a few percent of the interpolative code [see IntegerCodes.h] keeping the random access.

The contracts [see Contract.h]: the sequence is non-decreasing (an audit) and below \( u \), and access() needs \( i < n \); the audit of the construction is that access() gives back each item, and the postcondition of nextGEQ() is that the items before the place are \( < x \) and the one at it is not. The functions are defined in EliasFano.tpp.

See also
P. Ferragina, Pearls of Algorithm Engineering, Cambridge University Press, 2023, chapters 11, Integer Coding, and 15, Compressed Data Structures, doi:10.1017/9781009128933
P. Elias, Efficient storage and retrieval by content and address of static files, Journal of the ACM 21(2), 246-260, 1974, doi:10.1145/321812.321820
R. M. Fano, On the number of bits required to implement an associative memory, Memorandum 61, Computation Structures Group, MIT, 1971
D. Okanohara, K. Sadakane, Practical entropy-compressed rank/select dictionary, Proc. 9th ALENEX, 60-70, 2007, doi:10.1137/1.9781611972870.6
S. Vigna, Quasi-succinct indices, Proc. 6th WSDM, 83-92, 2013, doi:10.1145/2433396.2433409
G. Ottaviano, R. Venturini, Partitioned Elias-Fano indexes, Proc. 37th SIGIR, 273-282, 2014, doi:10.1145/2600428.2609615
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa