btllib: btllib::CountingBloomFilter< T > Class Template Reference

btllib

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
btllib::CountingBloomFilter< T > Class Template Reference

`#include <counting_bloom_filter.hpp>`

## Public Member Functions
| CountingBloomFilter ()
| CountingBloomFilter (size_t bytes, unsigned hash_num, std::string hash_fn="")
| CountingBloomFilter (const std::string &path)
| CountingBloomFilter (const CountingBloomFilter &)=delete
| CountingBloomFilter (CountingBloomFilter &&)=delete
CountingBloomFilter & | operator= (const CountingBloomFilter &)=delete
CountingBloomFilter & | operator= (CountingBloomFilter &&)=delete
void | insert (const uint64_t *hashes, T n=1)
void | insert (const std::vector< uint64_t > &hashes, T n=1)
void | remove (const uint64_t *hashes)
void | remove (const std::vector< uint64_t > &hashes)
void | clear (const uint64_t *hashes)
void | clear (const std::vector< uint64_t > &hashes)
T | contains (const uint64_t *hashes) const
T | contains (const std::vector< uint64_t > &hashes) const
T | contains_insert (const uint64_t *hashes, T n=1)
T | contains_insert (const std::vector< uint64_t > &hashes, T n=1)
T | insert_contains (const uint64_t *hashes, T n=1)
T | insert_contains (const std::vector< uint64_t > &hashes, T n=1)
T | insert_thresh_contains (const uint64_t *hashes, T threshold)
T | insert_thresh_contains (const std::vector< uint64_t > &hashes, const T threshold)
T | contains_insert_thresh (const uint64_t *hashes, T threshold)
T | contains_insert_thresh (const std::vector< uint64_t > &hashes, const T threshold)
size_t | get_bytes () const
uint64_t | get_pop_cnt (T threshold=1) const
double | get_occupancy (T threshold=1) const
unsigned | get_hash_num () const
double | get_fpr (T threshold=1) const
const std::string & | get_hash_fn () const
void | save (const std::string &path)

## Static Public Member Functions
static bool | is_bloom_file (const std::string &path)

## Friends
class | KmerCountingBloomFilter< T >

## Detailed Description

template<typename T>
class btllib::CountingBloomFilter< T >

Counting Bloom filter data structure. Provides CountingBloomFilter8, CountingBloomFilter16, and CountingBloomFilter32 classes with corresponding bit-size counters.

## Constructor & Destructor Documentation

## ◆ CountingBloomFilter() [1/3]

template<typename T >

btllib::CountingBloomFilter< T >::CountingBloomFilter | ( |  | ) |
| inline

Construct a dummy k-mer Bloom filter (e.g. as a default argument).

## ◆ CountingBloomFilter() [2/3]

template<typename T >

btllib::CountingBloomFilter< T >::CountingBloomFilter | ( | size_t | bytes,
|  | unsigned | hash_num,
|  | std::string | hash_fn = "" )
| inline

Construct an empty Counting Bloom filter of given size.

Parameters

  bytes | Filter size in bytes.
  hash_num | Number of hash values per element.
  hash_fn | Name of the hash function used. Used for metadata. Optional.

## ◆ CountingBloomFilter() [3/3]

template<typename T >

btllib::CountingBloomFilter< T >::CountingBloomFilter | ( | const std::string & | path | ) |
| inlineexplicit

Load a Counting Bloom filter from a file.

Parameters

  path | Filepath to load from.

## Member Function Documentation

## ◆ clear() [1/2]

template<typename T >

void btllib::CountingBloomFilter< T >::clear | ( | const std::vector< uint64_t > & | hashes | ) |
| inline

Set the count of an element to zero.

Parameters

  hashes | Integer vector of the element's hash values.

## ◆ clear() [2/2]

template<typename T >

void btllib::CountingBloomFilter< T >::clear | ( | const uint64_t * | hashes | ) |

Set the count of an element to zero.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

## ◆ contains() [1/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains | ( | const std::vector< uint64_t > & | hashes | ) | const
| inline

Get the count of an element.

Parameters

  hashes | Integer vector of the element's hash values.

Returns
  The count of the queried element.

## ◆ contains() [2/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains | ( | const uint64_t * | hashes | ) | const
| inline

Get the count of an element.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

Returns
  The count of the queried element.

## ◆ contains_insert() [1/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains_insert | ( | const std::vector< uint64_t > & | hashes,
|  | T | n = 1 )
| inline

Get the count of an element and then increment the count.

Parameters

  hashes | Integer vector of the element's hash values.
  n | Increment value

Returns
  The count of the queried element before insertion.

## ◆ contains_insert() [2/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains_insert | ( | const uint64_t * | hashes,
|  | T | n = 1 )
| inline

Get the count of an element and then increment the count.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  n | Increment value

Returns
  The count of the queried element before insertion.

