message
This commit is contained in:
parent
beb4e9e362
commit
50c17e59ef
@ -92,3 +92,28 @@ class HashTable:
|
||||
|
||||
self.slots[idx] = (key, value)
|
||||
self._size += 1
|
||||
def __delitem__(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:
|
||||
self.slots[idx] = self.deleted
|
||||
self._size -= 1
|
||||
else:
|
||||
raise KeyError(key)
|
||||
|
||||
def __contains__(self, key):
|
||||
self._check_key(key)
|
||||
idx = self.probe(key)
|
||||
slot = self.slots[idx]
|
||||
return slot is not self.empty and slot is not self.deleted and slot[0] == key
|
||||
|
||||
def __len__(self):
|
||||
return self._size
|
||||
|
||||
def __iter__(self):
|
||||
for slot in self.slots:
|
||||
if slot is not self.empty and slot is not self.deleted:
|
||||
yield slot[0]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user