On the internet, I've come across this question:
Classify the Hashing Functions based on the various methods by which the key value is found.
with answers like
- Direct method
- Subtraction method
- Modulo-Division method
- Digit-Extraction method
- Mid-Square method
- Folding method
- Pseudo-random method
which I find strange. I think I know a lot about hashing, but this is plain gibberish to me, could anybody explain?
Best Answer
They are methods of turning a hashcode into an index of the array that contains the values. Let's say you have a hashcode of 0x12345678. A very large number and you're unlikely to have an array of this size. If you do you can just do
And be done (direct method).
If you don't then you have a figure out a way to turn this value into one that fits the array size while trying to avoid too many collisions. The terms used are probably known by other names too, but for example you could just mask off the higher bits of the hashcode
Or mod the hashcode against the array size
Etc etc
Edit: this link may help