【数据结构】基数排序的哈希表

本哈希表类以及相关类属于作者智能内核项目的一个组成部分。为了实现计算机智能化, 需要在超巨量的空间内快速地存储、检索、匹配和修改数据,传统的哈希表算法根本不适用, 而且在很多应用场合需要一种按整数方式自然排序的哈希树容器,但可惜数据结构理论和实践中都没有。因此作者一直在思索构造适用于这一目的的算法和容器。
我相信,人的大脑神经网络中一定存在一种类似的容器,不同的是基于某种多进制分叉运算的, 而不是基于二进制分叉运算的。
此实现版本是基于java语言的,稍后有时间的话,将实现一个c++语言版本的。若有读者花时间实现了的话,可将之共享出来,请发邮件给我:iamkarl@163.com

源代码Java下载

以下是Map的put模块代码示例:

V put(K key,V value) {
keyvalue<K,V> pair = new keyvalue<K,V>(key,value);
int code = pair.hashCode();
//System.out.println("put:"+code);
int hash = ((code>>24) & 0xff);

if(table[hash]==null){
table[hash] = pair;
return null;
}else{

if(table[hash] instanceof keyvalue ){
keyvalue<K,V> pair1 = (keyvalue<K,V>) table[hash];
MyMapUnit<K,V> mmu = new MyMapUnit<K,V>();];//新建包含256个插槽的数组对象
mmu.put(pair1,pair1.hashCode(),1);
mmu.put(pair,code,1);
table[hash] = mmu;
return null;

}

MyMapUnit<K,V> mmu = (MyMapUnit<K,V>)table[hash];

return mmu.put(pair,1);

}

}


V put(keyvalue<K,V> pair,int code,int index) {
if(index >= LAYER_LIMIT){
return endPut( pair,code);
}
//int hash = toHash(code,index);
int hash = 0;
switch(index){
case 0:hash = ((code>>24) & 0xff);break;
case 1:hash = ((code>>16) & 0xff);break;
case 2:hash = ((code>>8) & 0xff);break;
case 3:hash = (code & 0xff);
}
if(table[hash]==null){

table[hash] = pair;
return null;
}else{
//index++;
if(table[hash] instanceof keyvalue ){
keyvalue<K,V>();
mmu.put(pair1,index+1);
table[hash] = mmu;
return mmu.put(pair,index+1);

}
//MyMapUnit<K,V>)table[hash];
return ( (MyMapUnit<K,V>)table[hash] ).put(pair,index+1);

}

}private V endPut( keyvalue<K,int code) {//int hash = toHash(code,LAYER_LIMIT);int hash = (code & 0xff);if(table[hash]==null){table[hash] = pair;return null;}else{if(table[hash] instanceof keyvalue ){keyvalue<K,V>) table[hash];if (pair.equals(pair1)) {V oldValue = pair1.value;table[hash] = pair;return oldValue;// 已有同key元素,执行更新操作}HashMap<String,keyvalue<K,V>> map = new HashMap<String,V>>();map.put(pair1.key.toString(),pair1);map.put(pair.key.toString(),pair);table[hash] = map;return null;}conflictCount++;keyvalue<K,V> obj = ( (HashMap<String,V>>) table[hash] ).put(pair.key.toString(),pair);if(obj==null) return null;return obj.value;}}

相关文章

【啊哈!算法】算法3:最常用的排序——快速排序       ...
匿名组 这里可能用到几个不同的分组构造。通过括号内围绕的正...
选择排序:从数组的起始位置处开始,把第一个元素与数组中其...
public struct Pqitem { public int priority; ...
在编写正则表达式的时候,经常会向要向正则表达式添加数量型...
来自:http://blog.csdn.net/morewindows/article/details/6...