diff --git a/VaravinVV/task1_1.py b/VaravinVV/task1_1.py index 204a936..06f4567 100644 --- a/VaravinVV/task1_1.py +++ b/VaravinVV/task1_1.py @@ -58,4 +58,42 @@ def ll_list_all(head): data_list.append({'name': current['name'], 'phone': current['phone']}) current = current['next'] data_list.sort(key=lambda x: x['name']) - return data_list \ No newline at end of file + return data_list + + +def hash_function(name, size): + return hash(name) % size + + +def ht_insert(buckets, name, phone): + index = hash_function(name, len(buckets)) + head = buckets[index] + new_head = ll_insert(head, name, phone) + buckets[index] = new_head + return buckets + + +def ht_find(buckets, name): + index = hash_function(name, len(buckets)) + head = buckets[index] + return ll_find(head, name) + + +def ht_delete(buckets, name): + index = hash_function(name, len(buckets)) + head = buckets[index] + new_head = ll_delete(head, name) + buckets[index] = new_head + return buckets + + +def ht_list_all(buckets): + all_records = [] + for head in buckets: + current = head + while current is not None: + all_records.append((current['name'], current['phone'])) + current = current['next'] + all_records.sort(key=lambda x: x[0]) + return all_records +