演算法-----二次探查
阿新 • • 發佈:2018-12-25
- package com.eshore.sweetop.dataframe;
- import java.math.BigInteger;
- import com.eshore.sweetop.data.KeyData;
- publicclass 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);
- }
- publicint hash(int k,int i){
- return (multihash1(k)+i*multihash2(k))%table.length;
- }
- publicint multihash1(int k){
- return k%table.length;
- }
- publicint multihash2(int k){
- return k%table.length+1;
- }
- publicstaticvoid main(String[] args) {
- OpenHash oh=
- 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);
- }
- }