|
ADS
Algorithms and Data Structures
|
The binary fuse filter of Graf and Lemire, beyond the book: a static filter of a set \( S \) of \( n \) keys, built once, which answers maybe for every key of \( S \) and for a key out of \( S \) with probability about \( 2^{-b} \), in about \( 1.13 b \) bits per key for fingerprints of \( b \) bits (8 or 16), against the \( 1.44 b \) of a filter of Bloom with the same false positives [see BloomFilter.h and BlockedBloomFilter.h] and the \( 1.23 b \) of the xor filter, of which it is the successor. More...
#include "ADS/Contract.h"#include "ADS/dictionary/FastHash.h"#include "ADS/external/MappedFile.h"#include <algorithm>#include <array>#include <bit>#include <cmath>#include <cstddef>#include <cstdint>#include <limits>#include <memory>#include <stdexcept>#include <string_view>#include <type_traits>#include <vector>#include "ADS/set/impl/BinaryFuseFilter.tpp"Go to the source code of this file.
Classes | |
| class | ADS::BinaryFuseFilter< T, F, H > |
| a static filter of the keys of type T with fingerprints of type F, 3 places per key in 3 consecutive segments More... | |
Namespaces | |
| namespace | ADS |
The binary fuse filter of Graf and Lemire, beyond the book: a static filter of a set \( S \) of \( n \) keys, built once, which answers maybe for every key of \( S \) and for a key out of \( S \) with probability about \( 2^{-b} \), in about \( 1.13 b \) bits per key for fingerprints of \( b \) bits (8 or 16), against the \( 1.44 b \) of a filter of Bloom with the same false positives [see BloomFilter.h and BlockedBloomFilter.h] and the \( 1.23 b \) of the xor filter, of which it is the successor.
A key with the hash \( h \) has 3 places \( h_0 , h_1 , h_2 \) of an array \( F \) of fingerprints, and is maybe in \( S \) if \( F[ h_0 ] \oplus F[ h_1 ] \oplus F[ h_2 ] = f( h ) \), its fingerprint, the high \( b \) bits of the product of \( h \) by an odd constant, which depend on every bit of \( h \) rather than on the bits that give the places (the false positive rate of \( 2^{-b} \) models them as independent). The array is cut into segments of \( L \) places (a power of 2): \( h_0 \) is a place of the first \( C L \) ones, by a product of \( h \), and \( h_1 \) and \( h_2 \) are in the two segments that follow, at places given by other bits of \( h \), so that the 3 places of a key are within 3 consecutive segments (the spatial coupling that lets the array have only about \( 1.125 n \) places for large \( n \), against \( 1.23 n \) for 3 places anywhere).
The build solves the system of the \( n \) equations by peeling: a place reached by exactly one key is solved last for that key, which is then removed from its other two places, and so on; each place keeps the number of its keys, the XOR of their hashes and the XOR of the indices (0, 1 or 2) by which they reach it, so that a place left with one key tells the hash of that key and which of its places it is, and the peeling touches nothing but these arrays. If every key is peeled, the fingerprints are assigned in the reverse order of the peeling, \( F[ h_i ] = f( h ) \oplus F[ h_{i+1} ] \oplus F[ h_{i+2} ] \), the place \( h_i \) being still free when its key is reached; otherwise (with probability well below \( 1 \% \) for the sizes of the paper) the build draws a new seed. Before the counts, the hashes are sorted by their segment by a counting sort, so that the counts and the peeling walk the arrays in order and stay in the cache. The keys may repeat: a key that occurs twice has twice the same hash, which cannot be peeled, so a build that fails removes the equal hashes before drawing a new seed.
The hash of a key is h( k ), taken as it is if H declares is_avalanching [see FastHash.h] and mixed by hashWord() otherwise; for each seed it is mixed once more by a folded product with the seed. The array has at most \( 2^{32} \) places.
The contracts [see Contract.h]: fewer than \( 2^{31} \) keys; after the build every key is maybe there, an audit. A build that draws 1000 seeds with no success throws std::runtime_error. The operations are defined in BinaryFuseFilter.tpp.