4.3 Maps
The hash table is one of the most ingenious and versatile of all data structures. It is an unordered collection of key/value pairs in which all the keys are distinct, and the value associated with a given key can be retrieved, updated, or removed using a constant number of key comparisons on the average, no matter how large the hash table.
In Go, a map is a reference
to a hash table, and a map type
is written map[K]V, where K and V are the types of its keys
and values. All of
the keys in a given map are of the same type, and all of the values are of the same
type, but the keys need not be of the same type as the values.
The key type K must be comparable using ==, so that the map can test whether a
given key is equal to one already ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access