Macro View of Map Internals In Go
Ardan Labs Blog on ·
Introduction
There are lots of posts that talk about the internals of slices, but when it comes to maps, we are left in the dark. I was wondering why and then I found the code for maps and it all made sense.
https://golang.org/src/runtime/hashmap.go (https://www.ardanlabs.com/broken-link)
At least for me, this code is complicated. That being said, I think we can create a macro view of how maps are structured and grow. This should explain why they are unordered, efficient and fast.
Creating and Using Maps
Let’s look at how we can use a map literal to create a map and store a few values: