Created
April 29, 2019 18:23
-
-
Save edwintcloud/f755f317d4116d7db8f337dee99b40a1 to your computer and use it in GitHub Desktop.
Hash Table Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_items(self): | |
"""Return a list of tuples representing all the items in the HashTable""" | |
return [items.extend(slot.items()) for slot in self.slots] | |
def _resize(self): | |
""""Resize the HashTable by doubling the number of slots and rehashing all items""" | |
# get a list of all items in the hash table | |
items = self.get_items() | |
# reset size for hash table | |
self.size = 0 | |
# generate new slots of double current slots | |
self.slots = [LinkedList() for i in range(len(self.slots) * 2)] | |
# rehash each item | |
for key, value in items: | |
self.set(key, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment