Implemented remove and get_keys methods

This commit is contained in:
Andrew Scott 2022-06-02 15:29:46 -04:00
parent 9e2217ab75
commit d0caad7862
Signed by: a
GPG key ID: 3EB62D0BBB8DB381

View file

@ -185,16 +185,35 @@ class HashMap:
def remove(self, key: str) -> None: def remove(self, key: str) -> None:
"""Removes a key/value pair from the hash map
Parameters
----------
key : str
Key to look up in the hash map
""" """
TODO: Write this implementation
""" hash = self._hash_function(key)
pass index = hash % self._capacity
is_removed = self._buckets[index].remove(key)
if is_removed:
self._size -= 1
def get_keys(self) -> DynamicArray: def get_keys(self) -> DynamicArray:
"""Get an array that contains all the keys in the hash map
Returns
-------
DynamicArray
Array containing the hash maps keys
""" """
TODO: Write this implementation
""" keys = DynamicArray()
pass for i in range(self._capacity):
linked_list = self._buckets[i]
for node in linked_list:
keys.append(node.key)
return keys
def find_mode(da: DynamicArray) -> (DynamicArray, int): def find_mode(da: DynamicArray) -> (DynamicArray, int):