diff --git a/KislyuninED/docks/data/1-st-exercize/main.py b/KislyuninED/docks/data/1-st-exercize/main.py index d86f523..1b05cd1 100644 --- a/KislyuninED/docks/data/1-st-exercize/main.py +++ b/KislyuninED/docks/data/1-st-exercize/main.py @@ -43,4 +43,42 @@ def ll_list_all(head): records.append((curr['n'], curr['p'])) curr = curr['nxt'] records.sort(key=lambda x: x[0]) - return records \ No newline at end of file + return records + + + +# хеш-функция – сумма ord(name) % size +def _hash(name, size): + h = 0 + for ch in name: + h += ord(ch) + return h % size + +SIZE = 13 # фиксированный размер таблицы + +def ht_create(): + return [None] * SIZE + +def ht_insert(buckets, name, phone): + idx = _hash(name, len(buckets)) + buckets[idx] = ll_insert(buckets[idx], name, phone) + return buckets + +def ht_find(buckets, name): + idx = _hash(name, len(buckets)) + return ll_find(buckets[idx], name) + +def ht_delete(buckets, name): + idx = _hash(name, len(buckets)) + buckets[idx] = ll_delete(buckets[idx], name) + return buckets + +def ht_list_all(buckets): + all_records = [] + for head in buckets: + curr = head + while curr: + all_records.append((curr['n'], curr['p'])) + curr = curr['nxt'] + all_records.sort(key=lambda x: x[0]) + return all_records \ No newline at end of file