In computer science
, an associative array (a map
in C++, a hash
in Perl) allows the programmer to store values that are then accessed according to their 'key' - another value that is associated with the value. For instance, I might want to store the name of my pet. I'd add the value "Max", with the key "My Dog's Name". Now, whenever I want to get at the name of my dog, I simply ask the associative array to give me the value of "My Dog's Name".
Keys and values can be of different types, and usually of any type (in C++, this is achieved by the use of templates).
Associative arrays are usually implemented using binary trees, which allow an extremely fast search to take place on the data structure. See binary search tree to find out why.