diff --git a/src/okbloomer/bloom_filter.py b/src/okbloomer/bloom_filter.py index 4fa1ba0..18c22d3 100644 --- a/src/okbloomer/bloom_filter.py +++ b/src/okbloomer/bloom_filter.py @@ -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) diff --git a/tests/test_bloom_filter.py b/tests/test_bloom_filter.py index 0e0b767..00922da 100644 --- a/tests/test_bloom_filter.py +++ b/tests/test_bloom_filter.py @@ -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)