I'm trying to create my own Hash data structure in python. In __init__
I initialize a list (m_list
) of size m
and in another function I add hashes to it from my hash function.
I'm now trying to search through the list, looking for value k
. I'm getting a list index out of range error on the if self.m_list[i] == k:
line.
class Hash:
def __init__ (self, n, m, m_list=None):
self.n = n
self.m = m
self.a = choice(range(1, n))
self.b = choice(range(n))
if m_list is None:
m_list = []
self.m_list = m_list * m
def search(self, k):
found = False
for i in self.m_list:
if i is not None and found is False:
if self.m_list[i] == k:
found = True
if found:
print True
else:
print False
I created m_list
using guidelines from Create an empty list in python with certain size