map的内部结构 Go中的map使用哈希表实现的,在源码go runtime/hashmap.go中可以看到对应实现。 1// A header for a Go map. 2type hmap struct { 3 // Note: the format of the Hmap is encoded in ../../cmd/internal/gc/reflect.go and 4 // ../reflect/type.go. Don't change this structure without also changing that code! 5 count int // # live cells == size of map. Must be first (used by len() builtin) 6 flags uint8 7 B uint8 // log_2 of……
slice的内部结构 一个slice本质上是一个数组的某个部分的引用。在go runtime/slice.go源码中定义了slice的结构: 1type slice struct { 2 array unsafe.Pointer 3 len int 4 cap int 5} 可以看到在Go的内部,slice是一个包含3个字段的结构体: array: 指向slice……