Update (10/24): The tasks in this assignment are to extend the HashTable class that is currently defined in the file “hashtable.py” (located in MS Teams -> General -> Files -> Code). By extending it we will increase the functionality of the HashTable class (by adding more methods) and will make it more flexible (e.g. can resize itself as needed) and robust (e.g. no issues/errors when it is full and an item is added). The ways to extend the class, and thus the requirements for this assignment are as follows. 1. Override Python function to work with HashTable in a specific way – Using will override the Python function. The way this is implemented should be to return the number of items stored in the hash table (note: this is *not* the same as HashTable’s “size” field). 2. Override Python operator – This will be done using and should be implemented so this operator will then return a boolean when used in statements of the form . For this example, the function should return True if 54 is an existing key in the HashTable instance , and False if it is not. 3. Override Python operator – This is done by using and should allow for a key/value pair to be removed from an instance of HashTable (e.g. ). Think about how you want to handle cases when deleting a key that was involved with collisions. Be sure to include in the documentation for this method any assumptions/restrictions on how this can be used. 4. Modify exiting method to resize an instance as needed – The current HashTable implementation is limited in that it is not able to gracefully handle the case when an item is added to already full HashTable instance. This method should be modified to deal with this more gracefully, and should resize the instance for the user. Be sure to include documentation here describing exactly when you choose to resize and how you select an appropriate new size (remember that prime numbers are preferred for sizes, in order to avoid clustering, or an even more severe but subtle issue). All of those methods should be clearly documented to describe how and why the implementation is defined as it is. You will also want to use unittest on this assignment. One good u
se case for unittest will be to add a few items (and maybe even delete) one, and then to use unittest to verify that the slots and data fields are equal to what you expect. All of the extensions that you’ve added should be tested as well. Lastly, for grading, you will want to ensure that you’re program can be run through a test script. The test script will look like the code shown at bottom of this assignment description. When it is run we should expect output similar to what is shown in this screenshot. test_hashtable.py (the final test script will vary slightly from this): from <> import HashTable # instantiate a HashTable object h = HashTable(7) # store keys and values in the object h[6] = ‘cat’ h[11] = ‘dog’ h[21] = ‘bird’ h[27] = ‘horse’ print(“-“*10, “keys and values”, “-“*10) print(h.slots) print(h.data) # check that data was stored correctly print(“-“*10, “data check”, “-“*10) if h.data == [‘bird’, ‘horse’, None, None, ‘dog’, None, ‘cat’]: print(” + HashTable ‘put’ all items in correctly”) else: print(” – items NOT ‘put’ in correctly”) # check that ‘in’ operator works correctly print(“-“*10, “in operator”, “-“*10) if 27 in h: print(” + ‘in’ operator correctly implemented”) else: print(” – ‘in’ operator NOT working”) # delete operator del h[11] # check that len() function is implemented and works print(“-“*10, “len() function”, “-“*10) if len(h) == 3: print(” + ‘len’ function works properly”) else: print(” – ‘len’ function NOT working”) # “in” operator (returns a boolean) print(“-“*10, “len() after deletion”, “-“*10) if 11 not in h: print(” + ‘in’ operator works correctly after 11 was removed”) else: print(” – ‘in’ operator OR ‘del’ NOT working”) # check that data was also removed print(“-“*10, “data after deletion”, “-“*10) if h.data == [‘bird’, ‘horse’, None, None, None, None, ‘cat’]: print(” + data is correct after deletion”) else: print(” – data not correctly removed after deletion”)