<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
            阅读 138
            收藏 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>