42 #define MAX_HASH_FUNCS 10
101 bitset_bytes =
Min(bloom_work_mem *
UINT64CONST(1024), total_elems * 2);
102 bitset_bytes =
Max(1024 * 1024, bitset_bytes);
114 sizeof(
unsigned char) * bitset_bytes);
117 filter->
m = bitset_bits;
145 filter->
bitset[hashes[
i] >> 3] |= 1 << (hashes[
i] & 7);
167 if (!(filter->
bitset[hashes[
i] >> 3] & (1 << (hashes[
i] & 7))))
192 return bits_set / (double) filter->
m;
212 int bloom_power = -1;
214 while (target_bitset_bits > 0 && bloom_power < 32)
217 target_bitset_bits >>= 1;
231 int k = rint(log(2.0) * bitset_bits / total_elems);
291 Assert(((m - 1) & m) == 0);
293 return val & (m - 1);
void bloom_free(bloom_filter *filter)
bloom_filter * bloom_create(int64 total_elems, int bloom_work_mem, uint64 seed)
static int optimal_k(uint64 bitset_bits, int64 total_elems)
double bloom_prop_bits_set(bloom_filter *filter)
static uint32 mod_m(uint32 val, uint64 m)
bool bloom_lacks_element(bloom_filter *filter, unsigned char *elem, size_t len)
static int my_bloom_power(uint64 target_bitset_bits)
static void k_hashes(bloom_filter *filter, uint32 *hashes, unsigned char *elem, size_t len)
void bloom_add_element(bloom_filter *filter, unsigned char *elem, size_t len)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
void pfree(void *pointer)
void * palloc0(Size size)
static uint64 pg_popcount(const char *buf, int bytes)
static uint64 DatumGetUInt64(Datum X)
static unsigned hash(unsigned *uv, int n)
unsigned char bitset[FLEXIBLE_ARRAY_MEMBER]