- packagecom.eshore.sweetop.dataframe;
- importjava.util.LinkedList;
- importcom.eshore.sweetop.data.KeyData;
- publicclassMultiChainedHash{
- LinkedList<KeyData>[]table=newLinkedList[(int)Math.pow(2,6)];
- publicMultiChainedHash(){
- }
- publicMultiChainedHash(inti){
- table=newLinkedList[(int)Math.pow(2,i)];
- }
- publicvoidinsert(KeyDatao){
- if(table[hash(o.getKey())]==null)
- table[hash(o.getKey())]=newLinkedList<KeyData>();
- table[hash(o.getKey())].add(o);
- }
- publicvoiddelete(KeyDatao){
- table[hash(o.getKey())].remove(o);
- }
- publicKeyDatasearch(intk){
- for(KeyDatakd:table[hash(k)]){
- if(kd.getKey()==k){
- returnkd;
- }
- }
- returnnull;
- }
- publicinthash(intk){
- doubled=k*0.6180339887;
- inta=(int)Math.floor(table.length*(d-(newDouble(d).intValue())));
- returna;
- }
- publicstaticvoidmain(String[]args){
- MultiChainedHashch=newMultiChainedHash(4);
- ch.insert(newKeyData(2));
- ch.insert(newKeyData(3));
- ch.insert(newKeyData(13));
- ch.insert(newKeyData(4));
- ch.delete(newKeyData(3));
- System.out.println(ch.search(13));
- }
- }
算法----乘法连接法散列表
最新推荐文章于 2023-05-06 21:46:44 发布