CS-Notes icon indicating copy to clipboard operation
CS-Notes copied to clipboard

Java 容器 JDK.1.7 HashMap 扩容源代码描述

Open ruiHut opened this issue 7 years ago • 1 comments

Background:

https://github.com/CyC2018/CS-Notes/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#5-%E6%89%A9%E5%AE%B9-%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86

loadFactor | 装载因子,table 能够使用的比例,threshold = capacity * loadFactor。

Suggest change

loadFactor | 装载因子,table 能够使用的比例,threshold = (int)(newCapacity * loadFactor)。

Cause

Jdk 1.7 HashMap source code

    final float loadFactor; 
    int threshold;  

    void resize(int newCapacity) {
// do something()
        threshold = (int)(newCapacity * loadFactor);
    }

ruiHut avatar Aug 12 '19 07:08 ruiHut

@ruiHut ok

CyC2018 avatar Aug 18 '19 15:08 CyC2018