当前位置:网站首页>多大数量级会出现哈希碰撞
多大数量级会出现哈希碰撞
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左右的量级会出现哈希碰撞
边栏推荐
猜你喜欢

你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑

iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?

第十七章 Excel操作

QT专题:事件机制event基础篇

瑞萨RZ/G2L处理器详细测评

全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落

How to choose a truly "easy-to-use, high-performance" remote control software

Application scenarios of js anti-shake function and function throttling

Why use BGP?

Verilog's random number system task----$random
随机推荐
从零开始Blazor Server(5)--权限验证
阿里巴巴 CTO 程立:开源是基础软件的源头!
Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
图形化矩阵,矩阵到底长什么样?
LayaBox---TypeScript---声明合并
牛客网项目17节生成验证码 刷新验证码一直没反应
阿里CTO程立:阿里巴巴开源的历程、理念和实践
wireshark的安装教程(暖气片安装方法图解)
第十七章 Excel操作
LayaBox---TypeScript---命名空间和模块
向量点积(Dot Product),向量叉积(Cross Product)
Hello, my new name is "Bronze Lock/Tongsuo"
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)
太帅了!我用炫酷大屏展示爬虫数据!
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
关于缓存数据的探讨
基于列表的排队与叫号系统
全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
LayaBox---TypeScript---Iterator and generator