c++ - 是否有满足以下条件的散列函数
问题描述
是否有满足以下条件的散列算法?
let "hash_funct" be a hashing function that takes two args, and returns a hash value. so all the following will be true
Hash1 = hash_funct(arg1, arg2) <=> hash_funct(Hash1, arg1) = hash_funct(Hash1, arg2) = Hash1;
谁能指出我这个算法?或者如果它不存在,任何人都可以与我合作发明它吗?
更多解释:
想象一个 setS={A,B,C,D}
和上面的 Hashing 函数。
如果我们可以 make: Hash1 = hash_funct(A,B,C,D)
,那么我们可以X
通过检查哈希结果来检查一个元素是否在集合中hash_funct(Hash1,X) == Hash1 ? belogns to the set : doesn't belong
使用此属性,我们检查集合中元素的存在性 O(1) 而不是 O(NlogN)
解决方案
我想最高公因数(Hcf)适合这里。设 a 和 b 是两个数,x 是它们的最大公因数。
hcf(a,b) = x.
这意味着a = x*m
和b = x*n
。这显然意味着:
hcf(x,x*m) = hcf(x,x*n) = hcf(x*n,x*m) = x
推荐阅读
- android - Flutter SDK 目录相关问题
- javascript - 每当在底部添加新 div 时都需要滚动到底部
- python-3.x - 有人可以帮我解决我的python代码中的错误吗?
- docker - 为什么我在 docker 中使用 Go 得到 404
- docker - 豆荚没有被创建,也没有在很长一段时间后运行
- sqlite - 被解雇的 Dismissible 小部件仍然是颤动树的一部分
- c++ - 如何将色彩空间信息添加到在 OPenCV 中使用“imwrite”创建的 Radiance HDR 格式文件
- tensorflow.js - 启用在本地计算机中使用 Tensorflow JS
- python - 熊猫造型:df中相同值的不同颜色?
- ubuntu - 如何在 Ubuntu 18.04LTS(Dell inspiron 13 型号)中设置电池阈值选项