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

The range filters of Costa, Ferragina and Vinciguerra, beyond the book: GrafiteFilter, a static filter of a set \( S \) of \( n \) keys that tells whether a range \( [ a , b ] \) of the universe may hold a key of \( S \) with a false positive probability that depends only on the length of the range, whatever the keys and the queries (adversarial ones included), and BucketingFilter, the heuristic of the same paper, faster and with no such guarantee. More...

#include "ADS/Contract.h"
#include "ADS/dictionary/FastHash.h"
#include "ADS/external/MappedFile.h"
#include "ADS/sort/RadixSort.h"
#include "ADS/succinct/EliasFano.h"
#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <vector>
#include "ADS/set/impl/GrafiteFilter.tpp"

Go to the source code of this file.

Classes

class  ADS::GrafiteFilter< T >
 a static range filter of the keys of type T, \( B \) bits per key, with false positive probability at most \( \ell / 2^{B-2} \) for a range of \( \ell \) keys, whatever the keys and the range More...
class  ADS::BucketingFilter< T >
 a static range filter of the keys of type T, \( B \) bits per key: the buckets of \( 2^w / ( n \, 2^{B-2} ) \) keys that hold a key of the set, \( w \) the bits of T, with no bound on the false positives of the queries near a key More...

Namespaces

namespace  ADS

Detailed description

The range filters of Costa, Ferragina and Vinciguerra, beyond the book: GrafiteFilter, a static filter of a set \( S \) of \( n \) keys that tells whether a range \( [ a , b ] \) of the universe may hold a key of \( S \) with a false positive probability that depends only on the length of the range, whatever the keys and the queries (adversarial ones included), and BucketingFilter, the heuristic of the same paper, faster and with no such guarantee.

Both answer the queries of a point too, as the range \( [ x , x ] \).

A range filter answers true for every range that holds a key of \( S \) (no false negatives), and for an empty range of length \( \ell = b - a + 1 \) with probability \( \varepsilon( \ell ) \), the false positive probability. The filters of points (Bloom, binary fuse, Ribbon, cuckoo [see BloomFilter.h, BinaryFuseFilter.h, RibbonFilter.h, CuckooFilter.h]) answer a range only by asking each of its \( \ell \) points, which costs \( \ell \) queries and \( \ell \) times their false positive probability; the tries of SuRF, the filters of prefixes of Rosetta and the learned models of SNARF and Proteus answer a range in fewer steps, but a query close to a key, which the workloads of a key-value store often ask (a correlated query), finds them unable to tell the range from the key, and their false positives go to 1 (Oasis, a learned filter of segments, shares the weakness). Grafite is the filter whose guarantee holds for every query, within 2 bits per key of the lower bound; the robust filters after it, Memento and Diva, keep a similar guarantee while they take insertions and keys of any length, at the price of more bits and slower queries, so that for a static set of keys of 64 bits Grafite remains the choice.

With \( B \) bits per key, Grafite reduces the universe \( [ 0 , 2^{64} ) \) to \( [ 0 , r ) \), \( r = n \, 2^{B-2} \), by the hash

\[ h( x ) = \bigl( q( \lfloor x / r \rfloor ) + x \bigr) \bmod r , \]

with \( q \) a hash of the blocks \( \lfloor x / r \rfloor \) of \( r \) consecutive keys into \( [ 0 , r ) \), drawn from a pairwise independent family: inside a block, \( h \) is the rotation of the keys by \( q \) of the block, so that the keys of a range in one block go to a range of \( [ 0 , r ) \) of the same length, cyclically (the locality), while the blocks are rotated independently of each other. The codes \( h( S ) \), sorted and without repetitions, are kept by Elias-Fano [see EliasFano.h] in the universe \( r \), in \( n ( 2 + \lceil \log_2( r / n ) \rceil ) = n B \) bits and the directory of select, and a range \( [ a , b ] \) with \( b - a < r \) meets at most two blocks, whose images are at most two cyclic ranges of \( [ 0 , r ) \) of \( \ell \) codes in all: the answer is whether a code lies in them, one nextGEQ() and one access() each, in \( O( 1 ) \) time for a constant \( B \). By the argument on the theory page of the area (Theorem 3.4 and Corollary 3.5 of the paper, which generalize the construction of Goswami, Grønlund, Larsen and Pagh),

\[ \varepsilon( \ell ) \le \min\Bigl( 1 , \frac{ n \ell }{ r } \Bigr) = \min\Bigl( 1 , \frac{ \ell }{ 2^{B-2} } \Bigr) , \]

whatever \( S \) and the range, since the only randomness is that of \( q \); the lower bound of the same paper needs \( n \log_2( \ell / \varepsilon ) - O( n ) \) bits, within 2 bits per key of Grafite. A range with \( b - a \ge r \) has \( n \ell / r \ge 1 \), and the filter answers true if \( S \) is not empty. The paper gives \( r \) as \( n L / \varepsilon \) for the ranges of length at most \( L \) and the probability \( \varepsilon \): with \( B \) bits per key this is \( \varepsilon = L / 2^{B-2} \), so that \( L \) need not be fixed in advance.

