# Algorithms_in_C++: data_structures::BloomFilter< T > Class Template Reference

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. More...
void | add (T)
| Add function for Bloom filter. More...
bool | contains (T)
| Check element function for Bloom filter. More...

## 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

  T | type 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

  T | type of elements that we need to filter

Parameters

  size | initial size of Bloom filter
  funks | hash functions for T type

Returns
  none

: set(size), hashFunks(funks) {}
data_structures::BloomFilter::hashFunks
std::vector< std::function< std::size_t(T)> > hashFunks
hash functions for T type
Definition: bloom_filter.cpp:103
data_structures::BloomFilter::set
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

  T | type of elements that we need to filter

Parameters

  x | element to add to filter

Returns
  void

{
for (std::size_t i = 0; i < hashFunks.size(); i++) {
set.add(hashFunks[i](x) % (sizeof(std::size_t) * set.size()));
}
}
data_structures::Bitset::add
void add(std::size_t)
Turn bit on position x to 1s.
Definition: bloom_filter.cpp:71
data_structures::Bitset::size
std::size_t size()
Utility function to return the size of the inner array.
Definition: bloom_filter.cpp:57
std::vector::size
T size(T... args)
std::size_t
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

  T | type of elements that we need to filter

Parameters

  x | element 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

{
for (std::size_t i = 0; i < hashFunks.size(); i++) {
if (set.contains(hashFunks[i](x) %
(sizeof(std::size_t) * set.size())) == false) {
return false;
}
}
return true;
}
data_structures::Bitset::contains
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:

- data_structures/bloom_filter.cpp