Aktualizovat u7/hash_table.py

This commit is contained in:
Oleksandr Mateshchuk 2026-10-27 14:01:52 +00:00
parent 267d6f5a1b
commit 0ae8311a91

View File

@ -1,10 +1,9 @@
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."""
if type(capacity) is not int: if type(capacity) is not int:
raise TypeError("Is not integer") raise TypeError("It's not integer")
if capacity <= 0: if capacity <= 0:
raise ValueError("Capacity > 0") raise ValueError("Capacity > 0")
@ -22,7 +21,7 @@ class HashTable:
def hash(self, key): def hash(self, key):
"""Vráť polynomiálny hash kľúča modulo aktuálna kapacita.""" """Vráť polynomiálny hash kľúča modulo aktuálna kapacita."""
if not isinstance(key, str): if not isinstance(key, str):
raise TypeError("Key - not string!") raise TypeError("Key must be a string")
h = 0 h = 0
for znak in key: for znak in key:
@ -59,7 +58,9 @@ class HashTable:
raise TypeError("Key must be a string") raise TypeError("Key must be a string")
def __len__(self): def __len__(self):
pass return self._size
def __iter__(self): def __iter__(self):
pass for item in self._table:
if item is not None and item is not self._DELETED:
yield item[0]