The hash \( q \) here is the multiply-add-shift of Dietzfelbinger, on 128 bits, \( q'( j ) = \lfloor ( \alpha j + \beta ) \bmod 2^{128} / 2^{64} \rfloor \) with \( \alpha , \beta \) random words of 128 bits from the seed, pairwise independent from the words of 64 bits to those of 64 bits (the Carter-Wegman hash modulo a prime of the paper needs a prime above the \( 2^{64} / r \) blocks), mapped onto \( [ 0 , r ) \) by \( q( j ) = \lfloor q'( j ) \, r / 2^{64} \rfloor \), whose values have probabilities within \( 1 / r \pm 2^{-64} \), which adds at most \( n \ell 2^{-64} \) to \( \varepsilon( \ell ) \).

BucketingFilter cuts the universe into buckets of \( s \) keys, \( s = \lceil 2^{64} / ( n \, 2^{B-2} ) \rceil \), and keeps by Elias-Fano the buckets \( \lfloor x / s \rfloor \) that hold a key, in at most \( B \) bits per key; \( [ a , b ] \) may hold a key if a kept bucket is in \( [ \lfloor a / s \rfloor , \lfloor b / s \rfloor ] \), one nextGEQ() and one access(). A query whose range is out of the buckets of \( S \) is answered right, and on keys and queries drawn independently at random from the universe a range of \( \ell \) keys, which meets at most \( \ell / s + 2 \) buckets, each kept with probability at most about \( n s / 2^{64} \approx 2^{-(B-2)} \), is a false positive with probability at most about \( ( \ell / s + 2 ) \, 2^{-(B-2)} \); the filter is also faster to build and to query than Grafite (no hash); but a query that falls in the bucket of a key without holding it (a correlated query, at distance below \( s \) from the key) is always a false positive: there is no bound that holds for every query.

The keys are of a type T that radixKey() maps in order onto unsigned words [see RadixSort.h]: integers and floating point numbers, whose ranges are those of their order (-0 and +0 are two keys, -0 the smaller, as the total order of IEEE 754 has them).

The contracts [see Contract.h]: \( 2 \le B \le 40 \) and \( n \, 2^{B-2} < 2^{63} \); a range has \( a \le b \); after the build every key may be there, an audit. The operations are defined in GrafiteFilter.tpp.

See also
M. Costa, P. Ferragina, G. Vinciguerra, Grafite: taming adversarial queries with optimal range filters, Proceedings of the ACM on Management of Data 2(1), 1-23, 2024, doi:10.1145/3639258
M. Goswami, A. Grønlund, K. G. Larsen, R. Pagh, Approximate range emptiness in constant time and optimal space, Proceedings of the 26th ACM-SIAM Symposium on Discrete Algorithms (SODA), 769-775, 2015, doi:10.1137/1.9781611973730.52
M. Dietzfelbinger, Universal hashing and k-wise independent random variables via integer arithmetic without primes, Proceedings of STACS 96, LNCS 1046, 567-580, 1996, doi:10.1007/3-540-60922-9_46
M. N. Wegman, J. L. Carter, New hash functions and their use in authentication and set equality, Journal of Computer and System Sciences 22(3), 265-279, 1981, doi:10.1016/0022-0000(81)90033-7
H. Zhang, H. Lim, V. Leis, D. G. Andersen, M. Kaminsky, K. Keeton, A. Pavlo, SuRF: practical range query filtering with fast succinct tries, Proceedings of SIGMOD 2018, 323-336, 2018, doi:10.1145/3183713.3196931
S. Luo, S. Chatterjee, R. Ketsetsidis, N. Dayan, W. Qin, S. Idreos, Rosetta: a robust space-time optimized range filter for key-value stores, Proceedings of SIGMOD 2020, 2071-2086, 2020, doi:10.1145/3318464.3389731
K. Vaidya, S. Chatterjee, E. Knorr, M. Mitzenmacher, S. Idreos, T. Kraska, SNARF: a learning-enhanced range filter, Proceedings of the VLDB Endowment 15(8), 1632-1644, 2022, doi:10.14778/3529337.3529347
E. R. Knorr, B. Lemaire, A. Lim, S. Luo, H. Zhang, S. Idreos, M. Mitzenmacher, Proteus: a self-designing range filter, Proceedings of SIGMOD 2022, 1670-1684, 2022, doi:10.1145/3514221.3526167
N. Eslami, N. Dayan, Memento filter: a fast, dynamic, and robust range filter, Proceedings of the ACM on Management of Data 2(6), 244, 1-27, 2024, doi:10.1145/3698820
G. Chen, Z. He, M. Li, S. Luo, Oasis: an optimal disjoint segmented learned range filter, Proceedings of the VLDB Endowment 17(8), 1911-1924, 2024, doi:10.14778/3659437.3659447
N. Eslami, I. O. Bercea, N. Dayan, Diva: dynamic range filter for var-length keys and queries, Proceedings of the VLDB Endowment 18(11), 3923-3936, 2025, doi:10.14778/3749646.3749664
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa