Skip to content

Commit 314237d

Browse files
committed
added types
1 parent 2fd7196 commit 314237d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

data_structures/hashing/bloom_filter.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,25 @@ def __init__(self, size: int = 8) -> None:
7272
self.size = size
7373

7474
def add(self, value: str) -> None:
75-
h = self.hash_(value)
75+
h = self.hash(value)
7676
self.bitarray |= h
7777

7878
def exists(self, value: str) -> bool:
79-
h = self.hash_(value)
79+
h = self.hash(value)
8080
return (h & self.bitarray) == h
8181

82-
def __contains__(self, other):
82+
def __contains__(self, other: str) -> bool:
8383
return self.exists(other)
8484

8585
def format_bin(self, bitarray: int) -> str:
8686
res = bin(bitarray)[2:]
8787
return res.zfill(self.size)
8888

8989
@property
90-
def bitstring(self):
90+
def bitstring(self) -> None:
9191
return self.format_bin(self.bitarray)
9292

93-
def hash_(self, value: str) -> int:
93+
def hash(self, value: str) -> int:
9494
res = 0b0
9595
for func in HASH_FUNCTIONS:
9696
b = func(value.encode()).digest()
@@ -99,9 +99,9 @@ def hash_(self, value: str) -> int:
9999
return res
100100

101101
def format_hash(self, value: str) -> str:
102-
return self.format_bin(self.hash_(value))
102+
return self.format_bin(self.hash(value))
103103

104-
def estimated_error_rate(self):
104+
def estimated_error_rate(self) -> float:
105105
n_ones = bin(self.bitarray).count("1")
106106
k = len(HASH_FUNCTIONS)
107107
return (n_ones / self.size) ** k

0 commit comments

Comments
 (0)