vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
bloom_filter.h
1#ifndef STORAGE_BLOOM_FILTER_H
2#define STORAGE_BLOOM_FILTER_H
3
4#include <vkdb/murmur_hash_3.h>
5#include <vkdb/time_series_key.h>
6#include <vkdb/random.h>
7#include <vector>
8#include <stdexcept>
9#include <cmath>
10
11namespace vkdb {
17public:
18 using key_type = TimeSeriesKey;
19 using size_type = uint64_t;
20
25 static constexpr double MIN_FALSE_POSITIVE_RATE{0.0};
26
31 static constexpr double MAX_FALSE_POSITIVE_RATE{1.0};
32
37 BloomFilter() = delete;
38
44 BloomFilter(std::string&& str) noexcept;
45
57 explicit BloomFilter(
58 uint64_t expected_no_of_elems,
59 double false_positive_rate
60 );
61
66 ~BloomFilter() noexcept = default;
67
72 BloomFilter(BloomFilter&&) noexcept = default;
73
78 BloomFilter& operator=(BloomFilter&&) noexcept = default;
79
84 BloomFilter(const BloomFilter&) = delete;
85
90 BloomFilter& operator=(const BloomFilter&) = delete;
91
97 void insert(const key_type& key) noexcept;
98
106 [[nodiscard]] bool mayContain(const key_type& key) const noexcept;
107
113 [[nodiscard]] std::string str() const noexcept;
114
115private:
120 using HashValue = uint32_t;
121
127 void initialise_seeds(size_type no_of_hashes) noexcept;
128
136 [[nodiscard]] HashValue hash(
137 const key_type& key,
138 size_type i
139 ) const noexcept;
140
145 std::vector<size_type> seeds_;
146
151 std::vector<bool> bits_;
152};
153} // namespace vkdb
154
155#endif // STORAGE_BLOOM_FILTER_H
Bloom filter for time series keys.
std::string str() const noexcept
Get the string representation of the Bloom filter.
BloomFilter()=delete
Deleted default constructor.
~BloomFilter() noexcept=default
Destroy the BloomFilter object.
bool mayContain(const key_type &key) const noexcept
Check if the Bloom filter may contain a key.
void insert(const key_type &key) noexcept
Insert a key into the Bloom filter.
static constexpr double MIN_FALSE_POSITIVE_RATE
Minimum (exclusive) false positive rate.
static constexpr double MAX_FALSE_POSITIVE_RATE
Maximum (exclusive) false positive rate.
Represents a key in vkdb.
STL namespace.