当前位置:网站首页>多大数量级会出现哈希碰撞
多大数量级会出现哈希碰撞
2022-08-02 10:13:00 【CBeann】
写作目的
今天在网上看到一个有意思的问题是多大的数据量会出现哈希碰撞?我当时的想法是2的32次方,因此hascode是init类型的,哈哈。
还是可以写个demo实验一下的。真实答案是10W5K左右的量级会出现哈希碰撞
实验
实验代码
package HashCcollision;
import java.util.HashSet;
import java.util.Set;
/** * @author chaird * @create 2022-07-31 22:08 */
public class App {

public static void main(String[] args) {
Set<Integer> set = new HashSet<>();
int hashcode = 0;
// 10w
int size = 11 * 10000;
System.out.println("init :" + size);
for (int i = 0; i < size; i++) {
hashcode = new Object().hashCode();
if (set.contains(hashcode)) {
System.out.println("第" + i + "次出现了 哈希冲突");
} else {
set.add(hashcode);
}
}
System.out.println("finish :" + set.size());
}
}
实验结果
如下图所示, 当数量量达到10W~11W的时候会出现哈希碰撞
结论
10W5K左右的量级会出现哈希碰撞
边栏推荐
- 你好,我的新名字叫“铜锁/Tongsuo”
- Smoothing of time series data in R language: smoothing time series data to remove noise using the dpill function and locpoly function of the KernSmooth package
- 太帅了!我用炫酷大屏展示爬虫数据!
- QT专题:组合会话框和文本编辑器
- Use compilation to realize special effects of love
- How to choose a truly "easy-to-use, high-performance" remote control software
- LayaBox---TypeScript---JSX
- 【云原生】快出数量级的性能是怎样炼成的?就提升了亿点点
- R language ggplot2 visualization: based on the fill parameter and shape parameter in the aes function, custom draw a grouped line chart and add data points (scatter points), use the legend.position fu
- 每日一题练习1-15
猜你喜欢

Why use BGP?

Use compilation to realize special effects of love

带你认识40G单纤双向光模块-QSFP+ BiDi光模块

STL中list实现

Application scenarios of js anti-shake function and function throttling

yolov7 innovation point

npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.

超赞!发现一个APP逆向神器!

ConvNeXt论文及实现

php组件漏洞
随机推荐
超赞!发现一个APP逆向神器!
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
Hello, my new name is "Bronze Lock/Tongsuo"
armv7与armv8的区别(v8和w12的区别)
LayaBox---TypeScript---Mixins
瑞萨RZ/G2L处理器详细测评
牛客网项目17节生成验证码 刷新验证码一直没反应
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
【云原生】快出数量级的性能是怎样炼成的?就提升了亿点点
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
LayaBox---TypeScript---三斜线指令
重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
Naive Bayesian Method of Li Hang's "Statistical Learning Methods" Notes
阿里巴巴 CTO 程立:开源是基础软件的源头!
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
LayaBox---TypeScript---命名空间和模块
牛客网项目2.7开发注册功能 报错This application has no explicit mapping for /error......
LayaBox---TypeScript---迭代器和生成器
周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!
阿里CTO程立:阿里巴巴开源的历程、理念和实践