- package com.eshore.sweetop.dataframe;
- import com.eshore.sweetop.data.KeyData;
- /*
- * linear probing
- * Note: secondary chustering
- */
- public class LineOpenHash extends OpenHash {
- public LineOpenHash(int size) {
- super(size);
- }
- @Override
- public int hash(int k,int i){
- return (multihash(k)+i)%table.length;
- }
- public int multihash(int k){
- double d=k*0.6180339887;
- int a=(int)Math.floor(table.length*(d-(new Double(d).intValue())));
- return a;
- }
- public static void main(String[] args) {
- OpenHash oh=new LineOpenHash(10);
- oh.insert(new KeyData(1));
- oh.insert(new KeyData(2));
- oh.insert(new KeyData(3));
- oh.insert(new KeyData(14));
- KeyData k=oh.search(2);
- System.out.println(k);
- }
- }
算法之线性探查
最新推荐文章于 2024-04-19 10:24:51 发布