-
[SOLVED] HashTables
How would you normally go about programming for hash collisions, and, ensuring the values with the same hash values can be read again, assuming that you want to retain values which generate the same hash key?
Is it common to simply discard values which generate values which generate the same hash keys?
What is a concrete example of data structures where a hashtable is an appropriate data structure?
-
The way they are handled are they are put into a 'overflow' area, if the value you are looking for is different from the one stored (first in best served) then it goes through the overflow area sequentially (very time consuming if you have LOTS of collisions) until it finds.
Hope this helps :)
-
How do you read the values from the overflow area?
-
You follow some rule like "add 5 to index if a collision" and keep going until you find what you're looking for (by testing keys for equality). The number you add should be coprime to the number of elements in your table.
Other methods include using the hash code to index an array of linked lists, or determine the path to take down a trie.