mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-03 13:28:40 +00:00
descriptive name for m
This commit is contained in:
parent
280ffa0564
commit
5d460aa79e
@ -14,7 +14,7 @@ class Bloom:
|
|||||||
self.bitstring = 0b0
|
self.bitstring = 0b0
|
||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
def add(self, value: str):
|
def add(self, value: str) -> None:
|
||||||
h = self.hash_(value)
|
h = self.hash_(value)
|
||||||
self.bitstring |= h
|
self.bitstring |= h
|
||||||
print(
|
print(
|
||||||
@ -70,18 +70,18 @@ def random_string(size: int) -> str:
|
|||||||
return "".join(choices(ascii_lowercase + " ", k=size))
|
return "".join(choices(ascii_lowercase + " ", k=size))
|
||||||
|
|
||||||
|
|
||||||
def test_probability(m: int = 64, n: int = 20) -> None:
|
def test_probability(bits: int = 64, n: int = 20) -> None:
|
||||||
b = Bloom(size=m)
|
b = Bloom(size=bits)
|
||||||
|
|
||||||
k = len(b.HASH_FUNCTIONS)
|
k = len(b.HASH_FUNCTIONS)
|
||||||
estimated_error_rate_beforehand = (1 - (1 - 1 / m) ** (k * n)) ** k
|
estimated_error_rate_beforehand = (1 - (1 - 1 / bits) ** (k * n)) ** k
|
||||||
|
|
||||||
added = {random_string(10) for i in range(n)}
|
added = {random_string(10) for i in range(n)}
|
||||||
for a in added:
|
for a in added:
|
||||||
b.add(a)
|
b.add(a)
|
||||||
|
|
||||||
n_ones = bin(b.bitstring).count("1")
|
n_ones = bin(b.bitstring).count("1")
|
||||||
estimated_error_rate = (n_ones / m) ** k
|
estimated_error_rate = (n_ones / bits) ** k
|
||||||
|
|
||||||
not_added = {random_string(10) for i in range(1000)}
|
not_added = {random_string(10) for i in range(1000)}
|
||||||
errors = 0
|
errors = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user