Question
In the context of this exercise, what happens when every index results in a collision for our getter?
Answer
In the current code, if the array is full and every index results in a collision, this means that the key is not in the hash map, and this will result in an infinite loop because we have not yet accounted for this scenario.
One way to add to the current code to account for this scenario is to check if the retrieving_array_index
has already been visited before. To do this, you could store the original hash code index in some variable, before the while loop. Then, you can add an additional condition inside the while loop which checks whether the current retrieving_array_index
matches the original hash code index, in which case we have checked all other indexes and the key must not be in the hash map.