How does the getter method work?



In the context of this exercise, how does the getter (retrieve) method work?


The getter, or retrieve(), method works by utilizing the same hash() and compressor() methods that were used for assigning a new key-value in the hash map.

When we are retrieving an entry, we essentially need to find where it was assigned in the first place. By using hash() and compressor(), we can obtain this index. And, because hash maps always return the same hash code index for any key every time whether we’re adding or retrieving a key, this index should contain our target entry.

Later in the lesson, these methods will apply open addressing to the getter and setter, but the result will be essentially the same.