collision resolution. In this exercise you will implement a hash table that uses separate chaining for collision resolution. The hash table will contain key-data pairs. You can assume that keys will be integer values and data strings. Your hash table class will be called ChainingHashTable. The constructor for this class will take one parameter, the size of the table. Three instance variables will be initialized: 1. 2. 3. size - the size of the hash table count- the number of items in the hash table slots - a python list with size number of elements. Each element is an ordered linked list. The implementation of the ordered list including its iterator have been discussed in lectures and have been provided as assignment resources. As you are now dealing with two values, a key and its associated data, you will need to make slight modifications to the provided ordered list code: Modify the provided Node class so that it stores both the key and the data in addition to a reference to the next node. You should also provide the appropriate get and set functions for these instance variables. Modify the provided OrderList class so that the add, search and remove functions use the key the node stores, not its data. Modify the provided LiskedListIterator class so that when each node in the list is visited, a tuple containing the key-data pair is returned. . For the ChainingHashTable class you will need to implement the following functions: key) and-getitem (self, key) get (self, . put (self, key, value) and setitem (self, key, value) . delete (self, key) and delitem (self, key) len (self) contains(self, key) --str(self)
class ChainingHashTable:
def __init__(self, arraySize): # Declaring variables
self._slots = [] #list of slots with data as member variable of the list
self._size = arraySize
self._count = 0
for j in xrange(self._size): #fill list
self._slots.append(SortedList())
def hashfunction(self,key,arraySize):
return key% arraySize
def put(self,key,data):
hashvalue = self.hashfunction(key,len(self.slots))
self.slots[hashvalue].data = data
def get(self,key):
hashvalue = self.hashfunction(key,len(self.slots))
data = self._hashArray[hashvalue].data #get data
return data #return data
def __getitem__(self,key):
return self.get(key)
def __setitem__(self,key,data):
self.put(key,data)
def __len__(self):
return(len(self.slots))