演算法-----二次探查
來源:互聯網
上載者:User
package com.eshore.sweetop.dataframe; import java.math.BigInteger; import com.eshore.sweetop.data.KeyData; public class DoubleOpenHash extends OpenHash { public DoubleOpenHash(int size) { // super((int)Math.pow(2, ((int)(Math.log(size)/Math.log(2)))+1)); super(new BigInteger(String.valueOf(size)).nextProbablePrime().intValue()); System.out.println(table.length); } public int hash(int k,int i){ return (multihash1(k)+i*multihash2(k))%table.length; } public int multihash1(int k){ return k%table.length; } public int multihash2(int k){ return k%table.length+1; } public static void main(String[] args) { OpenHash oh=new DoubleOpenHash(6); oh.insert(new KeyData(1)); oh.insert(new KeyData(2)); oh.insert(new KeyData(3)); oh.insert(new KeyData(14)); oh.insert(new KeyData(15)); KeyData k=oh.search(2); System.out.println(k); } }