Aktualizovat u7/hash_table.py

This commit is contained in:
Oleksandr Mateshchuk 2026-10-27 14:04:58 +00:00
parent 0ae8311a91
commit 961d49c532

View File

@ -1,4 +1,3 @@
class HashTable: class HashTable:
def __init__(self, capacity=10): def __init__(self, capacity=10):
"""Vytvor prázdnu tabuľku s kladnou celočíselnou kapacitou.""" """Vytvor prázdnu tabuľku s kladnou celočíselnou kapacitou."""
@ -57,6 +56,17 @@ class HashTable:
if not isinstance(key, str): if not isinstance(key, str):
raise TypeError("Key must be a string") raise TypeError("Key must be a string")
try:
index = self.probe(key)
except RuntimeError:
return False
item = self._table[index]
return (
item is not None
and item is not self._DELETED
and item[0] == key
)
def __len__(self): def __len__(self):
return self._size return self._size