Skip to content

Commit

Permalink
quotient filter: merge test mismatch hash strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Jan 13, 2024
1 parent c1b8310 commit 7522c02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions probables/quotientfilter/quotientfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def merge(self, second: "QuotientFilter") -> None:
The hashing function between the two filters should match
Note:
Errors can occur if the quotient filter being inserted into does not expand (i.e., auto_expand=False)"""
if self._hash_func("test", 0) != second._hash_func("test", 0):
raise QuotientFilterError("Hash functions do not match")

for _h in second.hashes():
self.add_alt(_h)
Expand Down
9 changes: 9 additions & 0 deletions tests/quotientfilter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,12 @@ def test_qf_merge_error(self):
fq.add(str(i))

self.assertRaises(QuotientFilterError, lambda: qf.merge(fq))

# test mismatch hashes
def useless_hash(key, seed) -> int:
return 99999999

qq = QuotientFilter(quotient=8, hash_function=useless_hash)
qq.add("999")

self.assertRaises(QuotientFilterError, lambda: fq.merge(qq))

0 comments on commit 7522c02

Please sign in to comment.