My understandment is that hash maps allow us to link, say, a string, to certain memory location. But if every string were to be linked to a unique place in memory it would need a huge block of empty memory. I don't get it.
|
Hash functions are used to convert the input (usually string) to a smaller fixed length (typically) "hashed value" which typically is used somewhat like a array index for the hash table. Ideally this value should be evenly spread throughout its range, and avoid any obvious/significant concentrations.
You have been miss informed with regards to the "certain memory location". The use of such a function is to reduce a large piece of data into a much smaller value which can be used to identify that large data. Since you are reducing the size of the data however, it is likely that more than one input "data" will have the same hashed value - that is what is called collision. A valid hash function (not a very good one, but valid still) could be one that sums up each of the letters of the string by their ASCII codes. |
|||||||||||||
|
Hash and map are two different concepts. (And hence two tags hashing and map :-)).
Getting a good hash function is really difficult as maintaining property 2 is quite difficult. A simplest hash function is modulo operator. There exists a good lot of hash algorithms and libraries. |
|||||||||||||||||
|