28 lines
815 B
Python
28 lines
815 B
Python
from codes.LL import ll_insert, ll_find, ll_delete
|
|
def ht_insert(buckets, name, phone):
|
|
index = hash(name) % len(buckets)
|
|
current_head = buckets[index]
|
|
new_head = ll_insert(current_head, name, phone)
|
|
buckets[index] = new_head
|
|
# print("-"*100)
|
|
# print(buskets)
|
|
|
|
def ht_find(buckets, name):
|
|
index = hash(name)%len(buckets)
|
|
slot_head = buckets[index]
|
|
res_ph = ll_find(slot_head, name)
|
|
return res_ph
|
|
|
|
def ht_delete(buskets, name):
|
|
index = hash(name)%len(buskets)
|
|
buskets[index] = ll_delete(buskets[index], name)
|
|
|
|
def ht_list_all(buckets):
|
|
all_rec = []
|
|
for head in buckets:
|
|
current = head
|
|
while current is not None:
|
|
all_rec.append((current['name'], current['phone']))
|
|
current = current['next']
|
|
all_rec.sort()
|
|
return all_rec |