Skip to content

Added doctest to hash_map.py #11105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 4, 2023
Prev Previous commit
Next Next commit
Added doctest to hash_map.py
  • Loading branch information
Suyashd999 committed Oct 30, 2023
commit f103a4571469069e8257094cc1d8c93762e841f4
14 changes: 14 additions & 0 deletions data_structures/hashing/hash_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ def __getitem__(self, key: KEY) -> VAL:
raise KeyError(key)

def __len__(self) -> int:
"""
Returns the number of items present in hashmap

>>> hm = HashMap(5)
>>> hm._add_item(1, 10)
>>> hm._add_item(2, 20)
>>> hm._add_item(3, 30)
>>> hm.__len__()
3

>>> hm = HashMap(5)
>>> hm.__len__()
0
"""
return self._len

def __iter__(self) -> Iterator[KEY]:
Expand Down