forked from UNN/2026-rff_mp
Удалить SmirnovaVYu/docs/data/hashtable.py
This commit is contained in:
parent
4071df31c4
commit
c4b3aa03af
|
|
@ -1,30 +0,0 @@
|
||||||
from linkedlist import ll_insert, ll_find, ll_delete, ll_list_all
|
|
||||||
|
|
||||||
|
|
||||||
def hash_function(name, size):
|
|
||||||
return sum(ord(c) for c in name) % size
|
|
||||||
|
|
||||||
def ht_create(size):
|
|
||||||
return [None] * size
|
|
||||||
|
|
||||||
def ht_insert(buckets, name, phone):
|
|
||||||
index = hash_function(name, len(buckets))
|
|
||||||
buckets[index] = ll_insert(buckets[index], name, phone)
|
|
||||||
|
|
||||||
def ht_find(buckets, name):
|
|
||||||
index = hash_function(name, len(buckets))
|
|
||||||
return ll_find(buckets[index], name)
|
|
||||||
|
|
||||||
def ht_delete(buckets, name):
|
|
||||||
index = hash_function(name, len(buckets))
|
|
||||||
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
|
|
||||||
Loading…
Reference in New Issue
Block a user