|
@ -88,11 +88,11 @@ unsetbit(bit_array_t* arr, int k) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bfilter_hashes_t |
|
|
fnv_hashes_t |
|
|
hash(const char* value) { |
|
|
hash_fnv(const char* value) { |
|
|
uint64_t hval; |
|
|
uint64_t hval; |
|
|
|
|
|
|
|
|
bfilter_hashes_t hashes; |
|
|
fnv_hashes_t hashes; |
|
|
|
|
|
|
|
|
fnv64Init(&hval); |
|
|
fnv64Init(&hval); |
|
|
|
|
|
|
|
@ -107,18 +107,35 @@ hash(const char* value) { |
|
|
return hashes; |
|
|
return hashes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t |
|
|
|
|
|
nth_hash(fnv_hashes_t hashes, |
|
|
|
|
|
uint32_t i, |
|
|
|
|
|
size_t m) { |
|
|
|
|
|
return (hashes.hash_1 + hashes.hash_2 * i) % m; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hashes_t |
|
|
|
|
|
hash(const char *input, uint32_t k, size_t m) { |
|
|
|
|
|
fnv_hashes_t fnv = hash_fnv(input); |
|
|
|
|
|
hashes_t hashes = malloc((sizeof (uint32_t)) * k); |
|
|
|
|
|
|
|
|
|
|
|
hashes[0] = fnv.hash_1 % m; |
|
|
|
|
|
hashes[1] = fnv.hash_2 % m; |
|
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < (k-2); i++) { |
|
|
|
|
|
hashes[i+2] = nth_hash(fnv, i+2, m); |
|
|
|
|
|
} |
|
|
|
|
|
return hashes; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
main (void) { |
|
|
main (void) { |
|
|
bit_array_t *test = new_bitarray(100); |
|
|
bit_array_t *test = new_bitarray(100); |
|
|
setbit(test, 31); |
|
|
const char *test_string = "what tf is this I can't even, lololol"; |
|
|
setbit(test, 63); |
|
|
hashes_t hashes = hash(test_string, 5, 100); |
|
|
setbit(test, 95); |
|
|
for(int i = 0; i < 5; i++) { |
|
|
setbit(test, 127); |
|
|
printf("%zu\n", hashes[i]); |
|
|
print_barray(test); |
|
|
} |
|
|
|
|
|
|
|
|
const char *test_string = "what blah is this I can't even, lololol"; |
|
|
|
|
|
printf("%zu\n", hash(test_string).hash_1); |
|
|
|
|
|
printf("%zu\n", hash(test_string).hash_2); |
|
|
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS; |
|
|
return EXIT_SUCCESS; |
|
|
} |
|
|
} |
|
|