From 5ed12f966f7eed07ecfd6bc8ee92881c2337a3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=20=D0=9C=D0=B0?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D0=B9?= Date: Thu, 16 Apr 2026 01:50:52 +0300 Subject: [PATCH] =?UTF-8?q?[1]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=85=D1=8D=D1=88=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BorisovMI/lab_1/docs/data/structures.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/BorisovMI/lab_1/docs/data/structures.py b/BorisovMI/lab_1/docs/data/structures.py index 2568a2a..de369ca 100644 --- a/BorisovMI/lab_1/docs/data/structures.py +++ b/BorisovMI/lab_1/docs/data/structures.py @@ -63,4 +63,42 @@ def ll_list_all(head): records.append((current['name'], current['phone'])) current = current['next'] records.sort(key=lambda x: x[0]) + return records + +# Хэш функции + +def hash_function(name, table_size): + return sum(ord(c) for c in name) % table_size + + +def ht_create(size=1000): + return [None] * size + + +def ht_insert(buckets, name, phone): + size = len(buckets) + index = hash_function(name, size) + buckets[index] = ll_insert(buckets[index], name, phone) + + +def ht_find(buckets, name): + size = len(buckets) + index = hash_function(name, size) + return ll_find(buckets[index], name) + + +def ht_delete(buckets, name): + size = len(buckets) + index = hash_function(name, size) + buckets[index] = ll_delete(buckets[index], name) + + +def ht_list_all(buckets): + records = [] + for bucket in buckets: + current = bucket + while current is not None: + records.append((current['name'], current['phone'])) + current = current['next'] + records.sort(key=lambda x: x[0]) return records \ No newline at end of file