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

Rank and select on a static vector of bits \( B \) of \( m \) bits with the counts inside the lines of the bits, the layout of SPIDER of Laws, Bliven, Conklin, Laalai, McCauley and Sturdevant: a line of the cache of 512 bits holds 496 bits of \( B \) and, in its first 16 bits, the 1s before it since its superblock of 128 lines (63488 bits, so that the count fits), and a superblock keeps the 1s before it in 64 bits apart. More...

#include "ADS/Contract.h"
#include "ADS/external/MappedFile.h"
#include "ADS/succinct/BitVector.h"
#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string_view>
#include <vector>
#include "ADS/succinct/impl/InterleavedRankSelect.tpp"

Go to the source code of this file.

Classes

class  ADS::InterleavedRankSelect
 a static vector of bits with its counts inside its lines, rank with one access to the memory More...

Namespaces

namespace  ADS

Detailed description

Rank and select on a static vector of bits \( B \) of \( m \) bits with the counts inside the lines of the bits, the layout of SPIDER of Laws, Bliven, Conklin, Laalai, McCauley and Sturdevant: a line of the cache of 512 bits holds 496 bits of \( B \) and, in its first 16 bits, the 1s before it since its superblock of 128 lines (63488 bits, so that the count fits), and a superblock keeps the 1s before it in 64 bits apart.

Hence

\[ \mathrm{rank}_1( i ) = S[ \lfloor \ell / 128 \rfloor ] + h_\ell + | B_\ell [ 0 , i \bmod 496 ) | , \qquad \ell = \lfloor i / 496 \rfloor , \]

\( h_\ell \) the count of the line \( \ell \), \( B_\ell \) its bits and \( | \cdot | \) the number of 1s, with one access to the memory of the vector, the line, against two of the directories kept apart [see RankSelect.h, CompactRankSelect.h] (the array of the superblocks, 1 word per 63488 bits, stays in the caches); the sum of the line is that of CompactRankSelect, the kernel detail::lineRank() of BitVector.h (32 bytes at a time by a table of the nibbles with AVX2). The counts take \( 16 / 512 = 3.125 \% \) of the line.

The select keeps the line of every 8192-th bit \( b \) with the bits \( b \) before that line (96 bits each, at most \( 96 / 8192 < 1.2 \% \) of \( m \) bits for each value) and guesses the line of the \( k \)-th bit \( b \) between two samples by interpolation, as SPIDER does,

\[ \hat\ell = \ell_j + \frac{ ( k - 1 - c_j ) ( \ell_{j+1} - \ell_j ) } { c_{j+1} - c_j } , \]

\( c_j \) the bits \( b \) before the line \( \ell_j \), corrects the guess a line at a time by the counts of the lines (a step or two where the bits \( b \) are spread evenly, \( \ell_{j+1} - \ell_j \) in the worst case), and ends in the line by the sums of its words and selectInWord() [see BitVector.h].

The contracts [see Contract.h]: \( i \le m \) for the rank and \( 1 \le k \) up to the number of the bits \( b \) for the select; the postconditions are that the bit at \( \mathrm{select}_b( k ) \) is \( b \) and that its rank is \( k - 1 \), and the audit of the construction is that the counts agree with a scan. The functions are defined in InterleavedRankSelect.tpp.

See also
M. D. Laws, J. Bliven, K. Conklin, E. Laalai, S. McCauley, Z. S. Sturdevant, SPIDER: improved succinct rank and select performance, Proc. 22nd SEA, LIPIcs 301, 21, 2024, doi:10.4230/LIPIcs.SEA.2024.21
F. Kurpicz, Engineering compact data structures for rank and select queries on bit vectors, Proc. 29th SPIRE, LNCS 13617, 257-272, 2022, doi:10.1007/978-3-031-20643-6_19
W. Mula, N. Kurz, D. Lemire, Faster population counts using AVX2 instructions, The Computer Journal 61(1), 111-120, 2018, doi:10.1093/comjnl/bxx046
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa