In computer science, a hashmap or hash table is a form of structuring data so that each piece of data is linked to a unique identification number or symbol. This allows easy retrieval, especially from a large database containing thousands of entries. The hashmap is not a specific part of the program, but rather refers to a form of data organization that assigns each item, known as a key, in the database to a value that stands for that item. The hash function is the part of the program which links keys to their values.
Phone books serve as an excellent example of a hashmap. The way the phone book is laid out represents the hashmap structure. It focuses on linking different values together and linking only one value to one other corresponding term, or phone number. The names in the phone book are the keys and the phone numbers are the values associated with them. Every person in the book is assigned a different number and no two are alike.
Post office boxes also serve as a metaphor for the hashmap. Every person has a key to a single box. The box can hold multiple pieces of information — bills, letters, postcards — all intended for the individual who has the key to the box. When the correct key is inserted in, or matched to, the correct box, it opens to reveal its contents.
Perfectly functioning hashmaps would link one key to one memory "box" in a computer database. Unfortunately, a factor known as hash collision can occur, where two keys go to the same box. This happens when a large amount of data is entered and there are not enough "boxes" to accommodate it all.
Unlike a phone book or a post office box, hashmaps include a third element in addition to the key and the value or box it matches. It also includes a hash function. A person knows which post office box is hers, but a computer must be told which key goes to which box. The hash function looks at the key, translates it into a series of numbers or code, and links it to the box that contains the corresponding code. The name of the key, such as "Mary," is only there so it is easier for people to interpret, while the actual code is a string of numbers meant for the computer to read.