38static inline uint32_t
fnv(
const char *datum,
size_t len)
40 uint32_t z = 0x811c9dc5;
78 uint32_t hash =
fnv(s, z);
84 unsigned int index = hash % (b->
size << 3);
85 unsigned int byte_index = index >> 3;
86 unsigned int bit_index = index & 7;
88 b->
filter[byte_index] |= (1 << bit_index);
94 uint32_t hash =
fnv(s, z);
100 unsigned int index = hash % (b->
size << 3);
101 unsigned int byte_index = index >> 3;
102 unsigned int bit_index = index & 7;
104 return (b->
filter[byte_index] & (1 << bit_index)) != 0;
uint32_t bloom_items(struct bloom_filter *b)
Find out how many items have been added to this bloom filter.
struct bloom_filter * bloom_create(size_t size)
Create a new bloom filter.
void bloom_destroy(struct bloom_filter *b)
Destroy a previously-created bloom filter.
bool bloom_search_str(struct bloom_filter *b, const char *s, size_t z)
Search the filter for the given string, assuming it was added by bloom_insert_str().
void bloom_insert_str(struct bloom_filter *b, const char *s, size_t z)
Insert a string of given length (may include NULs) into the filter, using an internal hash function.
bool bloom_search_hash(struct bloom_filter *b, uint32_t hash)
Search the filter for the given hash value, assuming it was added by bloom_insert_hash().
static uint32_t fnv(const char *datum, size_t len)
Hash a string, returning a 32bit value.
void bloom_insert_hash(struct bloom_filter *b, uint32_t hash)
Insert a given hash value into the filter, should you already have one to hand.
uint8_t filter[FLEX_ARRAY_LEN_DECL]
Interface to a number of general purpose functionality.
#define FLEX_ARRAY_LEN_DECL