This commit is contained in:
Marege 2026-10-29 22:19:29 +01:00
parent d5fa465a37
commit b6da8ca1cb

View File

@ -8,11 +8,11 @@ class HashTable:
raise TypeError("kapacita ma byt cele cislo")
if capacity <= 0:
raise ValueError("kapacita ma byt + a cela")
self.empty = object()
self.deleted = object()
self.empty = object()# позначка що позиція ніколи не використовувалась
self.deleted = object() # позначка шо тут був елемент, його видалили
self._capacity = capacity
self.size = 0
self.table = []
self.table = []# саме сховище позицій
for i in range(capacity):
self.table.append(self.empty)
@ -38,12 +38,12 @@ class HashTable:
del_slot = None
while i < self.capacity:
index = (self.hash(key) + i) % self.capacity
if self.table[index] is self.empty:
if self.table[index] is self.empty: # Дійшли до порожнього місця: ключа в таблиці точно нема
if del_slot is None:
return index
else:
return del_slot
elif self.table[index] is self.deleted:
elif self.table[index] is self.deleted: # Видалений слот: запам'ятовуємо лише перший і йдемо далі
if del_slot is None:
del_slot = index