Back to Gotraining

README

topics/go/language/maps/README.md

latest2.2 KB
Original Source

Maps

Maps provide a data structure that allow for the storage and management of key/value pair data.

Notes

  • Maps provide a way to store and retrieve key/value pairs.
  • Reading an absent key returns the zero value for the map's value type.
  • Iterating over a map is always random.
  • The map key must be a value that is comparable.
  • Elements in a map are not addressable.
  • Maps are a reference type.

Go maps in action - Andrew Gerrand
Macro View of Map Internals In Go - William Kennedy
Inside the Map Implementation - Keith Randall
How the Go runtime implements maps efficiently (without generics) - Dave Cheney

Code Review

Declare, write, read, and delete (Go Playground)
Absent keys (Go Playground)
Map key restrictions (Go Playground)
Map literals and range (Go Playground)
Sorting maps by key (Go Playground)
Taking an element's address (Go Playground)
Maps are Reference Types (Go Playground)

Exercises

Exercise 1

Declare and make a map of integer values with a string as the key. Populate the map with five values and iterate over the map to display the key/value pairs.

Template (Go Playground) | Answer (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.