From 41433c287aa10f66d850977c5d5c5deac2c27514 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 24 May 2026 23:44:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A5=D0=B5=D1=88-=D1=82=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KuzminskiyAA/Task 1/Dogs/Data/1.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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