Skip to content

Commit 2c99889

Browse files
committed
resize_down: expected test result
1 parent 454eded commit 2c99889

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: data_structures/hashing/hash_map.py

+22
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ def __delitem__(self, key: KEY) -> None:
228228
Traceback (most recent call last):
229229
...
230230
KeyError: 4
231+
232+
# Test resize down when sparse
233+
## Setup: resize up
234+
>>> hm = HashMap(100, capacity_factor=0.75)
235+
>>> len(hm._buckets)
236+
100
237+
>>> for i in range(75):
238+
... hm[i] = i
239+
>>> len(hm._buckets)
240+
100
241+
>>> hm[75] = 75
242+
>>> len(hm._buckets)
243+
200
244+
245+
## Resize down
246+
>>> for i in range(38, 76):
247+
... del hm[i]
248+
>>> len(hm._buckets)
249+
200
250+
>>> del hm[37]
251+
>>> len(hm._buckets)
252+
100
231253
"""
232254
for ind in self._iterate_buckets(key):
233255
item = self._buckets[ind]

0 commit comments

Comments
 (0)