面試這麼撩準拿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}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章