<output id="ilehw"><bdo id="ilehw"><nobr id="ilehw"></nobr></bdo></output>
        <dl id="ilehw"><font id="ilehw"></font></dl>
          1. JDK hashmap 鏈表數組

            帝孤 發布于 2018/10/11 17:53
            閱讀 123
            收藏 0

            發生hash沖突的時候,  hashmap底層新的元素會覆蓋原有的元素, 新元素的next指向原有元素形成鏈表數組  ,   為什么不直接覆蓋呢,如果直接覆蓋的話, 就可以減少鏈表的存儲了, 這樣豈不是更節省空間嗎?  保留原有的數據值是為了什么, 有什么意義嗎?求各位大佬解惑

            加載中
            0
            煙頭
            煙頭

            equals會覆蓋,hashcode相同equals為false才會形成鏈表,另外java8以后鏈表長了會用紅黑樹

            0
            趙熠熠
            趙熠熠
                /**
                 * Computes key.hashCode() and spreads (XORs) higher bits of hash
                 * to lower.  Because the table uses power-of-two masking, sets of
                 * hashes that vary only in bits above the current mask will
                 * always collide. (Among known examples are sets of Float keys
                 * holding consecutive whole numbers in small tables.)  So we
                 * apply a transform that spreads the impact of higher bits
                 * downward. There is a tradeoff between speed, utility, and
                 * quality of bit-spreading. Because many common sets of hashes
                 * are already reasonably distributed (so don't benefit from
                 * spreading), and because we use trees to handle large sets of
                 * collisions in bins, we just XOR some shifted bits in the
                 * cheapest possible way to reduce systematic lossage, as well as
                 * to incorporate impact of the highest bits that would otherwise
                 * never be used in index calculations because of table bounds.
                 */
                static final int hash(Object key) {
                    int h;
                    return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
                }
            

             

            返回頂部
            頂部
            广东快乐十分实时开奖

                  <output id="ilehw"><bdo id="ilehw"><nobr id="ilehw"></nobr></bdo></output>
                  <dl id="ilehw"><font id="ilehw"></font></dl>

                            <output id="ilehw"><bdo id="ilehw"><nobr id="ilehw"></nobr></bdo></output>
                            <dl id="ilehw"><font id="ilehw"></font></dl>