面试这么撩准拿offer,HashMap深度学习,扰动函数、负载因子、扩容拆分,原理和实践验证,让懂了就是真的懂!

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作者:小傅哥"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"博客:"},{"type":"link","attrs":{"href":"https://bugstack.cn","title":""},"content":[{"type":"text","text":"https://bugstack.cn"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"沉淀、分享、成长,让自己和他人都能有所收获!😄"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一、前言"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"得益于"},{"type":"codeinline","content":[{"type":"text","text":"Doug Lea"}]},{"type":"text","text":"老爷子的操刀,让"},{"type":"codeinline","content":[{"type":"text","text":"HashMap"}]},{"type":"text","text":"成为使用和面试最频繁的API,没办法设计的太优秀了!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"HashMap 最早出现在 JDK 1.2中,底层基于散列算法实现。HashMap 允许 null 键和 null 值,在计算哈键的哈希值时,null 键哈希值为 0。HashMap 并不保证键值对的顺序,这意味着在进行某些操作后,键值对的顺序可能会发生变化。另外,需要注意的是,HashMap 是非线程安全类,在多线程环境下可能会存在问题。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"HashMap 最早在JDK 1.2中就出现了,底层是基于散列算法实现,随着几代的优化更新到目前为止它的源码部分已经比较复杂,涉及的知识点也非常多,在JDK 1.8中包括;"},{"type":"codeinline","content":[{"type":"text","text":"1、散列表实现"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"2、扰动函数"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"3、初始化容量"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"4、负载因子"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"5、扩容元素拆分"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"6、链表树化"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"7、红黑树"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"8、插入"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"9、查找"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"10、删除"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"11、遍历"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"12、分段锁"}]},{"type":"text","text":"等等,因涉及的知识点较多所以需要分开讲解,本章节我们会先把目光放在前五项上,也就是关于数据结构的使用上。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"数据结构相关往往与数学离不开,学习过程中建议下载相应源码进行实验验证,可能这个过程有点烧脑,但学会后不用死记硬背就可以理解这部分知识。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二、资源下载"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本章节涉及的源码和资源在工程,"},{"type":"text","marks":[{"type":"strong"}],"text":"interview-04"},{"type":"text","text":"中,包括;"}]},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"10万单词测试数据,在doc文件夹"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"扰动函数excel展现,在dock文件夹"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"测试源码部分在"},{"type":"codeinline","content":[{"type":"text","text":"interview-04"}]},{"type":"text","text":"工程中"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可以通过关注公众号:"},{"type":"link","attrs":{"href":"https://bugstack.cn/assets/images/qrcode.png","title":""},"content":[{"type":"text","text":"bugstack虫洞栈"}]},{"type":"text","text":",回复下载进行获取{"},{"type":"text","marks":[{"type":"italic"}],"text":"回复下载后打开获得的链接,找到编号ID:19"},{"type":"text","text":"}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"三、源码分析"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. 写一个最简单的HashMap"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"学习HashMap前,最好的方式是先了解这是一种怎么样的数据结构来存放数据。而HashMap经过多个版本的迭代后,乍一看代码还是很复杂的。就像你原来只穿个裤衩,现在还有秋裤和风衣。所以我们先来看看最根本的HashMap是什么样,也就是只穿裤衩是什么效果,之后再去分析它的源码。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"问题:"},{"type":"text","text":" 假设我们有一组7个字符串,需要存放到数组中,但要求在获取每个元素的时候时间复杂度是O(1)。也就是说你不能通过循环遍历的方式进行获取,而是要定位到数组ID直接获取相应的元素。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"方案:"},{"type":"text","text":" 如果说我们需要通过ID从数组中获取元素,那么就需要把每个字符串都计算出一个在数组中的位置ID。"},{"type":"text","marks":[{"type":"italic"}],"text":"字符串获取ID你能想到什么方式?"},{"type":"text","text":" 一个字符串最直接的获取跟数字相关的信息就是HashCode,可HashCode的取值范围太大了"},{"type":"codeinline","content":[{"type":"text","text":"[-2147483648, 2147483647]"}]},{"type":"text","text":",不可能直接使用。那么就需要使用HashCode与数组长度做与运算,得到一个可以在数组中出现的位置。如果说有两个元素得到同样的ID,那么这个数组ID下就存放两个字符串。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上呢其实就是我们要把字符串散列到数组中的一个基本思路,接下来我们就把这个思路用代码实现出来。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.1 代码实现"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"// 初始化一组字符串\nList list = new ArrayList<>();\nlist.add(\"jlkk\");\nlist.add(\"lopi\");\nlist.add(\"小傅哥\");\nlist.add(\"e4we\");\nlist.add(\"alpo\");\nlist.add(\"yhjk\");\nlist.add(\"plop\");\n\n// 定义要存放的数组\nString[] tab = new String[8];\n\n// 循环存放\nfor (String key : list) {\n int idx = key.hashCode() & (tab.length - 1); // 计算索引位置\n System.out.println(String.format(\"key值=%s Idx=%d\", key, idx));\n if (null == tab[idx]) {\n tab[idx] = key;\n continue;\n }\n tab[idx] = tab[idx] + \"->\" + key;\n}\n// 输出测试结果\nSystem.out.println(JSON.toJSONString(tab));"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这段代码整体看起来也是非常简单,并没有什么复杂度,主要包括以下内容;"}]},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"初始化一组字符串集合,这里初始化了7个。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"定义一个数组用于存放字符串,注意这里的长度是8,也就是2的倍数。这样的数组长度才会出现一个 "},{"type":"codeinline","content":[{"type":"text","text":"0111"}]},{"type":"text","text":" 除高位以外都是1的特征,也是为了散列。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"接下来就是循环存放数据,计算出每个字符串在数组中的位置。"},{"type":"codeinline","content":[{"type":"text","text":"key.hashCode() & (tab.length - 1)"}]},{"type":"text","text":"。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"在字符串存放到数组的过程,如果遇到相同的元素,进行连接操作"},{"type":"codeinline","content":[{"type":"text","text":"模拟链表的过程"}]},{"type":"text","text":"。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"最后输出存放结果。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"测试结果"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"key值=jlkk Idx=2\nkey值=lopi Idx=4\nkey值=小傅哥 Idx=7\nkey值=e4we Idx=5\nkey值=alpo Idx=2\nkey值=yhjk Idx=0\nkey值=plop Idx=5\n测试结果:[\"yhjk\",null,\"jlkk->alpo\",null,\"lopi\",\"e4we->plop\",null,\"小傅哥\"]"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在测试结果首先是计算出每个元素在数组的Idx,也有出现重复的位置。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最后是测试结果的输出,1、3、6,位置是空的,2、5,位置有两个元素被链接起来"},{"type":"codeinline","content":[{"type":"text","text":"e4we->plop"}]},{"type":"text","text":"。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这就达到了我们一个最基本的要求,将串元素散列存放到数组中,最后通过字符串元素的索引ID进行获取对应字符串。这样是HashMap的一个最基本原理,有了这个基础后面就会更容易理解HashMap的源码实现。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.2 Hash散列示意图"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果上面的测试结果不能在你的头脑中很好的建立出一个数据结构,那么可以看以下这张散列示意图,方便理解;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b1/b1c7213bdb7aef4fc1045d6823875d30.png","alt":"bugstack.cn Hash散列示意图","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这张图就是上面代码实现的全过程,将每一个字符串元素通过Hash计算索引位置,存放到数组中。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"黄色的索引ID是没有元素存放、绿色的索引ID存放了一个元素、红色的索引ID存放了两个元素。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.3 这个简单的HashMap有哪些问题"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上我们实现了一个简单的HashMap,或者说还算不上HashMap,只能算做一个散列数据存放的雏形。但这样的一个数据结构放在实际使用中,会有哪些问题呢?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"这里所有的元素存放都需要获取一个索引位置,而如果元素的位置不够散列碰撞严重,那么就失去了散列表存放的意义,没有达到预期的性能。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"在获取索引ID的计算公式中,需要数组长度是2的倍数,那么怎么进行初始化这个数组大小。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"数组越小碰撞的越大,数组越大碰撞的越小,时间与空间如何取舍。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"目前存放7个元素,已经有两个位置都存放了2个字符串,那么链表越来越长怎么优化。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"随着元素的不断添加,数组长度不足扩容时,怎么把原有的元素,拆分到新的位置上去。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上这些问题可以归纳为;"},{"type":"codeinline","content":[{"type":"text","text":"扰动函数"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"初始化容量"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"负载因子"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"扩容方法"}]},{"type":"text","text":"以及"},{"type":"codeinline","content":[{"type":"text","text":"链表和红黑树"}]},{"type":"text","text":"转换的使用等。接下来我们会逐个问题进行分析。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 扰动函数"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在HashMap存放元素时候有这样一段代码来处理哈希值,这是"},{"type":"codeinline","content":[{"type":"text","text":"java 8"}]},{"type":"text","text":"的散列值扰动函数,用于优化散列效果;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"static final int hash(Object key) {\n int h;\n return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.1 为什么使用扰动函数"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"理论上来说字符串的"},{"type":"codeinline","content":[{"type":"text","text":"hashCode"}]},{"type":"text","text":"是一个int类型值,那可以直接作为数组下标了,且不会出现碰撞。但是这个"},{"type":"codeinline","content":[{"type":"text","text":"hashCode"}]},{"type":"text","text":"的取值范围是[-2147483648, 2147483647],有将近40亿的长度,谁也不能把数组初始化的这么大,内存也是放不下的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我们默认初始化的Map大小是16个长度 "},{"type":"codeinline","content":[{"type":"text","text":"DEFAULT_INITIAL_CAPACITY = 1 << 4"}]},{"type":"text","text":",所以获取的Hash值并不能直接作为下标使用,需要与数组长度进行取模运算得到一个下标值,也就是我们上面做的散列列子。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那么,hashMap源码这里不只是直接获取哈希值,还进行了一次扰动计算,"},{"type":"codeinline","content":[{"type":"text","text":"(h = key.hashCode()) ^ (h >>> 16)"}]},{"type":"text","text":"。把哈希值右移16位,也就正好是自己长度的一半,之后与原哈希值做异或运算,这样就混合了原哈希值中的高位和低位,增大了"},{"type":"text","marks":[{"type":"strong"}],"text":"随机性"},{"type":"text","text":"。计算方式如下图;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/13/131a86b03a020c4aaf8e5ae69a5a32dc.png","alt":"bugstack.cn 扰动函数","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"说白了,使用扰动函数就是为了增加随机性,让数据元素更加均衡的散列,减少碰撞。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.2 实验验证扰动函数"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"从上面的分析可以看出,扰动函数使用了哈希值的高半区和低半区做异或,混合原始哈希码的高位和低位,以此来加大低位区的随机性。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但看不到实验数据的话,这终究是一段理论,具体这段哈希值真的被增加了随机性没有,并不知道。所以这里我们要做一个实验,这个实验是这样做;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"选取10万个单词词库"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"定义128位长度的数组格子"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"分别计算在扰动和不扰动下,10万单词的下标分配到128个格子的数量"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"统计各个格子数量,生成波动曲线。如果扰动函数下的波动曲线相对更平稳,那么证明扰动函数有效果。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"2.2.1 扰动代码测试"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"扰动函数对比方法"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"public class Disturb {\n\n public static int disturbHashIdx(String key, int size) {\n return (size - 1) & (key.hashCode() ^ (key.hashCode() >>> 16));\n }\n\n public static int hashIdx(String key, int size) {\n return (size - 1) & key.hashCode();\n }\n\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"disturbHashIdx"}]},{"type":"text","text":" 扰动函数下,下标值计算"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"hashIdx"}]},{"type":"text","text":" 非扰动函数下,下标值计算"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"单元测试"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"// 10万单词已经初始化到words中\n@Test\npublic void test_disturb() {\n Map map = new HashMap<>(16);\n for (String word : words) {\n // 使用扰动函数\n int idx = Disturb.disturbHashIdx(word, 128);\n // 不使用扰动函数\n // int idx = Disturb.hashIdx(word, 128);\n if (map.containsKey(idx)) {\n Integer integer = map.get(idx);\n map.put(idx, ++integer);\n } else {\n map.put(idx, 1);\n }\n }\n System.out.println(map.values());\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上分别统计两种函数下的下标值分配,最终将统计结果放到excel中生成图表。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"2.2.2 扰动函数散列图表"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上的两张图,分别是没有使用扰动函数和使用扰动函数的,下标分配。实验数据;"}]},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"10万个不重复的单词"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"128个格子,相当于128长度的数组"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"未使用扰动函数"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/fb/fb870cc063ae535ef42a71134a298641.png","alt":"bugstack.cn 未使用扰动函数","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"使用扰动函数"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/73/738ae9283ec0ea56702915b2c324c2ca.png","alt":"bugstack.cn 使用扰动函数","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"从这两种的对比图可以看出来,在使用了扰动函数后,数据分配的更加均匀了。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"数据分配均匀,也就是散列的效果更好,减少了hash的碰撞,让数据存放和获取的效率更佳。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3. 初始化容量和负载因子"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下来我们讨论下一个问题,从我们模仿HashMap的例子中以及HashMap默认的初始化大小里,都可以知道,散列数组需要一个2的倍数的长度,因为只有2的倍数在减1的时候,才会出现"},{"type":"codeinline","content":[{"type":"text","text":"01111"}]},{"type":"text","text":"这样的值。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那么这里就有一个问题,我们在初始化HashMap的时候,如果传一个17个的值"},{"type":"codeinline","content":[{"type":"text","text":"new HashMap<>(17);"}]},{"type":"text","text":",它会怎么处理呢?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3.1 寻找2的倍数最小值"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在HashMap的初始化中,有这样一段方法;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"public HashMap(int initialCapacity, float loadFactor) {\n ...\n this.loadFactor = loadFactor;\n this.threshold = tableSizeFor(initialCapacity);\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"阀值"},{"type":"codeinline","content":[{"type":"text","text":"threshold"}]},{"type":"text","text":",通过方法"},{"type":"codeinline","content":[{"type":"text","text":"tableSizeFor"}]},{"type":"text","text":"进行计算,是根据初始化来计算的。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这个方法也就是要寻找比初始值大的,最小的那个2进制数值。比如传了17,我应该找到的是32。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"计算阀值大小的方法;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"static final int tableSizeFor(int cap) {\n int n = cap - 1;\n n |= n >>> 1;\n n |= n >>> 2;\n n |= n >>> 4;\n n |= n >>> 8;\n n |= n >>> 16;\n return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"MAXIMUM_CAPACITY = 1 << 30,这个是临界范围,也就是最大的Map集合。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"乍一看可能有点晕😵怎么都在向右移位1、2、4、8、16,这主要是为了把二进制的各个位置都填上1,当二进制的各个位置都是1以后,就是一个标准的2的倍数减1了,最后把结果加1再返回即可。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那这里我们把17这样一个初始化计算阀值的过程,用图展示出来,方便理解;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f8/f8ab5967a220d7925c5573ed85df552f.png","alt":"bugstack.cn 计算阀值","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3.2 负载因子"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"static final float DEFAULT_LOAD_FACTOR = 0.75f;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"负载因子是做什么的?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"负载因子,可以理解成一辆车可承重重量超过某个阀值时,把货放到新的车上。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那么在HashMap中,负载因子决定了数据量多少了以后进行扩容。"},{"type":"text","marks":[{"type":"italic"}],"text":"这里要提到上面做的HashMap例子,我们准备了7个元素,但是最后还有3个位置空余,2个位置存放了2个元素。"},{"type":"text","text":" 所以可能即使你数据比数组容量大时也是不一定能正正好好的把数组占满的,而是在某些小标位置出现了大量的碰撞,只能在同一个位置用链表存放,那么这样就失去了Map数组的性能。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所以,要选择一个合理的大小下进行扩容,默认值0.75就是说当阀值容量占了3/4s时赶紧扩容,减少Hash碰撞。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同时0.75是一个默认构造值,在创建HashMap也可以调整,比如你希望用更多的空间换取时间,可以把负载因子调的更小一些,减少碰撞。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4. 扩容元素拆分"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为什么扩容,因为数组长度不足了。那扩容最直接的问题,就是需要把元素拆分到新的数组中。拆分元素的过程中,原jdk1.7中会需要重新计算哈希值,但是到jdk1.8中已经进行优化,不在需要重新计算,提升了拆分的性能,设计的还是非常巧妙的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"4.1 测试数据"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"@Test\npublic void test_hashMap() {\n List list = new ArrayList<>();\n list.add(\"jlkk\");\n list.add(\"lopi\");\n list.add(\"jmdw\");\n list.add(\"e4we\");\n list.add(\"io98\");\n list.add(\"nmhg\");\n list.add(\"vfg6\");\n list.add(\"gfrt\");\n list.add(\"alpo\");\n list.add(\"vfbh\");\n list.add(\"bnhj\");\n list.add(\"zuio\");\n list.add(\"iu8e\");\n list.add(\"yhjk\");\n list.add(\"plop\");\n list.add(\"dd0p\");\n for (String key : list) {\n int hash = key.hashCode() ^ (key.hashCode() >>> 16);\n System.out.println(\"字符串:\" + key + \" \\tIdx(16):\" + ((16 - 1) & hash) + \" \\tBit值:\" + Integer.toBinaryString(hash) + \" - \" + Integer.toBinaryString(hash & 16) + \" \\t\\tIdx(32):\" + ((\n System.out.println(Integer.toBinaryString(key.hashCode()) +\" \"+ Integer.toBinaryString(hash) + \" \" + Integer.toBinaryString((32 - 1) & hash));\n }\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"测试结果"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"字符串:jlkk \tIdx(16):3 \tBit值:1100011101001000010011 - 10000 \t\tIdx(32):19\n1100011101001000100010 1100011101001000010011 10011\n字符串:lopi \tIdx(16):14 \tBit值:1100101100011010001110 - 0 \t\tIdx(32):14\n1100101100011010111100 1100101100011010001110 1110\n字符串:jmdw \tIdx(16):7 \tBit值:1100011101010100100111 - 0 \t\tIdx(32):7\n1100011101010100010110 1100011101010100100111 111\n字符串:e4we \tIdx(16):3 \tBit值:1011101011101101010011 - 10000 \t\tIdx(32):19\n1011101011101101111101 1011101011101101010011 10011\n字符串:io98 \tIdx(16):4 \tBit值:1100010110001011110100 - 10000 \t\tIdx(32):20\n1100010110001011000101 1100010110001011110100 10100\n字符串:nmhg \tIdx(16):13 \tBit值:1100111010011011001101 - 0 \t\tIdx(32):13\n1100111010011011111110 1100111010011011001101 1101\n字符串:vfg6 \tIdx(16):8 \tBit值:1101110010111101101000 - 0 \t\tIdx(32):8\n1101110010111101011111 1101110010111101101000 1000\n字符串:gfrt \tIdx(16):1 \tBit值:1100000101111101010001 - 10000 \t\tIdx(32):17\n1100000101111101100001 1100000101111101010001 10001\n字符串:alpo \tIdx(16):7 \tBit值:1011011011101101000111 - 0 \t\tIdx(32):7\n1011011011101101101010 1011011011101101000111 111\n字符串:vfbh \tIdx(16):1 \tBit值:1101110010111011000001 - 0 \t\tIdx(32):1\n1101110010111011110110 1101110010111011000001 1\n字符串:bnhj \tIdx(16):0 \tBit值:1011100011011001100000 - 0 \t\tIdx(32):0\n1011100011011001001110 1011100011011001100000 0\n字符串:zuio \tIdx(16):8 \tBit值:1110010011100110011000 - 10000 \t\tIdx(32):24\n1110010011100110100001 1110010011100110011000 11000\n字符串:iu8e \tIdx(16):8 \tBit值:1100010111100101101000 - 0 \t\tIdx(32):8\n1100010111100101011001 1100010111100101101000 1000\n字符串:yhjk \tIdx(16):8 \tBit值:1110001001010010101000 - 0 \t\tIdx(32):8\n1110001001010010010000 1110001001010010101000 1000\n字符串:plop \tIdx(16):9 \tBit值:1101001000110011101001 - 0 \t\tIdx(32):9\n1101001000110011011101 1101001000110011101001 1001\n字符串:dd0p \tIdx(16):14 \tBit值:1011101111001011101110 - 0 \t\tIdx(32):14\n1011101111001011000000 1011101111001011101110 1110"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这里我们随机使用一些字符串计算他们分别在16位长度和32位长度数组下的索引分配情况,看哪些数据被重新路由到了新的地址。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同时,这里还可以观察🕵出一个非常重要的信息,原哈希值与扩容新增出来的长度16,进行&运算,如果值等于0,则下标位置不变。如果不为0,那么新的位置则是原来位置上加16。{这个地方需要好好理解下,并看实验数据}"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这样一来,就不需要在重新计算每一个数组中元素的哈希值了。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"4.2 数据迁移"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/36/36e5e998034ce8c4aa72ca366b4340be.png","alt":"bugstack.cn 数据迁移","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这张图就是原16位长度数组元素,像32位数组长度中转移的过程。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其中黄色区域元素"},{"type":"codeinline","content":[{"type":"text","text":"zuio"}]},{"type":"text","text":"因计算结果 "},{"type":"codeinline","content":[{"type":"text","text":"hash & oldCap"}]},{"type":"text","text":" 不为1,则被迁移到下标位置24。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同时还是用重新计算哈希值的方式验证了,确实分配到24的位置,因为这是在二进制计算中补1的过程,所以可以通过上面简化的方式确定哈希值的位置。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"四、总结"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你能坚持看完这部分内容,并按照文中的例子进行相应的实验验证,那么一定可以学会本章节涉及这五项知识点;"},{"type":"codeinline","content":[{"type":"text","text":"1、散列表实现"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"2、扰动函数"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"3、初始化容量"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"4、负载因子"}]},{"type":"text","text":"、"},{"type":"codeinline","content":[{"type":"text","text":"5、扩容元素拆分"}]},{"type":"text","text":"。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"对我个人来说以前也知道这部分知识,但是没有验证过,只知道概念如此,正好借着写面试手册专栏,加深学习,用数据验证理论,让知识点可以更加深入的理解。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这一章节完事,下一章节继续进行HashMap的其他知识点挖掘,让懂了就是真的懂了。好了,写到这里了,感谢大家的阅读。如果某处没有描述清楚,或者有不理解的点,欢迎与我讨论交流。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"五、推荐阅读"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/interview/2020/08/04/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E7%AC%AC2%E7%AF%87-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-HashCode%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A831%E4%BD%9C%E4%B8%BA%E4%B9%98%E6%95%B0.html","title":""},"content":[{"type":"text","text":"HashCode为什么使用31作为乘数?"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/interview/2020/07/28/%E9%9D%A2%E7%BB%8F%E6%89%8B%E5%86%8C-%E5%BC%80%E7%AF%87-%E9%9D%A2%E8%AF%95%E5%AE%98%E9%83%BD%E9%97%AE%E6%88%91%E5%95%A5.html","title":""},"content":[{"type":"text","text":"面经手册 · 开篇《面试官都问我啥》"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/itstack-code-life/2020/04/11/工作两年简历写成这样-谁要你呀.html","title":""},"content":[{"type":"text","text":"工作两年简历写成这样,谁要你呀!"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/itstack-code-life/2020/04/30/讲道理-只要你是一个爱折腾的程序员-毕业找工作真的不需要再花钱培训.html","title":""},"content":[{"type":"text","text":"讲道理,只要你是一个爱折腾的程序员,毕业找工作真的不需要再花钱培训!"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/itstack-code-life/2020/03/31/大学四年到毕业工作5年的学习路线资源汇总.html","title":""},"content":[{"type":"text","text":"大学四年到毕业工作5年的学习路线资源汇总"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bugstack.cn/itstack-demo-any/2019/12/25/源码分析-Mybatis接口没有实现类为什么可以执行增删改查.html","title":""},"content":[{"type":"text","text":"源码分析 | Mybatis接口没有实现类为什么可以执行增删改查"}]}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章