forked from UNN/2026-rff_mp
Compare commits
2 Commits
057c7188bd
...
242abe433d
| Author | SHA1 | Date | |
|---|---|---|---|
| 242abe433d | |||
| edcc503f46 |
|
|
@ -117,3 +117,43 @@ print("====== TESTING ll_list_all FUNC ======")
|
||||||
print(ll_list_all(head))
|
print(ll_list_all(head))
|
||||||
|
|
||||||
print("====== END ======")
|
print("====== END ======")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SIZE = 5
|
||||||
|
buckets = [None] * SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
print(f"\n\n\n ====== TEST INSERT HASH ======")
|
||||||
|
print(buckets)
|
||||||
|
ht_insert(buckets, "Ivan", "123-456")
|
||||||
|
print(buckets)
|
||||||
|
ht_insert(buckets, "Dima", "789-123")
|
||||||
|
print(buckets)
|
||||||
|
ht_insert(buckets, "Boris", "456-789")
|
||||||
|
print(buckets)
|
||||||
|
print("====== END TEST ======\n\n\n")
|
||||||
|
|
||||||
|
|
||||||
|
def ht_find(buckets, name):
|
||||||
|
index = hash_function(name, len(buckets))
|
||||||
|
head = buckets[index]
|
||||||
|
return ll_find(head, name)
|
||||||
|
|
||||||
|
print("====== TEST FIND HASH FUN ======")
|
||||||
|
print("find by name Ivan: ",ht_find(buckets, "Ivan"))
|
||||||
|
print("find by name Dima: ",ht_find(buckets, "Dima"))
|
||||||
|
print("find by name Boris: ", ht_find(buckets, "Boris"))
|
||||||
|
print("====== END TEST ======")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
SIZE = 1000
|
|
||||||
buckets = [None] * SIZE
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user