mirror of
https://codeberg.org/andyscott/HashMaps.git
synced 2024-12-21 12:33:10 -05:00
Added empty_map_put method to help with external find_mode function
This commit is contained in:
parent
9a53e5f27f
commit
52ff569178
1 changed files with 24 additions and 0 deletions
|
@ -72,6 +72,26 @@ class HashMap:
|
||||||
else:
|
else:
|
||||||
node.value = value
|
node.value = value
|
||||||
|
|
||||||
|
def empty_map_put(self, index_array, key: str, value: object) -> DynamicArray:
|
||||||
|
"""Alternative to put() with reduced time complexity for empty hash maps
|
||||||
|
|
||||||
|
Note that unlike put() this method allows duplicates for the purpose of
|
||||||
|
finding the mode and frequency of values added to the hash map.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
key : str
|
||||||
|
Indentifier for the given value
|
||||||
|
value : object
|
||||||
|
Value to add
|
||||||
|
"""
|
||||||
|
|
||||||
|
hash = self._hash_function(key)
|
||||||
|
index = hash % self._capacity
|
||||||
|
index_array.append(index)
|
||||||
|
self._buckets[index].insert(key, value)
|
||||||
|
return index_array
|
||||||
|
|
||||||
def empty_buckets(self) -> int:
|
def empty_buckets(self) -> int:
|
||||||
"""Gets the number of empty buckets in the hash table
|
"""Gets the number of empty buckets in the hash table
|
||||||
|
|
||||||
|
@ -224,6 +244,10 @@ def find_mode(da: DynamicArray) -> (DynamicArray, int):
|
||||||
# use this instance of your Separate Chaining HashMap
|
# use this instance of your Separate Chaining HashMap
|
||||||
map = HashMap(da.length() // 3, hash_function_1)
|
map = HashMap(da.length() // 3, hash_function_1)
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------- BASIC TESTING ---------------------------------------- #
|
# ------------------- BASIC TESTING ---------------------------------------- #
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue