Skip to content

Instantly share code, notes, and snippets.

@edwintcloud
Created April 29, 2019 18:23
Show Gist options
  • Save edwintcloud/f755f317d4116d7db8f337dee99b40a1 to your computer and use it in GitHub Desktop.
Save edwintcloud/f755f317d4116d7db8f337dee99b40a1 to your computer and use it in GitHub Desktop.
Hash Table Part 2
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