当前位置:网站首页>多大数量级会出现哈希碰撞
多大数量级会出现哈希碰撞
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左右的量级会出现哈希碰撞
边栏推荐
- 迭代器失效问题
- You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
- After 21 years of graduation, I switched to software testing. From 0 income to a monthly salary of over 10,000, I am really lucky...
- 练习-17
- 行为型模式-策略模式
- 每日一题练习1-15
- LayaBox---TypeScript---Namespaces and modules
- LayaBox---TypeScript---高级类型
- Hello, my new name is "Bronze Lock/Tongsuo"
- wireshark的安装教程(暖气片安装方法图解)
猜你喜欢
随机推荐
【术语科普】关于集成工作台那些难懂的词儿,看这篇秒懂!
Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
DirectX修复工具增强版「建议收藏」
LayaBox---TypeScript---Mixins
The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
Use compilation to realize special effects of love
未知内容监控
R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
LayaBox---TypeScript---模块
你好,我的新名字叫“铜锁/Tongsuo”
每日一题练习1-15
currentstyle 织梦_dede currentstyle属性完美解决方案
牛客网项目17节生成验证码 刷新验证码一直没反应
行为型模式-模板方法模式
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
瑞萨RZ/G2L处理器详细测评
基于列表的排队与叫号系统
带你认识40G单纤双向光模块-QSFP+ BiDi光模块









