aboutsummaryrefslogtreecommitdiffstats
path: root/OLD/csci4041/hw3prob2.py
blob: 33f36f6ee827f8d168781957ec8e81a00c5c741c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def ADDYHASHSEARCH(T,k):
    i=0
    j=0
    s=1
    m=len(T)
    while T[j]!=None and i<=m:
        j=(h(k)+i)%m
        if T[j] is k:
            return j
        else:
            i=i+s
            s=s+2
    return -1

def h(k):
    return k*2

T = [0,None,1,None,2,None,3,None,4]
print(ADDYHASHSEARCH(T,1))
print(ADDYHASHSEARCH(T,3))
print(ADDYHASHSEARCH(T,5))