I'm reading up on hash tables and hashing functions and there's one thing that I don't get. A hashing function takes a key and converts it into a memory address, right? What exactly is a key? Is it the same as an index in an array?
I'm reading up on hash tables and hashing functions and there's one thing that I don't get. A hashing function takes a key and converts it into a memory address, right? What exactly is a key? Is it the same as an index in an array?
A key is the thing you want to use to refer to the piece of data.
For example, if you are building a hash table of names to phone numbers, and you want to be able to look up the phone number given the name, the names would be the keys.
ok, so it's not a particular data type?
Nope, it can be any type, as long as it can be hashed.
That's the purpose of the hashing function - to make the key an int (usually), so you can use it to index an array.