Skip to content

Instantly share code, notes, and snippets.

@AdamGold
Last active March 24, 2019 15:15
Show Gist options
  • Save AdamGold/8b2db46eca75327a97b9cace21d1d2e1 to your computer and use it in GitHub Desktop.
Save AdamGold/8b2db46eca75327a97b9cace21d1d2e1 to your computer and use it in GitHub Desktop.
def __getitem__(self, key: str) -> Entry:
"""subscript method - object[key]
use hashing function to find the index"""
entry = Entry(key)
index = entry.hash % self.actual_size
found = self.entries[index]
while found and not entry.compare_hash(found):
index = (index + 1) % self.actual_size
found = self.entries[index]
if found == None:
raise KeyError
return found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment