Hi,
What’s wrong with the implementation below? Can you help me, please?
If I used “get_valid_index(data_list, key)” instead of “get_valid_index(self.data_list, key)” I obtained TRUE | FALSE | TRUE | FALSE.
I am very grateful to you for your help.
p/s: It seems that the last version of Assignment 2 used get_index(data_list, key) and get_valid_index(data_list, key), isn’t it?
class ProbingHashTable:
def init(self, max_size=MAX_HASH_TABLE_SIZE):
# 1. Create a list of size max_size
with all values None
self.data_list = max_size * [None]
def insert(self, key, value):
# 1. Find the index for the key using get_valid_index
idx = get_valid_index(self.data_list, key)
# 2. Store the key-value pair at the right index
self.data_list[idx] = (key, value)
def find(self, key):
# 1. Find the index for the key using get_valid_index
idx = get_valid_index(self.data_list, key)
# 2. Retrieve the data stored at the index
kv = self.data_list[idx]
# 3. Return the value if found, else return None
return None if kv is None else kv[1]
def update(self, key, value):
# 1. Find the index for the key using get_valid_index
idx = get_valid_index(self.data_list, key)
# 2. Store the new key-value pair at the right index
self.data_list[idx] = (key, value)
def list_all(self):
# 1. Extract the key from each key-value pair
return [kv[0] for kv in self.data_list if kv is not None]