为什么HashMap 的加载因子是0.75?

在这里插入图片描述

static final int hash(Object key) {
    int h;
    return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
// AbstractMap
public int hashCode() {
     int h = 0;
     Iterator<Entry<K,V>> i = entrySet().iterator();
     while (i.hasNext())
         h += i.next().hashCode();

     return h;
}

在这里插入图片描述
在这里插入图片描述

Hi = (H(key) + di) MOD m,其中i=1,2,,k(k<=m-1)

在这里插入图片描述
在这里插入图片描述

Hi = RHi(key), 其中i=1,2,,k

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

* Ideally, under random hashCodes, the frequency of
* nodes in bins follows a Poisson distribution
* (http://en.wikipedia.org/wiki/Poisson_distribution) with a
* parameter of about 0.5 on average for the default resizing
* threshold of 0.75, although with a large variance because of
* resizing granularity. Ignoring variance, the expected
* occurrences of list size k are (exp(-0.5) * pow(0.5, k) /
* factorial(k)). The first values are:
* 0:    0.60653066
* 1:    0.30326533
* 2:    0.07581633
* 3:    0.01263606
* 4:    0.00157952
* 5:    0.00015795
* 6:    0.00001316
* 7:    0.00000094
* 8:    0.00000006
* more: less than 1 in ten million

在这里插入图片描述

0:    0.60653066
1:    0.30326533
2:    0.07581633
3:    0.01263606
4:    0.00157952
5:    0.00015795
6:    0.00001316
7:    0.00000094
8:    0.00000006

在这里插入图片描述

参考资料

[1]泊松分布和指数分布:10分钟教程:

http://www.ruanyifeng.com/blog/2015/06/poisson-distribution.html

转载: https://mp.weixin.qq.com/s?__biz=MzA3MjMwMzg2Nw==&mid=2247509609&idx=1&sn=614d2c9d3f23fa55a306d5105cc91178&chksm=9f22b3fda8553aeb42067cdddeb8c75369878d7faf776e59154d1eccb0e9bc56ef9a7d0e8500&scene=126&sessionid=1695613955&key=bb7fb9914ffd1349d953cf11956bf849913204b219546563f3b407e2be22dddebf1a991158ce5c811911f866d87c9f6bf6958860ebfce00d4428328e5d3a0876fb4c68088015b7a3308da8865bb386b5cb606400df2cef4113770cff938bd38da61f159fb023c963e4f5539c60f06367668838e42d075ff89153a4391d03a2fa&ascene=0&uin=MTM3NDE5NzQ2Mw%3D%3D&devicetype=Windows+11+x64&version=63090719&lang=zh_CN&countrycode=AU&exportkey=n_ChQIAhIQFlYyjkGzUEslFCfxzpu6PRLgAQIE97dBBAEAAAAAAOL6BW5CWvIAAAAOpnltbLcz9gKNyK89dVj06tXQ6iuzrbA53yqX9UccXczS17haAFCUVQJFlvQpZdg2svY0plbpEWFSFj36XWUSFUG4UEIlizT7DkfsHw1iLtvbaDM73ND530Y%2Biq0k366EsFkqXA%2BBvYzredz2jIxgMvcLYH1wCz1%2BQLQQIUJuK%2FriAKB6%2BjDcjifngV7fq0ltGWX18BCS3OL325ZA2zyASdIkkG2g27NskoCJmqw1HJb7Rsf5Nko4j4HSR0jztXZVULd2HVah2fDg&acctmode=0&pass_ticket=tJ2mQaGoQbxK6f%2BodOSqknpNy4tZR37JM6AWqkMKaCo%2BfD7TJS7dd%2Bze7rA2L3v9&wx_header=1&fasttmpl_type=0&fasttmpl_fullversion=6872077-zh_CN-zip&fasttmpl_flag=3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值