1. 程式人生 > >演算法-----二次探查

演算法-----二次探查

  1. package com.eshore.sweetop.dataframe;
  2. import java.math.BigInteger;
  3. import com.eshore.sweetop.data.KeyData;
  4. publicclass DoubleOpenHash extends OpenHash {
  5. public DoubleOpenHash(int size) {
  6. //      super((int)Math.pow(2, ((int)(Math.log(size)/Math.log(2)))+1));
  7. super(new BigInteger(String.valueOf(size)).nextProbablePrime().intValue());
  8.         System.out.println(table.length);
  9.     }
  10. publicint hash(int k,int i){
  11. return (multihash1(k)+i*multihash2(k))%table.length; 
  12.     }
  13. publicint multihash1(int k){
  14. return k%table.length;
  15.     }
  16. publicint multihash2(int k){
  17. return k%table.length+1;
  18.     }
  19. publicstaticvoid main(String[] args) {
  20.         OpenHash oh=
    new DoubleOpenHash(6);
  21.         oh.insert(new KeyData(1));
  22.         oh.insert(new KeyData(2));
  23.         oh.insert(new KeyData(3));
  24.         oh.insert(new KeyData(14));
  25.         oh.insert(new KeyData(15));
  26.         KeyData k=oh.search(2);
  27.         System.out.println(k);
  28.     }
  29. }