Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5d460aa

Browse files
committed
descriptive name for m
1 parent 280ffa0 commit 5d460aa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

data_structures/hashing/bloom_filter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, size: int = 8) -> None:
1414
self.bitstring = 0b0
1515
self.size = size
1616

17-
def add(self, value: str):
17+
def add(self, value: str) -> None:
1818
h = self.hash_(value)
1919
self.bitstring |= h
2020
print(
@@ -70,18 +70,18 @@ def random_string(size: int) -> str:
7070
return "".join(choices(ascii_lowercase + " ", k=size))
7171

7272

73-
def test_probability(m: int = 64, n: int = 20) -> None:
74-
b = Bloom(size=m)
73+
def test_probability(bits: int = 64, n: int = 20) -> None:
74+
b = Bloom(size=bits)
7575

7676
k = len(b.HASH_FUNCTIONS)
77-
estimated_error_rate_beforehand = (1 - (1 - 1 / m) ** (k * n)) ** k
77+
estimated_error_rate_beforehand = (1 - (1 - 1 / bits) ** (k * n)) ** k
7878

7979
added = {random_string(10) for i in range(n)}
8080
for a in added:
8181
b.add(a)
8282

8383
n_ones = bin(b.bitstring).count("1")
84-
estimated_error_rate = (n_ones / m) ** k
84+
estimated_error_rate = (n_ones / bits) ** k
8585

8686
not_added = {random_string(10) for i in range(1000)}
8787
errors = 0

0 commit comments

Comments
 (0)