from LinkedList import ll_insert, ll_find, ll_delete, ll_list_all

def create_ht(size = 1000):
    return[None] * size

def hash_function(name, size = 1000): 
    value = 0
    for char in name:
        value = (value * 31 + ord(char)) % size
    return value

def ht_insert(buckets, name, phone):
    index = hash_function(name, len(buckets))
    buckets[index] = ll_insert(buckets[index], name, phone)
    return buckets

def ht_delete(buckets, name): 
    index = hash_function(name, len(buckets))
    buckets[index] = ll_delete(buckets[index], name)
    return buckets

def ht_find(buckets, name):
    index = hash_function(name, len(buckets))
    return ll_find(buckets[index], name)

def ht_list_all(buckets):
    records = []
    for bucket in buckets:
        if buckets is not None:
            records.extend(ll_list_all(buckets))