bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2018 Dovecot authors, see the included COPYING file */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi#define BITMAP_HAS_BIT(map, idx) (((map)[((idx)/CHAR_BIT)] & (0x1<<((idx)%CHAR_BIT))) != 0)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi#define BITMAP_SET_BIT(map, idx) ((map)[((idx)/CHAR_BIT)] |= (0x1<<((idx)%CHAR_BIT)))
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi/* use only murmurhash3 by default */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomibloomfilter_hash_func_t *const bloomfilter_default_functions[] = {
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomistatic inline size_t
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomibloomfilter_hash_fold(unsigned char result[STATIC_ARRAY BLOOMFILTER_HASH_BYTES],
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* rolls 128 bit result into a 64 bit result by xoring the first 64 bits
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi and seed, and remaining 64 bits. */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* rolls 128 bit result into a 32 bit result by folding
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi all the successive 32 bit values into one together with seed. */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomisize_t bloomfilter_murmur3_hash(const void *data, size_t len, uint32_t seed)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi unsigned char result[MURMURHASH3_128_RESULTBYTES];
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* murmur includes seed already */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomisize_t bloomfilter_md5_hash(const void *data, size_t len, uint32_t seed)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi struct bloomfilter *bf = p_new(pool, struct bloomfilter, 1);
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* allocate extra byte to round up result */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* in case system pool was used .. */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomisize_t bloomfilter_estimated_item_count(struct bloomfilter *bf)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomibool bloomfilter_has_data(struct bloomfilter *bf, const void *data, size_t len)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi for(;*k != NULL; k++) {
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomivoid bloomfilter_set_data(struct bloomfilter *bf, const void *data, size_t len)
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi /* total added will cap at size_t, because it's an estimate */
44d29bbfa14662dc1b2873f1a570a0767f827cd1Aki Tuomi for(;*k != NULL; k++) {