diff --git a/KuzminskiyAA/Task 1/Dogs/Data/1.py b/KuzminskiyAA/Task 1/Dogs/Data/1.py index f9d5525..a4bd2d2 100644 --- a/KuzminskiyAA/Task 1/Dogs/Data/1.py +++ b/KuzminskiyAA/Task 1/Dogs/Data/1.py @@ -46,4 +46,30 @@ def ll_list_all(head): while current: records.append((current['name'], current['phone'])) current = current['next'] + return sorted(records, key=lambda x: x[0]) +def hash_func(name, size): + return sum(ord(c) for c in name) % size + +def ht_create(size=1000): + return [None] * size + +def ht_insert(table, name, phone): + idx = hash_func(name, len(table)) + table[idx] = ll_insert(table[idx], name, phone) + +def ht_find(table, name): + idx = hash_func(name, len(table)) + return ll_find(table[idx], name) + +def ht_delete(table, name): + idx = hash_func(name, len(table)) + table[idx] = ll_delete(table[idx], name) + +def ht_list_all(table): + records = [] + for bucket in table: + current = bucket + while current: + records.append((current['name'], current['phone'])) + current = current['next'] return sorted(records, key=lambda x: x[0]) \ No newline at end of file