- 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));
- }
- }
算法----乘法连接法散列表
最新推荐文章于 2022-01-25 20:49:26 发布
本文介绍了一种基于链表解决冲突的多链式散列表实现方法。该方法使用0.618作为乘法因子进行散列计算,并提供了插入、删除及查找等基本操作。示例代码展示了如何创建一个初始大小为16的散列表,并进行一系列数据操作。
442

被折叠的 条评论
为什么被折叠?



