-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhashing algo
More file actions
33 lines (30 loc) · 896 Bytes
/
hashing algo
File metadata and controls
33 lines (30 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
def hash(x):
x = random.randrange(1, 100)
return x
class customerid:
def __init__(self, hv, c):
self.hashvalue = hv
self.customer = c
#initialising the
list = []
for i in range(5):
list.append(customerid(0, i))
for x in range(len(list)):
p = hash(list[x].hashvalue)
list[x].hashvalue = p
print(list[x].hashvalue, list[x].customer)
#checking if a value repeats, hash must be unique
for k in range(len(list)):
if p == list[k].hashvalue:
list[k].hashvalue = hash(k)
print(list[k].hashvalue, list[k].customer, "there was a copy")
else:
continue
#search for a hash
def search(searchvalue):
for b in range(len(list)):
if searchvalue == list[b].hashvalue:
print(list[b].hashvalue, "There customer id is", list[b].customer)
else:
continue