Skip to content

Instantly share code, notes, and snippets.

@AdamGold
Last active March 24, 2019 14:03
Show Gist options
  • Save AdamGold/27f5be47c3c43eee55e205cacc755b87 to your computer and use it in GitHub Desktop.
Save AdamGold/27f5be47c3c43eee55e205cacc755b87 to your computer and use it in GitHub Desktop.
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