diff --git a/src/bloom_filter/__init__.py b/src/bloom_filter/__init__.py index 0f3379c..4092527 100644 --- a/src/bloom_filter/__init__.py +++ b/src/bloom_filter/__init__.py @@ -3,12 +3,12 @@ from .bloom_filter import ( BloomFilter, - get_bitno_lin_comb, + get_filter_bitno_probes, get_bitno_seed_rnd, ) __all__ = [ 'BloomFilter', - 'get_bitno_lin_comb', + 'get_filter_bitno_probes', 'get_bitno_seed_rnd', ] diff --git a/src/bloom_filter/bloom_filter.py b/src/bloom_filter/bloom_filter.py index e16c952..d8ced40 100644 --- a/src/bloom_filter/bloom_filter.py +++ b/src/bloom_filter/bloom_filter.py @@ -465,7 +465,7 @@ def hash2(int_list): return simple_hash(int_list, MERSENNES2[0], MERSENNES2[1], MERSENNES2[2]) -def get_bitno_lin_comb(bloom_filter, key): +def get_filter_bitno_probes(bloom_filter, key): """Apply num_probes_k hash functions to key. Generate the array index and bitmask corresponding to each result""" # This one assumes key is either bytes or str (or other list of integers) @@ -487,11 +487,13 @@ def get_bitno_lin_comb(bloom_filter, key): hash_value1 = hash1(int_list) hash_value2 = hash2(int_list) + probe_value = hash_value1 - # We're using linear combinations of hash_value1 and hash_value2 to obtain num_probes_k hash functions for probeno in range(1, bloom_filter.num_probes_k + 1): - bit_index = hash_value1 + probeno * hash_value2 - yield bit_index % bloom_filter.num_bits_m + probe_value *= hash_value1 + probe_value += hash_value2 + probe_value %= MERSENNES1[2] + yield probe_value % bloom_filter.num_bits_m def try_unlink(filename): @@ -508,7 +510,7 @@ class BloomFilter(object): def __init__(self, max_elements=10000, error_rate=0.1, - probe_bitnoer=get_bitno_lin_comb, + probe_bitnoer=get_filter_bitno_probes, filename=None, start_fresh=False): # pylint: disable=R0913 diff --git a/tests/test_bloom_filter.py b/tests/test_bloom_filter.py index a94508c..0e4292f 100755 --- a/tests/test_bloom_filter.py +++ b/tests/test_bloom_filter.py @@ -39,14 +39,14 @@ def _test(description, values, trials, error_rate, probe_bitnoer=None, filename= # R0914: We want some local variables too. This is just test code. """Some quick automatic tests for the bloom filter class""" if not probe_bitnoer: - probe_bitnoer = bloom_filter.get_bitno_lin_comb + probe_bitnoer = bloom_filter.get_filter_bitno_probes all_good = True divisor = 100000 bloom = bloom_filter.BloomFilter( - max_elements=trials * 2, + max_elements=values.length() * 2, error_rate=error_rate, probe_bitnoer=probe_bitnoer, filename=filename, @@ -294,6 +294,7 @@ def test_bloom_filter(): all_good &= _test('states', States(), trials=100000, error_rate=0.01) all_good &= _test('random', Random_content(), trials=10000, error_rate=0.1) + all_good &= _test('random', Random_content(), trials=1000000, error_rate=1E-9) all_good &= _test('random', Random_content(), trials=10000, error_rate=0.1, probe_bitnoer=bloom_filter.get_bitno_seed_rnd)