a filter of Bloom of \( m \) bits and \( k \) hashes
More...
#include <ADS/set/BloomFilter.h>
|
| | BloomFilter (void) |
| | a filter of 64 bits and one hash, empty
|
| | BloomFilter (std::size_t m, int k, H h=H()) |
| | the empty filter of \( m \) bits and \( k \) hashes
|
| void | insert (const T &x) |
| | \( x \) into the filter, by setting its \( k \) bits
|
| bool | maybe (const T &x) const |
| | whether \( x \) may be in the set: false only if \( x \) was never inserted
|
| double | falsePositiveRate (void) const |
| | the expected false positives after the \( n \) insertions made, \( ( 1 - e^{-k n / m} )^k \)
|
| std::size_t | bits (void) const |
| | the bits \( m \)
|
| int | hashes (void) const |
| | the hashes \( k \)
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]
|
|
| static BloomFilter | forItems (std::size_t n, double p) |
| | the filter of the best \( k \) for \( n \) items and the false positives \( p \): \( m = \lceil n \ln( 1 / p ) / ( \ln 2 )^2 \rceil \) bits and \( k = ( m / n ) \ln 2 \) rounded, at least 1
|
| static constexpr std::uint64_t | persistTag (void) |
| | the parameters of the layout, in a file
|
template<class T, class H = std::hash< T >>
class ADS::BloomFilter< T, H >
a filter of Bloom of \( m \) bits and \( k \) hashes
◆ BloomFilter() [1/2]
template<class T, class H = std::hash< T >>
a filter of 64 bits and one hash, empty
◆ BloomFilter() [2/2]
template<class T, class H = std::hash< T >>
the empty filter of \( m \) bits and \( k \) hashes
- Precondition
- \( m \ge 1 \) and \( k \ge 1 \)
◆ bits()
template<class T, class H = std::hash< T >>
◆ falsePositiveRate()
template<class T, class H = std::hash< T >>
the expected false positives after the \( n \) insertions made, \( ( 1 - e^{-k n / m} )^k \)
◆ forItems()
template<class T, class H = std::hash< T >>
the filter of the best \( k \) for \( n \) items and the false positives \( p \): \( m = \lceil n \ln( 1 / p ) / ( \ln 2 )^2 \rceil \) bits and \( k = ( m / n ) \ln 2 \) rounded, at least 1
- Precondition
- \( n \ge 1 \) and \( 0 < p < 1 \)
◆ hashes()
template<class T, class H = std::hash< T >>
◆ insert()
template<class T, class H = std::hash< T >>
\( x \) into the filter, by setting its \( k \) bits
In pseudocode (Bloom, with the two hashes of Kirsch and Mitzenmacher), \( B \) the bits and \( h_2 \) never 0:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( x ) \cr
2 & \quad h_1 \gets \mathrm{splitmix64}( h( x ) );\ h_2 \gets (
\mathrm{splitmix64}( h_1 ) \vee 1 ) \bmod m;\ \textbf{if}\ h_2 = 0
\ \textbf{then}\ h_2 \gets 1 \cr
3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ k - 1\ \textbf{do}
\ B[ ( h_1 + i h_2 ) \bmod m ] \gets 1
\end{array}}
\]
- Postcondition
- maybe( x )
◆ maybe()
template<class T, class H = std::hash< T >>
whether \( x \) may be in the set: false only if \( x \) was never inserted
In pseudocode (Bloom), the bits of insert() read instead of set:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{maybe}( x ) \cr
2 & \quad h_1 \gets \mathrm{splitmix64}( h( x ) );\ h_2 \gets (
\mathrm{splitmix64}( h_1 ) \vee 1 ) \bmod m;\ \textbf{if}\ h_2 = 0
\ \textbf{then}\ h_2 \gets 1 \cr
3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ k - 1\ \textbf{do} \cr
4 & \qquad \textbf{if}\ B[ ( h_1 + i h_2 ) \bmod m ] = 0\ \textbf{then
return false} \cr
5 & \quad \textbf{return true}
\end{array}}
\]
◆ persist()
template<class T, class H = std::hash< T >>
template<class A>
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistTag()
template<class T, class H = std::hash< T >>
|
|
inlinestaticnodiscardconstexpr |
the parameters of the layout, in a file
◆ persistName
template<class T, class H = std::hash< T >>
The documentation for this class was generated from the following file: