Skip to content

Commit

Permalink
Nevermind
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Oct 29, 2024
1 parent e3e96c1 commit 8ecb28f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
28 changes: 0 additions & 28 deletions src/okbloomer/bloom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,6 @@ def false_positive_rate(self) -> float:
"""Return the estimated probability of recording a false positive."""
return self.utilization**self._num_hashes

def merge(self, filter: Self) -> None:
"""Merge this filter with another filter."""
if self._num_hashes != filter.num_hashes:
raise ValueError("Filters must have the same number of hash functions.")

if self._layer_size != filter.layer_size:
raise ValueError("Filters must have the same layer size.")

combined_false_positive_rate = self.false_positive_rate + filter.false_positive_rate

can_combine_heads = combined_false_positive_rate < self.max_false_positive_rate

a, b = self._layers.pop(), filter.layers.pop()

layers = self._layers + filter.layers

if can_combine_heads:
layer = np.bitwise_or(a, b)

layers.append(layer)

else:
layers.extend([a, b])

self._layers = layers
self._n += filter.n
self._m = len(layers) * self.layer_size

def insert(self, token: str) -> None:
"""Insert a token into the filter"""
offsets = self._hash(token)
Expand Down
29 changes: 0 additions & 29 deletions tests/test_bloom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,3 @@ def test_autoscaling(self):
self.assertLessEqual(filter.false_positive_rate, 0.001)
self.assertLessEqual(filter.utilization, 1.0)
self.assertGreater(filter.capacity, 0.0)

def test_merge(self):
a = BloomFilter()
b = BloomFilter()

a.insert('foo')
a.insert('bar')

b.insert('baz')
b.insert('qux')

self.assertTrue(a.exists("foo"))
self.assertTrue(a.exists("bar"))
self.assertFalse(a.exists("baz"))
self.assertFalse(a.exists("qux"))

self.assertFalse(b.exists("foo"))
self.assertFalse(b.exists("bar"))
self.assertTrue(b.exists("baz"))
self.assertTrue(b.exists("qux"))

a.merge(b)

self.assertTrue(a.exists("foo"))
self.assertTrue(a.exists("bar"))
self.assertTrue(a.exists("baz"))
self.assertTrue(a.exists("qux"))

self.assertEqual(a.num_layers, 1)

0 comments on commit 8ecb28f

Please sign in to comment.