当前位置: 首页 > news >正文

go map

// A header for a Go map.
type hmap struct {// Note: the format of the hmap is also encoded in cmd/compile/internal/reflectdata/reflect.go.// Make sure this stays in sync with the compiler's definition.// 元素个数,len(map)count     int // # live cells == size of map.  Must be first (used by len() builtin)// 标记是否有线程正在写flags     uint8// buckets 的对数 log_2B         uint8  // log_2 of # of buckets (can hold up to loadFactor * 2^B items)// overflow的bucket大致数量noverflow uint16 // approximate number of overflow buckets; see incrnoverflow for details//  哈希的种子,它能为哈希函数的结果引入随机性,这个值在创建哈希表时确定,并在调用哈希函数时作为参数传入hash0     uint32 // hash seed// buckets 数组,大小为 2^Bbuckets    unsafe.Pointer // array of 2^B Buckets. may be nil if count==0.// 旧map,不为nil时表示正在扩容oldbuckets unsafe.Pointer // previous bucket array of half the size, non-nil only when growing// 扩容进度,小于此地址的 buckets 是已经迁移完成的nevacuate  uintptr        // progress counter for evacuation (buckets less than this have been evacuated)extra *mapextra // optional fields
}

buckets 是一个指针,最终它指向的是一个结构体:

// A bucket for a Go map.
type bmap struct {// tophash generally contains the top byte of the hash value// for each key in this bucket. If tophash[0] < minTopHash,// tophash[0] is a bucket evacuation state instead.tophash [bucketCnt]uint8// Followed by bucketCnt keys and then bucketCnt elems.// NOTE: packing all the keys together and then all the elems together makes the// code a bit more complicated than alternating key/elem/key/elem/... but it allows// us to eliminate padding which would be needed for, e.g., map[int64]int8.// Followed by an overflow pointer.
}

运行时:

type bmap struct {topbits  [8]uint8keys     [8]keytypevalues   [8]valuetypepad      uintptroverflow uintptr
}

bmap 就是我们常说的“桶”,桶里面会最多装 8 个 key,这些 key 之所以会落入同一个桶,是因为它们经过哈希计算后,哈希结果是“一类”的。在桶内,又会根据 key 计算出来的 hash 值的高 8 位来决定 key 到底落入桶内的哪个位置(一个桶内最多有8个位置)。
在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【小技巧】KEIL C51 报错`Warning L6: XDATA Space Memory Overlap`
  • [前端] axios 请求成功了,为什么通过浏览器看不到返回数据
  • 极致优化之道-JVM字节码调优全揭秘
  • 2024电工杯数学建模B题完整论文讲解(含每一问python代码+数据)
  • 2、OpenVPN搭建
  • 学 Python 具体能干什么?
  • ZeroTier+Nomachine远程
  • 【Python】 使用SMOTE解决数据不平衡问题
  • 【加密与解密(第四版)】第十八章笔记
  • 【计算机网络】第三章——停止-等待协议
  • VGG论文解析—Very Deep Convolutional Networks for Large-Scale Image Recognition
  • clickhouse 中的数组(array)和元组(Tuple)—— clickhouse 基础篇(二)
  • STM32_ADC
  • 两种单例模式的区别
  • 【简明指南:Python中的异常处理与稳健代码设计】
  • 【347天】每日项目总结系列085(2018.01.18)
  • 07.Android之多媒体问题
  • 2017届校招提前批面试回顾
  • EventListener原理
  • JavaScript 一些 DOM 的知识点
  • Java程序员幽默爆笑锦集
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • Making An Indicator With Pure CSS
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • SSH 免密登录
  • Theano - 导数
  • 编写符合Python风格的对象
  • 多线程 start 和 run 方法到底有什么区别?
  • 猫头鹰的深夜翻译:JDK9 NotNullOrElse方法
  • 面试题:给你个id,去拿到name,多叉树遍历
  • 巧用 TypeScript (一)
  • 使用parted解决大于2T的磁盘分区
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 移动端 h5开发相关内容总结(三)
  • 在Mac OS X上安装 Ruby运行环境
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • ​卜东波研究员:高观点下的少儿计算思维
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • ‌前端列表展示1000条大量数据时,后端通常需要进行一定的处理。‌
  • #mysql 8.0 踩坑日记
  • (附源码)spring boot建达集团公司平台 毕业设计 141538
  • (附源码)ssm航空客运订票系统 毕业设计 141612
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (附源码)计算机毕业设计SSM疫情居家隔离服务系统
  • (几何:六边形面积)编写程序,提示用户输入六边形的边长,然后显示它的面积。
  • (六)vue-router+UI组件库
  • (论文阅读笔记)Network planning with deep reinforcement learning
  • (转)四层和七层负载均衡的区别
  • .net 4.0发布后不能正常显示图片问题
  • .net core 6 redis操作类
  • .NET 中 GetProcess 相关方法的性能
  • .Net7 环境安装配置
  • .NET编程C#线程之旅:十种开启线程的方式以及各自使用场景和优缺点
  • .net实现头像缩放截取功能 -----转载自accp教程网
  • @GlobalLock注解作用与原理解析