|
ADS
Algorithms and Data Structures
|
The variants and the analysis of the filter of Bloom, beyond the book. More...
Files | |
| file | ADS/set/BloomVariants.h |
| The variants and the analysis of the filter of Bloom [see BloomFilter.h for the standard one], beyond the book: | |
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... | |
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 \) | |
The variants and the analysis of the filter of Bloom, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of sets.
|
inlinenodiscard |
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
In pseudocode (Bloom), the false positives being convex in \( r \) near its real optimum:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{bloomBestHashes}( m , n ) \cr 2 & \quad \ell \gets \max( 1 , \lfloor ( m / n ) \ln 2 \rfloor ) \cr 3 & \quad \textbf{if}\ \mathrm{bloomFalsePositive}( m , n , \ell + 1 ) < \mathrm{bloomFalsePositive}( m , n , \ell )\ \textbf{then return} \ \ell + 1 \cr 4 & \quad \textbf{return}\ \ell \end{array}} \]
|
inlinenodiscard |
\( n \log_2( 1 / \epsilon ) / \ln 2 \), the bits of a filter of Bloom with the best number of hashes and false positives \( \epsilon \)
|
inlinenodiscard |
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 \)
|
nodiscard |
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 \)
In pseudocode (Broder and Mitzenmacher), the first machine holding \( A \) and the second \( B \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{bloomIntersection}( A , B , m_A ) \cr 2 & \quad F \gets \text{a filter of } m_A \text{ bits and the best } \text{number of hashes} \cr 3 & \quad \textbf{foreach}\ a \in A\ \textbf{do}\ F.\mathrm{insert}( a ) \quad \triangleright\ \text{the first machine sends } F \cr 4 & \quad Q \gets ( b \in B : F.\mathrm{maybe}( b ) )\quad \triangleright\ \text{the second sends } Q \cr 5 & \quad I \gets ( q \in Q : q \in A ) \cr 6 & \quad \textbf{return}\ ( Q , I ) \end{array}} \]
|
inlinenodiscard |
\( n \log_2( 1 / \epsilon ) \), the bits that any filter of \( n \) keys with false positives \( \epsilon \) needs
|
inlinenodiscard |
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
In pseudocode (Mitzenmacher), \( p \) the probability that a bit is 0 and \( H \) the binary entropy:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{compressedBloom}( \mathit{bitsPerKey} , r ) \cr 2 & \quad p \gets e^{-r / \mathit{bitsPerKey}} \cr 3 & \quad H \gets - p \log_2 p - ( 1 - p ) \log_2( 1 - p ) \cr 4 & \quad \textbf{return}\ ( ( 1 - p )^r , \mathit{bitsPerKey} \cdot H ) \end{array}} \]