0PricingLogin
Go Academy · Lesson

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

  1. Map Internals
  2. Checking Existence
  3. Maps as Sets
  4. Iteration and Ordering
← Back to Go Academy