- packagecom.eshore.sweetop.dataframe;
- importjava.math.BigInteger;
- importcom.eshore.sweetop.data.KeyData;
- publicclassDoubleOpenHashextendsOpenHash{
- publicDoubleOpenHash(intsize){
- //super((int)Math.pow(2,((int)(Math.log(size)/Math.log(2)))+1));
- super(newBigInteger(String.valueOf(size)).nextProbablePrime().intValue());
- System.out.println(table.length);
- }
- publicinthash(intk,inti){
- return(multihash1(k)+i*multihash2(k))%table.length;
- }
- publicintmultihash1(intk){
- returnk%table.length;
- }
- publicintmultihash2(intk){
- returnk%table.length+1;
- }
- publicstaticvoidmain(String[]args){
- OpenHashoh=newDoubleOpenHash(6);
- oh.insert(newKeyData(1));
- oh.insert(newKeyData(2));
- oh.insert(newKeyData(3));
- oh.insert(newKeyData(14));
- oh.insert(newKeyData(15));
- KeyDatak=oh.search(2);
- System.out.println(k);
- }
- }
算法之双重散列
最新推荐文章于 2025-06-22 17:33:47 发布
本文介绍了一种使用双散列技术实现的散列表类(DoubleOpenHash)。该类继承自OpenHash基类,并通过两个不同的散列函数(hash1和hash2)来解决冲突问题。在构造函数中使用BigInteger寻找最接近的素数作为散列表大小。
278

被折叠的 条评论
为什么被折叠?



