Map Internals
How maps store data.
What Is a Map
A map stores key-value pairs. Each key maps to one value, and lookups are very fast on average.
In Go you write map[KeyType]ValueType.
package main
import "fmt"
func main() {
ages := map[string]int{"Ann": 30, "Bob": 25}
fmt.Println(ages["Ann"])
}Hash Tables Underneath
Go maps are implemented as hash tables. A hash function turns each key into a number that points to a bucket where the value lives.
All lessons in this course
- Map Internals
- Checking Existence
- Maps as Sets
- Iteration and Ordering