diff --git a/bfilter.c b/bfilter.c index cf5887c..fab2f73 100644 --- a/bfilter.c +++ b/bfilter.c @@ -132,6 +132,14 @@ kth_hash(fnv_hashes_t hashes, hashes_t hash(const char *input, uint32_t k, size_t m) { fnv_hashes_t fnv = hash_fnv(input); + + if (k <= 2) { + hashes_t hashes = malloc((sizeof (uint32_t)) * 2); + hashes[0] = fnv.hash_1 % m; + hashes[1] = fnv.hash_2 % m; + return hashes; + } + hashes_t hashes = malloc((sizeof (uint32_t)) * k); hashes[0] = fnv.hash_1 % m; @@ -147,6 +155,9 @@ int bfilter_set(bit_array_t *filter, const char *key, int k) { + if (k <= 2) { + k = 2; + } hashes_t hashes = hash(key, k, filter->num_elems); for(int i = 0; i < k; i++) { @@ -159,6 +170,9 @@ int bfilter_get(bit_array_t *filter, const char*key, int k) { + if (k <= 2) { + k = 2; + } hashes_t hashes = hash(key, k, filter->num_elems); int exists = 1; diff --git a/bfilter.o b/bfilter.o index 132ba8c..954c271 100644 Binary files a/bfilter.o and b/bfilter.o differ diff --git a/bfilter.py b/bfilter.py index 04fb5b3..4febaa4 100755 --- a/bfilter.py +++ b/bfilter.py @@ -46,9 +46,9 @@ int bfilter_get(bit_array_t *, const char*, int); int getbit(bit_array_t *, int); """) -bfilter = lib.empty_bfilter(190) +bfilter = lib.empty_bfilter(1900) -k = 10 +k = 1 with open("./roadnottaken") as rnt: words = rnt.read().split(" ") @@ -56,7 +56,7 @@ with open("./roadnottaken") as rnt: lib.bfilter_set(bfilter, word.encode("UTF-8"), k) for word in words: - print(lib.bfilter_get(bfilter, word.encode("UTF-8"), k)) + lib.bfilter_get(bfilter, word.encode("UTF-8"), k) print(lib.bfilter_get(bfilter, b"wes", k)) diff --git a/bfilter.so b/bfilter.so index 1a3d503..07bdd86 100755 Binary files a/bfilter.so and b/bfilter.so differ