MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / bloom_check_add

Function bloom_check_add

libCacheSim/dataStructure/bloom.c:52–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52static int bloom_check_add(struct bloom *bloom, const void *buffer, int len,
53 int add) {
54 if (bloom->ready == 0) {
55 printf("bloom at %p not initialized!\n", (void *)bloom);
56 return -1;
57 }
58
59 int hits = 0;
60 // register unsigned int a = murmurhash2(buffer, len, 0x9747b28c);
61 // register unsigned int b = murmurhash2(buffer, len, a);
62 register unsigned int a = XXH64(buffer, len, HASH_SEED0);
63 register unsigned int b = XXH64(buffer, len, HASH_SEED1);
64 register unsigned int x;
65 register int i;
66
67 for (i = 0; i < bloom->hashes; i++) {
68 x = (a + i * b) % bloom->bits;
69 if (test_bit_set_bit(bloom->bf, x, add)) {
70 hits++;
71 } else if (!add) {
72 // Don't care about the presence of all the bits. Just our own.
73 return 0;
74 }
75 }
76
77 if (hits == bloom->hashes) {
78 return 1; // 1 == element already in (or collision)
79 }
80
81 return 0;
82}
83
84int bloom_init_size(struct bloom *bloom, int entries, double error,
85 unsigned int cache_size) {

Callers 2

bloom_checkFunction · 0.85
bloom_addFunction · 0.85

Calls 1

test_bit_set_bitFunction · 0.85

Tested by

no test coverage detected