May 2017
Intermediate to advanced
310 pages
8h 5m
English
The implementation of the get() method should return the value that corresponds to a key. We also have to decide what to do in the event that the key does not exist in the table. We start by calculating the hash of the key:
def get(self, key): h = self._hash(key)
Now, we simply start looking through the list for an element that has the key we are searching for, starting at the element which has the hash value of the key that was passed in. If the current element is not the correct one, then, just like in the put() method, we add one to the previous hash value and get the remainder of dividing this value by the size of the list. This becomes our new index. If we find an element that contains None, we stop looking. If we ...
Read now
Unlock full access