mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-04 13:58:39 +00:00
again hash_
This commit is contained in:
parent
314237d94e
commit
9b014721e4
@ -72,11 +72,11 @@ class Bloom:
|
|||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
def add(self, value: str) -> None:
|
def add(self, value: str) -> None:
|
||||||
h = self.hash(value)
|
h = self.hash_(value)
|
||||||
self.bitarray |= h
|
self.bitarray |= h
|
||||||
|
|
||||||
def exists(self, value: str) -> bool:
|
def exists(self, value: str) -> bool:
|
||||||
h = self.hash(value)
|
h = self.hash_(value)
|
||||||
return (h & self.bitarray) == h
|
return (h & self.bitarray) == h
|
||||||
|
|
||||||
def __contains__(self, other: str) -> bool:
|
def __contains__(self, other: str) -> bool:
|
||||||
@ -87,10 +87,10 @@ class Bloom:
|
|||||||
return res.zfill(self.size)
|
return res.zfill(self.size)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bitstring(self) -> None:
|
def bitstring(self) -> str:
|
||||||
return self.format_bin(self.bitarray)
|
return self.format_bin(self.bitarray)
|
||||||
|
|
||||||
def hash(self, value: str) -> int:
|
def hash_(self, value: str) -> int:
|
||||||
res = 0b0
|
res = 0b0
|
||||||
for func in HASH_FUNCTIONS:
|
for func in HASH_FUNCTIONS:
|
||||||
b = func(value.encode()).digest()
|
b = func(value.encode()).digest()
|
||||||
@ -99,7 +99,7 @@ class Bloom:
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def format_hash(self, value: str) -> str:
|
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) -> float:
|
def estimated_error_rate(self) -> float:
|
||||||
n_ones = bin(self.bitarray).count("1")
|
n_ones = bin(self.bitarray).count("1")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user