#Map abstract data structure experiment
#hash_ object which has keys list and values list
class hash_:
def __init__(self):
self.slots = [None] * 11
self.data = [None] * 11
hash_obj = hash_()
hash_obj.slots[3] = 12
print(hash_obj.slots,hash_obj.data)
#this function is to get the hashvalue or generate a position based on the key value [0,10] we pass as an argument
def hash_val(key,size):
return key%size
#this function is to generate a (position + 1),an extened position value to check or iterate if possible
def rehash_val(key,size):
return (((hash_val(2,len(key)))%size)+1)% size
def Hash_function(key,data):
hash_value = hash_val(key,len(hash_obj.slots))
if hash_obj.slots[hash_value] == None:
hash_obj.slots[hash_value] = key
hash_obj.data[hash_value] = data
else:
if hash_obj.slots[hash_value] == key:
hash_obj.slots[hash_value] = key
else:
next_val = rehash_val(key,len(hash_obj.slots))
while hash_obj.slots[hash_value] != None and hash_obj.slots[hash_value] != key:
#repeat the if and else conditions again and apply the rehash function to moves forward
if hash_obj.slots[hash_value] == None:
hash_obj.slots[hash_value] = key
hash_obj.data[hash_value] = data
else:
if hash_obj.slots[hash_value] == key:
hash_obj.slots[hash_value] = key
Hash_function(3,hash_val(3,len(hash_obj.slots)))
print(hash_obj.slots,hash_obj.data)
I wrote a function that loops through a list of length 11 with only None values.As it is based on Hashing .Can someone review the whole algorithm.But the problem of collision is still not solved.Correct this if possible