Last active
March 24, 2019 14:03
-
-
Save AdamGold/27f5be47c3c43eee55e205cacc755b87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 __setitem__(self, key: str, value: Any) -> int: | |
"""allow insertion of items with object[key] = value""" | |
entry = Entry(key, value) | |
index = entry.hash % self.actual_size | |
existing_entry = self.entries[index] | |
while existing_entry and not entry.compare_hash(existing_entry): | |
# don't overlap existing values | |
index = (index + 1) % self.actual_size | |
existing_entry = self.entries[index] | |
self.entries[index] = entry | |
return index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment