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