вычисление индекса, начало хеш таблицы

This commit is contained in:
volkovva 2026-05-23 19:22:09 +03:00
parent 238245c512
commit 759c0eab91

View File

@ -1,5 +1,5 @@
import random as rnd
<<<<<<< HEAD
def ll_insert(head, name, phone):
new_node = {'name': name, 'phone': phone, 'next': None}
@ -61,5 +61,21 @@ def ll_list_all(head):
current = current['next']
res = sort_records(record)
return res
=======
>>>>>>> 221b0dbe36c30826c59c8721814c9bb881eafeee
def def_hash(name, size):
hash_value = 0
for char in name:
hash_value += ord(char)
final_idx = hash_value % size
return final_idx
def ht_insert(buckets, name, phone):
size = len(buckets)
idx = def_hash(name, size)
ll_insert(buckets[idx], name, phone)