user469652 user469652 - 1 month ago 22
C++ Question

Hash table collision, how to get the right value?

For example, the hash of 'a'(key) and 'b'(key) both refer to the position 10, and I use '+1' method to handle collision, so the position of 'b' is now 11.

So, if I try to get b(key), the hash function returns 10, and how to tell the hash function to return 11 which is supposed.

nbt nbt
Answer

You need to compare the key at (10) with the value you are searching for, and if they are not the same, goto the next position,(11) in this case and repeat. Hash tables generally require that the values being stored can be tested for equality.

However, this flavour of hashing has lots of problems - you are better off storing a table of lists.