Go map
前言 go版本: go version go1.17.3 linux/amd64 建议阅读注释 如果没有实现过朴素的哈希表,推荐写一下leetcode 706.设计哈希映射,连最简单的哈希表都没写过就想来看实际工程实践中经过大量性能考量、折衷和优化的哈希表,还是比较困难的。 map总览 map相关的结构体定义在 runtime/map.go中: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 // A header for a Go map. type hmap struct { count int // 表示map中的键值对个数,等于len()操作返回值 flags uint8 B uint8 // B=log_2(len(buckets)) noverflow uint16 // overflow buckets 的数量的近似值 hash0 uint32 // 哈希种子,为哈希函数的结果增加随机性 buckets unsafe....