Skip to content
Browse files

Added access to the keys that a bloom filter uses, if it has been sha…

…rded among multiple keys
  • Loading branch information...
1 parent 21a233f commit 19cca48661f316d8087641cee4a80d765e9fd7dc Dan Lecocq committed
Showing with 877 additions and 449 deletions.
  1. +3 −3 pyreBloom/bloom.c
  2. +1 −0 pyreBloom/bloom.h
  3. +1 −0 pyreBloom/bloom.pxd
  4. +864 −446 pyreBloom/pyreBloom.c
  5. +4 −0 pyreBloom/pyreBloom.pyx
  6. +4 −0 test/accuracy.py
View
6 pyreBloom/bloom.c
@@ -42,10 +42,10 @@ int init_pyrebloom(pyrebloomctxt * ctxt, char * key, uint32_t capacity, double e
strncpy(ctxt->password, password, strlen(password));
/* We'll need a certain number of strings here */
- uint32_t num_keys = (uint32_t)(
+ ctxt->num_keys = (uint32_t)(
ceil((float)(ctxt->bits) / max_bits_per_key));
- ctxt->keys = (char**)(malloc(num_keys * sizeof(char*)));
- for (i = 0; i < num_keys; ++i) {
+ ctxt->keys = (char**)(malloc(ctxt->num_keys * sizeof(char*)));
+ for (i = 0; i < ctxt->num_keys; ++i) {
ctxt->keys[i] = (char*)(malloc(strlen(key) + 10));
sprintf(ctxt->keys[i], "%s.%i", key, i);
}
View
1 pyreBloom/bloom.h
@@ -31,6 +31,7 @@
typedef struct {
uint32_t capacity;
uint32_t hashes;
+ uint32_t num_keys;
uint64_t bits;
double error;
uint32_t * seeds;
View
1 pyreBloom/bloom.pxd
@@ -33,6 +33,7 @@ cdef extern from "bloom.h":
ctypedef struct pyrebloomctxt:
uint32_t capacity
uint32_t hashes
+ uint32_t num_keys
uint64_t bits
double error
uint32_t * seeds
View
1,310 pyreBloom/pyreBloom.c
864 additions, 446 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
4 pyreBloom/pyreBloom.pyx
@@ -89,3 +89,7 @@ cdef class pyreBloom(object):
def __contains__(self, value):
return self.contains(value)
+
+ def keys(self):
+ '''Return a list of the keys used in this bloom filter'''
+ return [self.context.keys[i] for i in range(self.context.num_keys)]
View
4 test/accuracy.py
@@ -45,6 +45,10 @@ def test_size_allocation(self):
self.assertLess(
false_rate, 0.00001, 'False positive error rate exceeded!')
+ # We also need to know that we can access all the keys we need
+ self.assertEqual(self.bloom.keys(),
+ ['pyreBloomTesting.0', 'pyreBloomTesting.1'])
+
def test_delete(self):
'''Make sure that when we delete the bloom filter, we really do'''
samples = sample_strings(20, 5000)

0 comments on commit 19cca48

Please sign in to comment.
Something went wrong with that request. Please try again.