This commit is contained in:
Vadym Afanasiev 2026-10-29 14:14:13 +00:00
parent 19572c7785
commit beb4e9e362

View File

@ -67,4 +67,28 @@ class HashTable:
key, value = slot
index = self.probe(key)
self.slots[index] = (key, value)
self.size += 1
self.size += 1
def __getitem__(self, key):
self._check_key(key)
idx = self.probe(key)
slot = self.slots[idx]
if slot is not self.empty and slot is not self.deleted and slot[0] == key:
return slot[1]
raise KeyError(key)
def __setitem__(self, key, value):
self._check_key(key)
idx = self.probe(key)
slot = self.slots[idx]
if slot is not self.empty and slot is not self.deleted and slot[0] == key:
self.slots[idx] = (key, value)
return
if (self._size + 1) / self.__capacity > 0.7:
self._resize()
idx = self.probe(key)
self.slots[idx] = (key, value)
self._size += 1