2020-11-25:go中,map的底层数据结构是什么?
福哥答案2020-11-25:
简单回答:hmap映射头、bmap桶、mapextra溢出额外信息
中级回答:
// 映射头
type hmap struct {
// Note: the format of the hmap is also encoded in cmd/compile/internal/gc/reflect.go.
// Make sure this stays in sync with the compiler's definition.
count int // map的大小. len()函数就取的这个值
flags uint8 // map状态标识
B uint8 // B 表示当前哈希表持有的 buckets 数量,但是因为哈希表中桶的数量都 2 的倍数,所以该字段会存储对数,也就是 len(buckets) == 2^B;
noverflow uint16 // 溢出buckets的数量,表示我们当前有多少个 overflow buckets
hash0 uint32 // 哈希种子 buckets unsafe.Pointer // 指向最大2^B个Buckets数组的指针. count==0时为nil.
oldbuckets unsafe.Pointer // 指向扩容之前的buckets数组,并且容量是现在一半.不增长就为nil
nevacuate uintptr // 搬迁进度,小于nevacuate的已经搬迁 extra *mapextra // 可选字段,额外信息
} // 源码的桶
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 //hash高8位
// 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]uint8 //hash高8位
keys [8]keytype //键
values [8]valuetype //值
pad uintptr
overflow uintptr // 指针,溢出桶
} //溢出额外信息
type mapextra struct {
// 如果 key 和 value 都不包含指针,并且可以被 inline(<=128 字节)
// 使用 extra 来存储 overflow bucket,这样可以避免 GC 扫描整个 map
// 然而 bmap.overflow 也是个指针。这时候我们只能把这些 overflow 的指针
// 都放在 hmap.extra.overflow 和 hmap.extra.oldoverflow 中了
// overflow 包含的是 hmap.buckets 的 overflow 的 bucket
// oldoverflow 包含扩容时的 hmap.oldbuckets 的 overflow 的 bucket
overflow *[]*bmap
oldoverflow *[]*bmap // 指向空闲的 overflow bucket 的指针
nextOverflow *bmap
}
2020-11-25:go中,map的底层数据结构是什么?的更多相关文章
- ES6中Map与其他数据结构的互相转换
最近在学习ES6的基础知识,整理了一下Map与其他数据结构相互转换的写法. Map转为数组的方法 let myMap = new Map([[true, 7], [{foo: 3}, ['abc']] ...
- Redis学习笔记(二)redis 底层数据结构
在上一节提到的图中,我们知道,可以通过 redisObject 对象的 type 和 encoding 属性.可以决定Redis 主要的底层数据结构:SDS.QuickList.ZipList.Has ...
- 转载:STL常用容器的底层数据结构实现
转载至:https://blog.csdn.net/qq_28584889/article/details/88763090 vector :底层数据结构为数组,支持快速随机访问 list:底层数据结 ...
- java中list和map的底层实现原理
Collection(单列集合) List(有序,可重复) ArrayList 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector 底层数据结构是数组,查询快,增删慢 线程安全,效率 ...
- STL中map与hash_map容器的选择收藏
这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ...
- 日本IT行业劳动力缺口达22万 在日中国留学生迎来就业好时机 2017/07/18 11:25:09
作者:倪亚敏 来源:日本新华侨报 发布时间:2017/07/18 11:25:09 据日本政府提供的数据,日本2018年应届毕业生的“求人倍率”已经达到了1.78倍.换言之,就是100名大学生 ...
- JDK中枚举的底层实现
前提 上一篇文章复习介绍了JDK中注解的底层实现,跟注解一样比较常用,但是底层实现比较神秘的还有枚举类型.趁着国庆假期的最后两天,把JDK中枚举的底层实现也进行一次探究. 通过例子查找本质 在探究JD ...
- java apache-commons-collections中Map辅助类的使用
前言 apache-commons-collections中Map辅助类,很是有用.尽管我们通过原生Map经过业务逻辑处理也能达到相同的作用与效果,但毕竟作为一个开源的工具类辅助类,对它有个了解还是有 ...
- 2020.11最新JAVA环境安装配置
Windows10下java环境配置 更新:2020年11月25日 电脑环境: windows10 64位 一.下载jdk 首先到Oracle网站下载对应操作系统的jdk安装包. https://ww ...
- 【转】Python 中map、reduce、filter函数
转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...
随机推荐
- tcpdump在wlan抓包时的可用过滤器
抓包前使用iw命令创建一个监听模式(monitor)的接口 iw phy phy0 interface add mon0 type monitor tcpdum抓包命令: tcpdump -nei m ...
- C# 返回指定目录下所有文件信息
返回指定目录下所有文件信息 /// <summary> /// 返回指定目录下所有文件信息 /// </summary> /// <param name="st ...
- mybaits-plus 部分注解说明
参考: https://blog.csdn.net/qq_45684867/article/details/123951309
- LoadRunner——分析图详解(十四)
<分析图详解> 一.Running V user s 图 X轴表示运行所用的时间,Y轴表示vuser数, 显示在整个运行过程中随着时间的推移,虚拟用户数量是如何变化的,具体描述为:用户是如 ...
- RHEL8使用NMCLI管理网络
使用 NMCLI 配置静态以太网连接 要在命令行上配置以太网连接,请使用 nmcli 工具. 例如,以下流程使用以下设置为 enp7s0 设备创建 NetworkManager 连接配置文件: 静态 ...
- PGF 概率生成函数 Probability generating function
Probability Mass Function 离散随机变量的分布函数PMF 目录 随机结构举例 two classical combinatorial distributions PGF Pro ...
- 用户user退出登录
/** * 用户退出登录 * @param request * @return */ @PostMapping("/loginout") public R<String> ...
- 2023GDKOI总结
2023GDKOI总结 说明:不是GD选手,只是因为来zsjz集训就顺便参加了GDKOI,不过也不参与GD选手排名. 考前看了看GDKOI2021的题,当时是考了3天,每天4题,而里面只有一道题是我一 ...
- Flink 1.0 ProgramInvocationException: Job failed ConnectException: 拒绝连接 (Connection refused)
[问题描述]:[root@hadoop1 flink-1.10.1]# bin/flink run examples/streaming/SocketWindowWordCount.jar --po ...
- Synchronized 关键字详解
更多内容,前往 IT-BLOG Synchronized原理分析 加锁和释放锁的原理 深入JVM看字节码,创建如下的代码: 1 public class SynchronizedDemo2 { 2 O ...