Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
data_structures::BloomFilter< T > Class Template Reference

Bloom filter template class. More...

Collaboration diagram for data_structures::BloomFilter< T >:
[legend]

Public Member Functions

 BloomFilter (std::size_t, std::initializer_list< std::function< std::size_t(T)> >)
 Constructor for Bloom filter.
 
void add (T)
 Add function for Bloom filter.
 
bool contains (T)
 Check element function for Bloom filter.
 

Private Attributes

Bitset set
 inner bitset for elements
 
std::vector< std::function< std::size_t(T)> > hashFunks
 hash functions for T type
 

Detailed Description

template<typename T>
class data_structures::BloomFilter< T >

Bloom filter template class.

Template Parameters
Ttype of elements that we need to filter

Constructor & Destructor Documentation

◆ BloomFilter()

template<typename T >
data_structures::BloomFilter< T >::BloomFilter ( std::size_t size,
std::initializer_list< std::function< std::size_t(T)> > funks )

Constructor for Bloom filter.

Template Parameters
Ttype of elements that we need to filter
Parameters
sizeinitial size of Bloom filter
funkshash functions for T type
Returns
none
124 : set(size), hashFunks(funks) {}
std::vector< std::function< std::size_t(T)> > hashFunks
hash functions for T type
Definition bloom_filter.cpp:103
Bitset set
inner bitset for elements
Definition bloom_filter.cpp:101

Member Function Documentation

◆ add()

template<typename T >
void data_structures::BloomFilter< T >::add ( T x)

Add function for Bloom filter.

Template Parameters
Ttype of elements that we need to filter
Parameters
xelement to add to filter
Returns
void
134 {
135 for (std::size_t i = 0; i < hashFunks.size(); i++) {
136 set.add(hashFunks[i](x) % (sizeof(std::size_t) * set.size()));
137 }
138}
void add(std::size_t)
Turn bit on position x to 1s.
Definition bloom_filter.cpp:71
std::size_t size()
Utility function to return the size of the inner array.
Definition bloom_filter.cpp:57
T size(T... args)
Here is the call graph for this function:

◆ contains()

template<typename T >
bool data_structures::BloomFilter< T >::contains ( T x)

Check element function for Bloom filter.

Template Parameters
Ttype of elements that we need to filter
Parameters
xelement to check in filter
Returns
true if the element probably appears in the filter
false if the element certainly does not appear in the filter
149 {
150 for (std::size_t i = 0; i < hashFunks.size(); i++) {
151 if (set.contains(hashFunks[i](x) %
152 (sizeof(std::size_t) * set.size())) == false) {
153 return false;
154 }
155 }
156 return true;
157}
bool contains(std::size_t)
Doest bitset contains element x.
Definition bloom_filter.cpp:86
Here is the call graph for this function:

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