Skip to content

Commit

Permalink
Merge pull request #30 from mizvyt/len_fix
Browse files Browse the repository at this point in the history
Reset Bloom filter length after clear_all (fixes #27)
  • Loading branch information
mizvyt authored Jan 31, 2020
2 parents eb15c1f + 4154d74 commit eda554a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/bloomfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/bloomfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/cbloomfilter.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/pybloomfilter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eda554a

Please sign in to comment.