diff --git a/probables/quotientfilter/quotientfilter.py b/probables/quotientfilter/quotientfilter.py index 5f70056..95e4392 100644 --- a/probables/quotientfilter/quotientfilter.py +++ b/probables/quotientfilter/quotientfilter.py @@ -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) diff --git a/tests/quotientfilter_test.py b/tests/quotientfilter_test.py index 602ad8d..7ce9dc7 100644 --- a/tests/quotientfilter_test.py +++ b/tests/quotientfilter_test.py @@ -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))