From 4154d7402ab7f10bbc6250244f82a16dcace524b Mon Sep 17 00:00:00 2001 From: mizvyt Date: Tue, 14 Jan 2020 10:13:11 +0800 Subject: [PATCH] Reset Bloom filter length after clear_all (fixes #27) --- src/bloomfilter.c | 13 +++++++++++++ src/bloomfilter.h | 2 +- src/cbloomfilter.pxd | 1 + src/pybloomfilter.pyx | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bloomfilter.c b/src/bloomfilter.c index 82ecd14..cd89d18 100644 --- a/src/bloomfilter.c +++ b/src/bloomfilter.c @@ -41,6 +41,7 @@ BloomFilter *bloomfilter_Create_Malloc(size_t max_num_elem, double error_rate, return bf; } + BloomFilter *bloomfilter_Create_Mmap(size_t max_num_elem, double error_rate, const char * file, BTYPE num_bits, int oflags, int perms, int *hash_seeds, int num_hashes) @@ -108,6 +109,7 @@ void bloomfilter_Print(BloomFilter * bf) (unsigned long)bf->max_num_elem, bf->error_rate, bf->num_hashes); } + int bloomfilter_Update(BloomFilter * bf, char * data, int size) { MBArray * array = bf->array; @@ -123,6 +125,17 @@ int bloomfilter_Update(BloomFilter * bf, char * data, int size) } +int bloomfilter_Clear(BloomFilter * bf) +{ + int retval = mbarray_ClearAll(bf->array); + if (retval) { + return retval; + } + bf->elem_count = 0; + return 0; +} + + BloomFilter * bloomfilter_Copy_Template(BloomFilter * src, char * filename, int perms) { BloomFilter * bf = (BloomFilter *)malloc(sizeof(BloomFilter)); diff --git a/src/bloomfilter.h b/src/bloomfilter.h index 9a13d68..e974c58 100644 --- a/src/bloomfilter.h +++ b/src/bloomfilter.h @@ -36,8 +36,8 @@ BloomFilter *bloomfilter_Create_Mmap(size_t max_num_elem, double error_rate, int *hash_seeds, int num_hashes); void bloomfilter_Destroy(BloomFilter * bf); - int bloomfilter_Update(BloomFilter * bf, char * data, int size); +int bloomfilter_Clear(BloomFilter * bf); BloomFilter * bloomfilter_Copy_Template(BloomFilter * src, char * filename, int perms); diff --git a/src/cbloomfilter.pxd b/src/cbloomfilter.pxd index 0aa0395..3d20b30 100644 --- a/src/cbloomfilter.pxd +++ b/src/cbloomfilter.pxd @@ -52,4 +52,5 @@ cdef extern from "bloomfilter.h": int bloomfilter_Add(BloomFilter * bf, Key * key) int bloomfilter_Test(BloomFilter * bf, Key * key) int bloomfilter_Update(BloomFilter * bf, char * data, int size) + int bloomfilter_Clear(BloomFilter * bf) BloomFilter * bloomfilter_Copy_Template(BloomFilter * src, char * filename, int perms) diff --git a/src/pybloomfilter.pyx b/src/pybloomfilter.pyx index e702dc9..adde0eb 100644 --- a/src/pybloomfilter.pyx +++ b/src/pybloomfilter.pyx @@ -308,7 +308,7 @@ cdef class BloomFilter: """Removes all elements from the Bloom filter at once.""" self._assert_open() self._assert_writable() - cbloomfilter.mbarray_ClearAll(self._bf.array) + cbloomfilter.bloomfilter_Clear(self._bf) def __contains__(self, item_): """Checks to see if item is contained in the filter, with