Просмотр исходного кода

Rename BloomFilter(ideal_num_elements_n, error_rate_p, ...) =>
BloomFilter(max_elements, error_rate, ...)

Harshad Sharma 8 лет назад
Родитель
Сommit
35265f75cc
2 измененных файлов с 16 добавлено и 13 удалено
  1. 10 7
      src/bloom_filter/bloom_filter.py
  2. 6 6
      tests/test_bloom_filter.py

+ 10 - 7
src/bloom_filter/bloom_filter.py

@@ -502,20 +502,23 @@ def try_unlink(filename):
 
 class BloomFilter(object):
     """Probabilistic set membership testing for large sets"""
-
-    #def __init__(self, ideal_num_elements_n, error_rate_p, probe_offsetter=get_index_bitmask_seed_rnd):
-    def __init__(self, ideal_num_elements_n, error_rate_p, probe_bitnoer=get_bitno_lin_comb, filename=None, start_fresh=False):
+    def __init__(self,
+                 max_elements=10000,
+                 error_rate=0.1,
+                 probe_bitnoer=get_bitno_lin_comb,
+                 filename=None,
+                 start_fresh=False):
         # pylint: disable=R0913
         # R0913: We want a few arguments
-        if ideal_num_elements_n <= 0:
+        if max_elements <= 0:
             raise ValueError('ideal_num_elements_n must be > 0')
-        if not (0 < error_rate_p < 1):
+        if not (0 < error_rate < 1):
             raise ValueError('error_rate_p must be between 0 and 1 exclusive')
 
-        self.error_rate_p = error_rate_p
+        self.error_rate_p = error_rate
         # With fewer elements, we should do very well.  With more elements, our error rate "guarantee"
         # drops rapidly.
-        self.ideal_num_elements_n = ideal_num_elements_n
+        self.ideal_num_elements_n = max_elements
 
         numerator = -1 * self.ideal_num_elements_n * math.log(self.error_rate_p)
         denominator = math.log(2) ** 2

+ 6 - 6
tests/test_bloom_filter.py

@@ -46,8 +46,8 @@ def _test(description, values, trials, error_rate, probe_bitnoer=None, filename=
     divisor = 100000
 
     bloom = bloom_filter.BloomFilter(
-        ideal_num_elements_n=trials * 2,
-        error_rate_p=error_rate,
+        max_elements=trials * 2,
+        error_rate=error_rate,
         probe_bitnoer=probe_bitnoer,
         filename=filename,
         start_fresh=True,
@@ -206,11 +206,11 @@ def and_test():
 
     all_good = True
 
-    abc = bloom_filter.BloomFilter(ideal_num_elements_n=100, error_rate_p=0.01)
+    abc = bloom_filter.BloomFilter(max_elements=100, error_rate=0.01)
     for character in ['a', 'b', 'c']:
         abc += character
 
-    bcd = bloom_filter.BloomFilter(ideal_num_elements_n=100, error_rate_p=0.01)
+    bcd = bloom_filter.BloomFilter(max_elements=100, error_rate=0.01)
     for character in ['b', 'c', 'd']:
         bcd += character
 
@@ -238,11 +238,11 @@ def or_test():
 
     all_good = True
 
-    abc = bloom_filter.BloomFilter(ideal_num_elements_n=100, error_rate_p=0.01)
+    abc = bloom_filter.BloomFilter(max_elements=100, error_rate=0.01)
     for character in ['a', 'b', 'c']:
         abc += character
 
-    bcd = bloom_filter.BloomFilter(ideal_num_elements_n=100, error_rate_p=0.01)
+    bcd = bloom_filter.BloomFilter(max_elements=100, error_rate=0.01)
     for character in ['b', 'c', 'd']:
         bcd += character