mirror of
https://codeberg.org/andyscott/HashMaps.git
synced 2024-12-21 12:33:10 -05:00
Implemented remove and get_keys methods
This commit is contained in:
parent
9e2217ab75
commit
d0caad7862
1 changed files with 25 additions and 6 deletions
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue