mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-31 14:43:43 +00:00
added types
This commit is contained in:
parent
2fd71965f1
commit
314237d94e
|
@ -72,14 +72,14 @@ class Bloom:
|
|||
self.size = size
|
||||
|
||||
def add(self, value: str) -> None:
|
||||
h = self.hash_(value)
|
||||
h = self.hash(value)
|
||||
self.bitarray |= h
|
||||
|
||||
def exists(self, value: str) -> bool:
|
||||
h = self.hash_(value)
|
||||
h = self.hash(value)
|
||||
return (h & self.bitarray) == h
|
||||
|
||||
def __contains__(self, other):
|
||||
def __contains__(self, other: str) -> bool:
|
||||
return self.exists(other)
|
||||
|
||||
def format_bin(self, bitarray: int) -> str:
|
||||
|
@ -87,10 +87,10 @@ class Bloom:
|
|||
return res.zfill(self.size)
|
||||
|
||||
@property
|
||||
def bitstring(self):
|
||||
def bitstring(self) -> None:
|
||||
return self.format_bin(self.bitarray)
|
||||
|
||||
def hash_(self, value: str) -> int:
|
||||
def hash(self, value: str) -> int:
|
||||
res = 0b0
|
||||
for func in HASH_FUNCTIONS:
|
||||
b = func(value.encode()).digest()
|
||||
|
@ -99,9 +99,9 @@ class Bloom:
|
|||
return res
|
||||
|
||||
def format_hash(self, value: str) -> str:
|
||||
return self.format_bin(self.hash_(value))
|
||||
return self.format_bin(self.hash(value))
|
||||
|
||||
def estimated_error_rate(self):
|
||||
def estimated_error_rate(self) -> float:
|
||||
n_ones = bin(self.bitarray).count("1")
|
||||
k = len(HASH_FUNCTIONS)
|
||||
return (n_ones / self.size) ** k
|
||||
|
|
Loading…
Reference in New Issue
Block a user