最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Java 7/8 HashMap源碼詳解與面試題分析

2022-07-31 06:24 作者:裹魁鉞  | 我要投稿

?
05:39
?

碰撞 collision

鏈表解決

?
09:14
?


?
09:34
?

https://openjdk.org/projects/jdk7/

https://jdk.java.net/java-se-ri/7

https://www.oracle.com/java/technologies/javase/javase7-archive-downloads.html


?
18:43
?

1、負(fù)數(shù)mod為負(fù)數(shù)

2、較慢

mod本質(zhì)是除法,相較于位運(yùn)算

?
20:18
?


實(shí)際jdk1.7實(shí)現(xiàn):

hash & ( lenght - 1)

static int indexFor(int h, int length) {
    // assert Integer.bitCount(length) == 1 : "length must be a non-zero power of 2";
    return h & (length-1);
}

圖中老師有筆誤

32 = DEC 10,0000

32 -1 = DEC 1,1111

?
21:53
?

假如不是 a power of two,length - 1 就不是全1了

彈幕參考:相當(dāng)于就是用按位與的快速運(yùn)算代替了非常笨重的取余運(yùn)算

(很取巧)



?
22:54
?

/**
 * Retrieve object hash code and applies a supplemental hash function to the
 * result hash, which defends against poor quality hash functions.  This is
 * critical because HashMap uses power-of-two length hash tables, that
 * otherwise encounter collisions for hashCodes that do not differ
 * in lower bits. Note: Null keys always map to hash 0, thus index 0.
 */
final int hash(Object k) {
    int h = hashSeed;
    if (0 != h && k instanceof String) {
        return sun.misc.Hashing.stringHash32((String) k);
    }

    h ^= k.hashCode();

    // This function ensures that hashCodes that differ only by
    // constant multiples at each bit position have a bounded
    // number of collisions (approximately 8 at default load factor).
    h ^= (h >>> 20) ^ (h >>> 12);
    return h ^ (h >>> 7) ^ (h >>> 4);
}




Java 7/8 HashMap源碼詳解與面試題分析的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
蓝田县| 甘南县| 海淀区| 廉江市| 潮州市| 韶山市| 麟游县| 塘沽区| 濮阳县| 吉木萨尔县| 隆回县| 林周县| 溆浦县| 东乡族自治县| 饶阳县| 冀州市| 台安县| 忻州市| 磐安县| 阿克陶县| 恩施市| 滕州市| 松滋市| 鄂托克前旗| 佛冈县| 张家港市| 乐都县| 凤台县| 昌吉市| 沂源县| 淳化县| 高邑县| 河间市| 东兴市| 澎湖县| 枣强县| 醴陵市| 贵溪市| 保康县| 吴江市| 兰溪市|