免费爱碰视频在线观看,九九精品国产屋,欧美亚洲尤物久久精品,1024在线观看视频亚洲

      JDK8中的HashMap的put key時(shí)的源碼學(xué)習(xí)

      一、putVal()源碼

      /** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for the key, the old * value is replaced. * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * @return the previous value associated with key, or * null if there was no mapping for key. * (A null return can also indicate that the map * previously associated null with key.) */ public V put(K key, V value) { return putVal(hash(key), key, value, false, true); } /** * Implements Map.put and related methods * * @param hash hash for key * @param key the key * @param value the value to put * @param onlyIfAbsent if true, don’t change existing value * @param evict if false, the table is in creation mode. * @return previous value, or null if none */ final V putVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict) { # Node[] tab是key被hash后存儲(chǔ)的哈希桶數(shù)組,是一個(gè)單向鏈表數(shù)組 Node[] tab; Node p; int n, i; # 如果哈希桶數(shù)組是null或者length==0,進(jìn)行擴(kuò)容操作,初始化哈希桶數(shù)組的容量為16 if ((tab = table) == null || (n = tab.length) == 0) n = (tab = resize()).length; # 如果在取模運(yùn)算后的索引位置的數(shù)組元素是null,直接插入新的鏈表元素 if ((p = tab[i = (n – 1) & hash]) == null) tab[i] = newNode(hash, key, value, null); # 如果tab[i]的位置是一個(gè)長(zhǎng)度于等于1的鏈表,就在最后一個(gè)節(jié)點(diǎn)next追加新的節(jié)點(diǎn) else { Node e; K k; # 如果已經(jīng)有相同hash和相同的k if (p.hash == hash && ((k = p.key) == key || (key != null && key.equals(k)))) e = p; # 如果這個(gè)元素是一個(gè)樹節(jié)點(diǎn),就往紅黑樹中添加值 else if (p instanceof TreeNode) e = ((TreeNode)p).putTreeVal(this, tab, hash, key, value); else { # 遍歷鏈表 for (int binCount = 0; ; ++binCount) { # 如果當(dāng)前節(jié)點(diǎn)沒有下一節(jié)點(diǎn),就新增尾節(jié)點(diǎn) if ((e = p.next) == null) { p.next = newNode(hash, key, value, null); # 如果鏈表的長(zhǎng)度大于等于8,將鏈表轉(zhuǎn)換為紅黑樹結(jié)構(gòu) if (binCount >= TREEIFY_THRESHOLD – 1) // -1 for 1st treeifyBin(tab, hash); break; } if (e.hash == hash && ((k = e.key) == key || (key != null && key.equals(k)))) break; p = e; } } # 判斷是否覆蓋相同key的value if (e != null) { // existing mapping for key V oldValue = e.value; if (!onlyIfAbsent || oldValue == null) e.value = value; afterNodeAccess(e); return oldValue; } } ++modCount; if (++size > threshold) resize(); afterNodeInsertion(evict); return null; }

      二、resize()擴(kuò)容源碼

      /** * Initializes or doubles table size. If null, allocates in * accord with initial capacity target held in field threshold. * Otherwise, because we are using power-of-two expansion, the * elements from each bin must either stay at same index, or move * with a power of two offset in the new table. * * @return the table */ final Node[] resize() { # 舊的哈希桶數(shù)組 Node[] oldTab = table; # 舊數(shù)組的長(zhǎng)度 int oldCap = (oldTab == null) ? 0 : oldTab.length; # 舊數(shù)組的最大擴(kuò)容限制容量(閾值),如12,24 int oldThr = threshold; int newCap, newThr = 0; # 舊哈希桶數(shù)組長(zhǎng)度大于0時(shí),重新設(shè)置哈希數(shù)組的長(zhǎng)度 if (oldCap > 0) { # 如果超過了默認(rèn)的最大容量1 <= MAXIMUM_CAPACITY) { threshold = Integer.MAX_VALUE; return oldTab; } # 普通擴(kuò)容 左位移 else if ((newCap = oldCap << 1) = DEFAULT_INITIAL_CAPACITY) newThr = oldThr < 0) // initial capacity was placed in threshold newCap = oldThr; # 默認(rèn)情況下,哈希桶數(shù)組長(zhǎng)度和閾值 else { // zero initial threshold signifies using efaults newCap = DEFAULT_INITIAL_CAPACITY; newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); } # 如果新的閾值等于0,設(shè)置默認(rèn)的數(shù)組容量和閾值 if (newThr == 0) { float ft = (float)newCap * loadFactor; newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? (int)ft : Integer.MAX_VALUE); } threshold = newThr; @SuppressWarnings({"rawtypes","unchecked"}) Node[] newTab = (Node[])new Node[newCap]; table = newTab; if (oldTab != null) { for (int j = 0; j < oldCap; ++j) { Node e; if ((e = oldTab[j]) != null) { oldTab[j] = null; if (e.next == null) newTab[e.hash & (newCap – 1)] = e; else if (e instanceof TreeNode) ((TreeNode)e).split(this, newTab, j, oldCap); else { // preserve order Node loHead = null, loTail = null; Node hiHead = null, hiTail = null; Node next; do { next = e.next; if ((e.hash & oldCap) == 0) { if (loTail == null) loHead = e; else loTail.next = e; loTail = e; } else { if (hiTail == null) hiHead = e; else hiTail.next = e; hiTail = e; } } while ((e = next) != null); if (loTail != null) { loTail.next = null; newTab[j] = loHead; } if (hiTail != null) { hiTail.next = null; newTab[j + oldCap] = hiHead; } } } } } return newTab; }

      鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場(chǎng),版權(quán)歸原作者所有,如有侵權(quán)請(qǐng)聯(lián)系管理員(admin#wlmqw.com)刪除。
      (0)
      用戶投稿
      上一篇 2022年6月28日 06:05
      下一篇 2022年6月28日 06:05

      相關(guān)推薦

      • 后置雙攝iPhone14 Max曝光,iPhone 13買早的網(wǎng)友直呼心碎

        在影像系統(tǒng)方面,這款iPhone14 Max采用了經(jīng)典的后置雙攝設(shè)計(jì)。后置雙攝像頭并沒有像之前一樣整合成一個(gè)“圓角矩形”的模塊,而是以獨(dú)立的形式布局在手機(jī)背面的左上角。另外,攝像頭…

        2022年6月15日
      • 「標(biāo)準(zhǔn)參編單位」江蘇中天互聯(lián)科技有限公司

        經(jīng)中國(guó)電子商會(huì)信息工程測(cè)試專委會(huì)審核批準(zhǔn),江蘇中天互聯(lián)科技有限公司成為《軟件測(cè)試人才技能評(píng)價(jià)規(guī)范》團(tuán)體標(biāo)準(zhǔn)編制組成員單位,參與此項(xiàng)標(biāo)準(zhǔn)的編制工作。江蘇中天互聯(lián)科技有限公司作為本次標(biāo)…

        2022年8月7日
      • LPL季后賽各路選手排行榜,上單369獨(dú)一檔,ADC阿水沒有對(duì)手?

        LPL季后賽進(jìn)行到現(xiàn)在,基本上大的懸念都已經(jīng)揭曉了,如今最吸引人也最具爭(zhēng)議性的便是LPL夏季賽的決死啊滔搏對(duì)陣JDG這場(chǎng),那么看來這么久的季后賽,大家對(duì)于選手的了解也非常透徹了,那…

        2022年9月8日
      • 萬葉的攻略

        角色與特點(diǎn):萬葉使用單手劍和風(fēng)元素神之眼,具有集怪、控場(chǎng)、化元素的象征性輔助能力。自我突破獲得元素掌握屬性,同時(shí)先天天賦2會(huì)根據(jù)萬葉的元素掌握為全隊(duì)角色提供元素傷害加成。推薦作為純…

        2022年7月4日
      • 金蟬正式增強(qiáng)!吳日天笑出聲:國(guó)一位置穩(wěn)了,輔助打法必是主流

        秦啟電競(jìng),暢談?dòng)螒蛐聼狳c(diǎn)。 自從金蟬上架之后,玩家們對(duì)他的評(píng)價(jià)是走的兩個(gè)極端,中低端局普遍認(rèn)為金蟬沒用,清線能力太低,支援速度慢,太偏向后期,沒有六神裝根本打不出傷害。但高端局卻覺…

        2022年6月29日
      • 原神千夜浮夢(mèng)怎么用 千夜浮夢(mèng)使用方法

        原神千夜浮夢(mèng)可以用來提升草神的傷害值,作為這樣重要的材料,不少玩家還不是很清楚千夜浮夢(mèng)的用法,小編接下來將在下面的攻略中為大家分享千夜浮夢(mèng)使用的方法,各位玩家感興趣的可以和小編一起…

        2022年10月25日
      • 小米公布自動(dòng)駕駛相關(guān)專利,可實(shí)現(xiàn)“自動(dòng)超車”

        記者 | 佘曉晨 小米造車又有新進(jìn)展。天眼查App顯示,近日,小米汽車科技有限公司申請(qǐng)的“自動(dòng)超車方法、裝置、車輛、存儲(chǔ)介質(zhì)及芯片”專利公布。 值得一提的是,此次公布的專利涉及自動(dòng)…

        2022年6月15日
      • 宋祖兒、趙露思都在穿的鉤花單品,時(shí)髦精都要有

        夏日的浪漫氛圍,90%都是編織單品給的。包容性強(qiáng)、特別百搭,可以說是夏天的專屬限定單品。 最近,被宋祖兒一套大理旅游的照片給美到!藍(lán)藍(lán)的天、甜甜的笑,還有好天氣,看得人想立刻解封出…

        2022年6月11日
      • 準(zhǔn)靜態(tài)壓縮下腰椎間盤破裂的力學(xué)行為

        摘要: 文題釋義: 本構(gòu)模型:反映材料應(yīng)力應(yīng)變宏觀性質(zhì)的數(shù)學(xué)模型。用于描述材料受到外力作用變形時(shí),應(yīng)力、應(yīng)變、時(shí)間或更多其他物理量變化率之間關(guān)系的物性方程,能反映材料屬性隨運(yùn)動(dòng)條件…

        2022年6月28日
      • 科珀28分李月汝未登場(chǎng) 天空不敵王牌丟失榜首位置

        北京時(shí)間8月12日,WNBA常規(guī)賽繼續(xù)進(jìn)行,拉斯維加斯王牌主場(chǎng)迎戰(zhàn)芝加哥天空,盡管卡利婭-科珀得到了全場(chǎng)最高28分,但是王牌有4人得分上雙,前狀元秀凱爾西-普拉姆25分5助攻,率隊(duì)…

        2022年8月14日

      聯(lián)系我們

      聯(lián)系郵箱:admin#wlmqw.com
      工作時(shí)間:周一至周五,10:30-18:30,節(jié)假日休息