38#include <gtest/gtest.h>
52size_t identity_hash(
const int &item,
unsigned long)
noexcept
54 return static_cast<size_t>(item);
57size_t salted_identity_hash(
const int &item,
unsigned long seed)
noexcept
59 return static_cast<size_t>(item) +
static_cast<size_t>(
seed);
73TEST(BloomFilterCtor, rejects_invalid_arguments)
80TEST(BloomFilterBasics, insert_contains_no_false_negatives)
84 for (
int i = 0; i < 50; ++i)
91TEST(BloomFilterBasics, deterministic_no_false_positives_when_k1_identity_and_sparse)
111TEST(BloomFilterIntrospection, hash_seeds_and_hashes_sizes)
116 EXPECT_EQ(seeds.size(), 5u);
119 EXPECT_EQ(hashes.size(), 5u);
120 for (
const auto h : hashes)
124TEST(BloomFilterIntrospection, set_bits_matches_inserted_for_k1_identity)
133 EXPECT_EQ(
bits.size(), 3u);
140TEST(BloomFilterSemantics, copy_and_move_preserve_behavior)
143 for (
int i = 0; i < 20; ++i)
150 for (
int i = 0; i < 20; ++i)
151 EXPECT_TRUE(
copy.contains(i));
154 for (
int i = 0; i < 20; ++i)
158TEST(BloomFilterSetOps, union_and_intersection_require_compatible_seeds)
184TEST(BloomFilterSetOps, mismatch_throws_domain_error_and_keeps_message)
192 FAIL() <<
"expected std::domain_error";
194 catch (
const std::domain_error &e)
196 const string msg = e.what();
197 EXPECT_NE(msg.find(
"Bloom filter have different hashes"), string::npos);
201TEST(BloomFilterMath, expected_size_is_reasonable_for_sparse_k1_identity)
204 for (
int i = 0; i < 50; ++i)
207 const auto x = f.
get_x();
Probabilistic set membership with Bloom filters.
size_t size_t int32_t value
size_t size_t int32_t * out
Bloom filter implementation.
size_t expected_size(const size_t x) const noexcept
Estimate the number of inserted items from the number of bits set.
size_t get_n() const noexcept
Return the number of insertions performed on the filter.
DynList< size_t > set_bits() const
Return the indexes of bits set to 1.
size_t get_m() const noexcept
Return the number of bits of the filter.
bool contains(const T &item) const
Test membership.
DynList< size_t > hash_seeds() const
Return the internally generated per-hash seeds.
auto & insert(const T &item)
Insert an item.
DynList< size_t > hashes(const T &item) const
Return the bit positions used by item.
size_t get_k() const noexcept
Return the number of hash functions used by the filter.
size_t get_x() const noexcept
Return the number of bits set to 1.
Doubly-linked list (defined in tpl_dynList.H).
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Main namespace for Aleph-w library functions.
constexpr Bit_Column bits(const unsigned n)
Column of n bits without sign: the integers of [0, 2^n - 1].
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.