## ◆ contains_insert_thresh() [1/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains_insert_thresh | ( | const std::vector< uint64_t > & | hashes,
|  | const T | threshold )
| inline

Get the count of an element and then increment the count if it's not above the threshold.

Parameters

  hashes | Integer vector of the element's hash values.
  threshold | The threshold.

Returns
  The count of the queried element before insertion.

## ◆ contains_insert_thresh() [2/2]

template<typename T >

T btllib::CountingBloomFilter< T >::contains_insert_thresh | ( | const uint64_t * | hashes,
|  | T | threshold )
| inline

Get the count of an element and then increment the count if it's not above the threshold.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried element before insertion.

## ◆ get_bytes()

template<typename T >

size_t btllib::CountingBloomFilter< T >::get_bytes | ( |  | ) | const
| inline

Get filter size in bytes.

## ◆ get_fpr()

template<typename T >

double btllib::CountingBloomFilter< T >::get_fpr | ( | T | threshold = 1 | ) | const
| inline

Get the query false positive rate for elements with count >= threshold.

Parameters

  threshold | The threshold.

Returns
  The false positive rate.

## ◆ get_hash_fn()

template<typename T >

const std::string & btllib::CountingBloomFilter< T >::get_hash_fn | ( |  | ) | const
| inline

Get the name of the hash function used.

## ◆ get_hash_num()

template<typename T >

unsigned btllib::CountingBloomFilter< T >::get_hash_num | ( |  | ) | const
| inline

Get the number of hash values per element.

## ◆ get_occupancy()

template<typename T >

double btllib::CountingBloomFilter< T >::get_occupancy | ( | T | threshold = 1 | ) | const
| inline

Get the fraction of the filter occupied by >= threshold counters.

## ◆ get_pop_cnt()

template<typename T >

uint64_t btllib::CountingBloomFilter< T >::get_pop_cnt | ( | T | threshold = 1 | ) | const
| inline

Get population count, i.e. the number of counters >= threshold in the filter.

## ◆ insert() [1/2]

template<typename T >

void btllib::CountingBloomFilter< T >::insert | ( | const std::vector< uint64_t > & | hashes,
|  | T | n = 1 )
| inline

Insert an element.

Parameters

  hashes | Integer vector of the element's hash values.
  n | Increment value

## ◆ insert() [2/2]

template<typename T >

void btllib::CountingBloomFilter< T >::insert | ( | const uint64_t * | hashes,
|  | T | n = 1 )
| inline

Insert an element.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  n | Increment value

## ◆ insert_contains() [1/2]

template<typename T >

T btllib::CountingBloomFilter< T >::insert_contains | ( | const std::vector< uint64_t > & | hashes,
|  | T | n = 1 )
| inline

Increment an element's count and then return the count.

Parameters

  hashes | Integer vector of the element's hash values.
  n | Increment value

Returns
  The count of the queried element after insertion.

## ◆ insert_contains() [2/2]

template<typename T >

T btllib::CountingBloomFilter< T >::insert_contains | ( | const uint64_t * | hashes,
|  | T | n = 1 )
| inline

Increment an element's count and then return the count.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  n | Increment value

Returns
  The count of the queried element after insertion.

## ◆ insert_thresh_contains() [1/2]

template<typename T >

T btllib::CountingBloomFilter< T >::insert_thresh_contains | ( | const std::vector< uint64_t > & | hashes,
|  | const T | threshold )
| inline

Increment an element's count if it's not above the threshold and then return the count.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried element after insertion.

## ◆ insert_thresh_contains() [2/2]

template<typename T >

T btllib::CountingBloomFilter< T >::insert_thresh_contains | ( | const uint64_t * | hashes,
|  | T | threshold )
| inline

Increment an element's count if it's not above the threshold and then return the count.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried element after insertion.

## ◆ is_bloom_file()

template<typename T >

static bool btllib::CountingBloomFilter< T >::is_bloom_file | ( | const std::string & | path | ) |
| inlinestatic

Check whether the file at the given path is a saved Counting Bloom filter.

Parameters

  path | Filepath to check.

## ◆ remove() [1/2]

template<typename T >

void btllib::CountingBloomFilter< T >::remove | ( | const std::vector< uint64_t > & | hashes | ) |
| inline

Delete an element.

Parameters

  hashes | Integer vector of the element's hash values.

## ◆ remove() [2/2]

template<typename T >

void btllib::CountingBloomFilter< T >::remove | ( | const uint64_t * | hashes | ) |
| inline

Delete an element.

Parameters

  hashes | Integer array of the element's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

## ◆ save()

template<typename T >

void btllib::CountingBloomFilter< T >::save | ( | const std::string & | path | ) |
| inline

Save the Bloom filter to a file that can be loaded in the future.

Parameters

  path | Filepath to store filter at.

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

- include/btllib/counting_bloom_filter.hpp
- include/btllib/counting_bloom_filter-inl.hpp