Many modern programming languages have a builtin datastructure that is variously called a map, dictionary, or associative array. This structure is based on the mathematical concept of a function, but differs from the programming functions discussed previously (see Functions):
Map
stores a set of input-output pairs. It has a finite domain consisting of those
inputs whose outputs were explicitly added. Typically, the inputs to a
Map are called keys, and the outputs are called values.
This example of a Map assigns integer values to string keys:
from collections.hashmap(K=string, V=int) access
HashMap_K_V as HashMap_string_int;
// Create a Map called h.
HashMap_string_int h;
// Add some key-value pairs to h.
h['hello'] = 5;
h['world'] = 3;
// Iterate over the keys (the domain) of h.
for (string key : h) {
// Compute the output for the given input.
int value = h[key];
write(key + ' ' + string(value));
}
producing the output
hello 5 world 3