Working with maps
You access the elements of an array or a slice using integer indexes. Maps provide a similar syntax to use index keys that are not only integers but also any type that is “comparable” (which means it can be compared using ==
or !=
.) A map is an associative data type – that is, it stores key-value pairs. Each key appears once in a map. A Go map provides amortized constant-time access to its elements (that is, when measured over time, map element access should look like a constant-time operation.)
The Go map
type provides convenient access to an underlying complicated data structure. It is one of the “reference” types – that is, assigning a map variable to another map simply assigns a pointer to the underlying structure and does not copy the elements of the map.
Warning
A map is an unordered collection. Do not rely on the ordering of elements in a map. The same order of insertion may result in different iteration orders...