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

The variants and the analysis of the filter of Bloom [see BloomFilter.h for the standard one], beyond the book: More...

#include "ADS/Contract.h"
#include "ADS/dictionary/RandomHashing.h"
#include "ADS/external/MappedFile.h"
#include "ADS/set/BloomFilter.h"
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <limits>
#include <string_view>
#include <unordered_set>
#include <utility>
#include <vector>
#include "ADS/set/impl/BloomVariants.tpp"

Go to the source code of this file.

Classes

class  ADS::SpectralBloomFilter< T, C, H >
 a filter of Bloom of \( m \) counters of the type C and \( r \) hashes, for multisets More...
class  ADS::PartitionedBloomFilter< T, H >
 a filter of Bloom of \( r \) parts of \( m / r \) bits, a hash for each part More...

Namespaces

namespace  ADS

Functions

double ADS::bloomFalsePositive (double m, double n, int r)
 the probability \( ( 1 - ( 1 - 1 / m )^{r n} )^r \) of a false positive of a filter of \( m \) bits and \( r \) hashes after \( n \) insertions, 0 for \( n = 0 \)
int ADS::bloomBestHashes (double m, double n)
 the number of hashes, the floor or the ceiling of \( ( m / n ) \ln 2 \), of the least false positives; past the largest int (\( m / n \) above about \( 3 \cdot 10^9 \)) the floor is cut to the largest int less one
double ADS::bloomLowerBound (double n, double epsilon)
 \( n \log_2( 1 / \epsilon ) \), the bits that any filter of \( n \) keys with false positives \( \epsilon \) needs
double ADS::bloomBits (double n, double epsilon)
 \( n \log_2( 1 / \epsilon ) / \ln 2 \), the bits of a filter of Bloom with the best number of hashes and false positives \( \epsilon \)
std::pair< double, double > ADS::compressedBloom (double bitsPerKey, int r)
 the false positives and the bits per key after an arithmetic coding, \( m / n \) times the entropy of a bit, of a filter of \( m / n = \mathit{bitsPerKey} \) bits per key and \( r \) hashes
template<class T, class H = std::hash< T >>
std::pair< std::vector< T >, std::vector< T > > ADS::bloomIntersection (const std::vector< T > &A, const std::vector< T > &B, std::size_t mA)
 the intersection of \( A \) and \( B \) by a filter of \( A \) of \( m_A \) bits: the keys \( Q \) of \( B \) that the filter accepts, and the keys of \( A \) in \( Q \), in the order of \( B \)

Detailed description

The variants and the analysis of the filter of Bloom [see BloomFilter.h for the standard one], beyond the book:

  • SpectralBloomFilter, the filter of Cohen and Matias for multisets: \( m \) counters instead of bits, an insertion of \( x \) with multiplicity \( f \) adds \( f \) to its \( r \) counters and a removal subtracts it, and the multiplicity of \( x \) is estimated by the least of its \( r \) counters (the minimum selection), never below the true one and above it only when all \( r \) counters of \( x \) are shared, with the probability of a false positive of the filter of Bloom with the same \( m \), \( n \) and \( r \). With counters of a few bits it is the counting filter of Fan, Cao, Almeida and Broder, which removes keys; a counter that reaches its largest value sticks there, as they do, so that a removal never makes a false negative;
  • PartitionedBloomFilter, whose \( m \) bits are cut into \( r \) parts of \( m / r \) bits, each hash setting one bit of its own part, so that the \( r \) bits of a key are distinct: the expected bits set and the false positives are about those of the standard filter, \( ( 1 - e^{-r n / m} )^r \), with a slightly smaller variance (Grandi);
  • the analysis: bloomFalsePositive(), the probability \( ( 1 - ( 1 - 1 / m )^{r n} )^r \approx ( 1 - e^{-r n / m} )^r \), least for \( r = ( m / n ) \ln 2 \), where a bit is 0 with probability \( 1 / 2 \) and the error is \( 0.6185^{m/n} \) [see bloomBestHashes()]; bloomLowerBound(), the \( n \log_2( 1 / \epsilon ) \) bits that any structure with false positives \( \epsilon \) and no false negative needs, of which a filter of Bloom uses \( \log_2 e \approx 1.44 \) times [see bloomBits()]; compressedBloom(), the trade-off of Mitzenmacher between the size of a filter and its entropy, by which a larger and sparser filter, compressed by an arithmetic coder, sends fewer bits for the same false positives;
  • bloomIntersection(), the intersection of two sets on two machines by sending the filter of \( A \) and receiving the keys \( Q \) of \( B \) that it accepts, \( A \cap B \subseteq Q \), then \( A \cap Q \): about \( | A \cap B | + 0.6185^{m_A / | A |} | B | \) keys travel back, instead of the whole \( A \).

The \( r \) hashes of a key are \( h_1 + i h_2 \bmod m \) of two hashes, as in BloomFilter. Other filters of today, closer to the lower bound for small false positives, are the quotient filters (Bender et al.), the cuckoo filters (Fan et al.) and the xor filters (Graf and Lemire), the latter with about \( 1.23 \log_2( 1 / \epsilon ) \) bits per key.

The contracts [see Contract.h]: \( m \ge 1 \) and \( r \ge 1 \) (\( m \ge r \) for the partitioned filter); a removal of \( x \) with multiplicity \( f \) only if the estimate of \( x \) is at least \( f \); an item inserted is always maybe there and its estimate is at least its multiplicity, postconditions; for the analysis \( m \ge 1 \), \( n \ge 0 \), \( r \ge 1 \), \( 0 < \epsilon < 1 \). The functions are defined in BloomVariants.tpp.

See also
P. Ferragina, Pearls of Algorithm Engineering, Cambridge University Press, 2023, chapter 8, The Dictionary Problem, doi:10.1017/9781009128933
S. Cohen, Y. Matias, Spectral Bloom filters, Proceedings of SIGMOD 2003, 241-252, 2003, doi:10.1145/872757.872787
L. Fan, P. Cao, J. Almeida, A. Z. Broder, Summary cache: a scalable wide-area web cache sharing protocol, IEEE/ACM Transactions on Networking 8(3), 281-293, 2000, doi:10.1109/90.851975
M. Mitzenmacher, Compressed Bloom filters, IEEE/ACM Transactions on Networking 10(5), 604-612, 2002, doi:10.1109/TNET.2002.803864
A. Z. Broder, M. Mitzenmacher, Network applications of Bloom filters: a survey, Internet Mathematics 1(4), 485-509, 2004, doi:10.1080/15427951.2004.10129096
F. Grandi, On the analysis of Bloom filters, Information Processing Letters 129, 35-39, 2018, doi:10.1016/j.ipl.2017.09.004
T. M. Graf, D. Lemire, Xor filters: faster and smaller than Bloom and cuckoo filters, ACM Journal of Experimental Algorithmics 25, article 1.5, 2020, doi:10.1145/3376122
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa