From 52ff56917815310fc9d384d40cc4b07ff8fb38a1 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 2 Jun 2022 18:31:53 -0400 Subject: [PATCH] Added empty_map_put method to help with external find_mode function --- hash_map_sc.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hash_map_sc.py b/hash_map_sc.py index ba89a66..0adcd65 100644 --- a/hash_map_sc.py +++ b/hash_map_sc.py @@ -72,6 +72,26 @@ class HashMap: else: 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: """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 map = HashMap(da.length() // 3, hash_function_1) + pass + + + # ------------------- BASIC TESTING ---------------------------------------- #