ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::BlockedBloomFilter< T, H > Class Template Reference

a filter of Bloom in blocks of 256 bits, 8 bits per item More...

#include <ADS/set/BlockedBloomFilter.h>

Public member functions

 BlockedBloomFilter (void)
 a filter of one block, empty
 BlockedBloomFilter (std::size_t n, double bitsPerItem=10, H h=H())
 the empty filter of about bitsPerItem bits for each of \( n \) items, in at least one block, \( \lceil n \cdot \mathit{bitsPerItem} / 256 \rceil \) blocks
void insert (const T &x)
 \( x \) into the filter, by insertHash() of its hash
bool maybe (const T &x) const
 whether \( x \) may be in the set, by maybeHash() of its hash: false only if \( x \) was never inserted
void insertHash (std::uint64_t h)
 the hash \( h \) of 64 bits, which must be random, into the filter
bool maybeHash (std::uint64_t h) const
 whether the hash \( h \) may be in the set: false only if it was never inserted
void unite (const BlockedBloomFilter &o)
 the items of o added, as if they had been inserted here, by the OR of the blocks
void clear (void)
 removes all the items
std::size_t size (void) const
 the insertions made
bool empty (void) const
 whether no item was inserted
std::size_t bits (void) const
 the bits, 256 per block
std::size_t blocks (void) const
 the blocks \( B \)
double falsePositiveRate (void) const
 the expected false positives after the insertions made, the mean over the Poisson loads of the blocks, \( \sum_j e^{-\lambda} \lambda^j / j! \, ( 1 - ( 31 / 32 )^j )^8 \) with \( \lambda = n / B \)
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]

Static public member functions

static constexpr std::uint64_t persistTag (void)
 the parameters of the layout, in a file

Static public attributes

static constexpr std::string_view persistName = "BlockedBloomFilter"
 the name of the structure in a file [see Persistence.h]

Detailed description

template<class T, class H = DefaultHash< T >>
class ADS::BlockedBloomFilter< T, H >

a filter of Bloom in blocks of 256 bits, 8 bits per item

Constructor and destructor documentation

◆ BlockedBloomFilter() [1/2]

template<class T, class H = DefaultHash< T >>
ADS::BlockedBloomFilter< T, H >::BlockedBloomFilter ( void )
inline

a filter of one block, empty

◆ BlockedBloomFilter() [2/2]

template<class T, class H = DefaultHash< T >>
ADS::BlockedBloomFilter< T, H >::BlockedBloomFilter ( std::size_t n,
double bitsPerItem = 10,
H h = H() )
explicit

the empty filter of about bitsPerItem bits for each of \( n \) items, in at least one block, \( \lceil n \cdot \mathit{bitsPerItem} / 256 \rceil \) blocks

Precondition
\( \mathit{bitsPerItem} > 0 \)

Member function documentation

◆ bits()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::BlockedBloomFilter< T, H >::bits ( void ) const
nodiscard

the bits, 256 per block

◆ blocks()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::BlockedBloomFilter< T, H >::blocks ( void ) const
nodiscard

the blocks \( B \)

◆ clear()

template<class T, class H = DefaultHash< T >>
void ADS::BlockedBloomFilter< T, H >::clear ( void )

removes all the items

◆ empty()

template<class T, class H = DefaultHash< T >>
bool ADS::BlockedBloomFilter< T, H >::empty ( void ) const
nodiscard

whether no item was inserted

◆ falsePositiveRate()

template<class T, class H = DefaultHash< T >>
double ADS::BlockedBloomFilter< T, H >::falsePositiveRate ( void ) const
nodiscard

the expected false positives after the insertions made, the mean over the Poisson loads of the blocks, \( \sum_j e^{-\lambda} \lambda^j / j! \, ( 1 - ( 31 / 32 )^j )^8 \) with \( \lambda = n / B \)

In pseudocode (Putze, Sanders and Singler), the terms by the recurrence \( p_{j+1} = p_j \lambda / ( j + 1 ) \) from the mode \( j_0 = \lfloor \lambda \rfloor \) both ways, until they fall below \( 10^{-18} p_{j_0} \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{falsePositiveRate}() \cr 2 & \quad \lambda \gets n / B;\ \textbf{if}\ \lambda = 0 \ \textbf{then return}\ 0 \cr 3 & \quad j_0 \gets \lfloor \lambda \rfloor;\ p_{j_0} \gets e^{-\lambda} \lambda^{j_0} / j_0! \cr 4 & \quad \textbf{return}\ \sum_j p_j ( 1 - ( 31 / 32 )^j )^8 \ \text{over the } j \text{ with } p_j \ge 10^{-18} p_{j_0} \end{array}} \]

◆ insert()

template<class T, class H = DefaultHash< T >>
void ADS::BlockedBloomFilter< T, H >::insert ( const T & x)

\( x \) into the filter, by insertHash() of its hash

Postcondition
maybe( x )

◆ insertHash()

template<class T, class H = DefaultHash< T >>
void ADS::BlockedBloomFilter< T, H >::insertHash ( std::uint64_t h)

the hash \( h \) of 64 bits, which must be random, into the filter

In pseudocode (Putze, Sanders and Singler, with the 8 words of the format Parquet), \( W_b \) the 8 words of 32 bits of the block \( b \) and \( s_i \) the 8 odd constants:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insertHash}( h ) \cr 2 & \quad b \gets \lfloor \lfloor h / 2^{32} \rfloor \cdot B / 2^{32} \rfloor;\ h_0 \gets h \bmod 2^{32} \cr 3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ 7\ \textbf{do} \ W_b[ i ] \gets W_b[ i ] \vee 2^{\lfloor ( h_0 s_i \bmod 2^{32} ) / 2^{27} \rfloor} \end{array}} \]

◆ maybe()

template<class T, class H = DefaultHash< T >>
bool ADS::BlockedBloomFilter< T, H >::maybe ( const T & x) const
nodiscard

whether \( x \) may be in the set, by maybeHash() of its hash: false only if \( x \) was never inserted

◆ maybeHash()

template<class T, class H = DefaultHash< T >>
bool ADS::BlockedBloomFilter< T, H >::maybeHash ( std::uint64_t h) const
nodiscard

whether the hash \( h \) may be in the set: false only if it was never inserted

In pseudocode (Putze, Sanders and Singler), the 8 bits of insertHash() tested at once:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{maybeHash}( h ) \cr 2 & \quad b \gets \text{the block of } h;\ M \gets \text{the 8 } \text{words of the bits of } h \cr 3 & \quad \textbf{return}\ M[ i ] \wedge \lnot W_b[ i ] = 0 \ \text{for } i = 0 , \ldots , 7 \end{array}} \]

◆ persist()

template<class T, class H = DefaultHash< T >>
template<class A>
void ADS::BlockedBloomFilter< T, H >::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ persistTag()

template<class T, class H = DefaultHash< T >>
constexpr std::uint64_t ADS::BlockedBloomFilter< T, H >::persistTag ( void )
inlinestaticnodiscardconstexpr

the parameters of the layout, in a file

◆ size()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::BlockedBloomFilter< T, H >::size ( void ) const
nodiscard

the insertions made

◆ unite()

template<class T, class H = DefaultHash< T >>
void ADS::BlockedBloomFilter< T, H >::unite ( const BlockedBloomFilter< T, H > & o)

the items of o added, as if they had been inserted here, by the OR of the blocks

Precondition
o has the blocks of this filter

Member data documentation

◆ persistName

template<class T, class H = DefaultHash< T >>
std::string_view ADS::BlockedBloomFilter< T, H >::persistName = "BlockedBloomFilter"
staticconstexpr

the name of the structure in a file [see Persistence.h]


The documentation for this class was generated from the following file: