Skip to content

Commit 4b78cf3

Browse files
committed
Add missed annotations
1 parent 13c1963 commit 4b78cf3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: data_structures/hashing/hash_map.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class _Item(Generic[KEY, VAL]):
2222

2323

2424
class _DeletedItem(_Item):
25-
def __init__(self):
25+
def __init__(self) -> None:
2626
super().__init__(None, None)
2727

28-
def __bool__(self):
28+
def __bool__(self) -> bool:
2929
return False
3030

3131

@@ -37,7 +37,9 @@ class HashMap(MutableMapping[KEY, VAL]):
3737
Hash map with open addressing.
3838
"""
3939

40-
def __init__(self, initial_block_size: int = 8, capacity_factor: float = 0.75):
40+
def __init__(
41+
self, initial_block_size: int = 8, capacity_factor: float = 0.75
42+
) -> None:
4143
self._initial_block_size = initial_block_size
4244
self._buckets: list[_Item | None] = [None] * initial_block_size
4345
assert 0.0 < capacity_factor < 1.0
@@ -75,7 +77,7 @@ def _try_set(self, ind: int, key: KEY, val: VAL) -> bool:
7577
else:
7678
return False
7779

78-
def _is_full(self):
80+
def _is_full(self) -> bool:
7981
"""
8082
Return true if we have reached safe capacity.
8183
@@ -84,25 +86,25 @@ def _is_full(self):
8486
limit = len(self._buckets) * self._capacity_factor
8587
return len(self) >= int(limit)
8688

87-
def _is_sparse(self):
89+
def _is_sparse(self) -> bool:
8890
"""Return true if we need twice fewer buckets when we have now."""
8991
if len(self._buckets) <= self._initial_block_size:
9092
return False
9193
limit = len(self._buckets) * self._capacity_factor / 2
9294
return len(self) < limit
9395

94-
def _resize(self, new_size: int):
96+
def _resize(self, new_size: int) -> None:
9597
old_buckets = self._buckets
9698
self._buckets = [None] * new_size
9799
self._len = 0
98100
for item in old_buckets:
99101
if item:
100102
self._add_item(item.key, item.val)
101103

102-
def _size_up(self):
104+
def _size_up(self) -> None:
103105
self._resize(len(self._buckets) * 2)
104106

105-
def _size_down(self):
107+
def _size_down(self) -> None:
106108
self._resize(len(self._buckets) // 2)
107109

108110
def _iterate_buckets(self, key: KEY) -> Iterator[int]:
@@ -111,7 +113,7 @@ def _iterate_buckets(self, key: KEY) -> Iterator[int]:
111113
yield ind
112114
ind = self._get_next_ind(ind)
113115

114-
def _add_item(self, key: KEY, val: VAL):
116+
def _add_item(self, key: KEY, val: VAL) -> None:
115117
for ind in self._iterate_buckets(key):
116118
if self._try_set(ind, key, val):
117119
break

0 commit comments

Comments
 (0)