当前位置:网站首页>多大数量级会出现哈希碰撞
多大数量级会出现哈希碰撞
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左右的量级会出现哈希碰撞
边栏推荐
- The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
- 你好,我的新名字叫“铜锁/Tongsuo”
- MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
- Do you agree with this view?Most businesses are digitizing just to ease anxiety
- 如何选择一块真正“好用的、性能高”的远程控制软件
- 为什么要使用BGP?
- 牛客刷题——剑指offer(第三期)
- 图形化矩阵,矩阵到底长什么样?
- This article takes you to understand the commonly used models and frameworks of recommender systems
- LayaBox---TypeScript---三斜线指令
猜你喜欢
Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)
8月份的.NET Conf 活动 专注于 .NET MAUI
iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
Hello, my new name is "Bronze Lock/Tongsuo"
Linux system uninstall, install, upgrade, migrate clickHouse database
全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
如何选择一块真正“好用的、性能高”的远程控制软件
matlab-day02
How to choose a truly "easy-to-use, high-performance" remote control software
链表的实现
随机推荐
LayaBox---TypeScript---Namespaces and modules
21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
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...
链表的实现
R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、设置align参数指定结果数据中的时间标签取自窗口中的位置(参数right指定取自窗口的最右侧)
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
2022.7.25-7.31 AI行业周刊(第108期):值钱比赚钱更重要
You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
Spearman's correlation coefficient
The ggbarplot function of the R language ggpubr package visualizes the grouped histogram, sets the add parameter to mean_se to visualize the histogram of the mean values of different levels and adds
Using the TCP protocol, will there be no packet loss?
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
Event 对象,你很了解吗?
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
LayaBox---TypeScript---模块
DVWA Clearance Log 2 - Command Injection
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
wireshark的安装教程(暖气片安装方法图解)
关于缓存数据的探讨
MSYS2 QtCreator Clangd code analysis can not find mm_malloc.h problem remedy