JAVASCRIPT HashTable
更新時間:2007年01月22日 00:00:00 作者:
function Hashtable()
{
this._hash = new Object();
this.add = function(key,value){
if(typeof(key)!="undefined"){
if(this.contains(key)==false){
this._hash[key]=typeof(value)=="undefined"?null:value;
return true;
} else {
return false;
}
} else {
return false;
}
}
this.remove = function(key){delete this._hash[key];}
this.count = function(){var i=0;for(var k in this._hash){i++;} return i;}
this.items = function(key){return this._hash[key];}
this.contains = function(key){ return typeof(this._hash[key])!="undefined";}
this.clear = function(){for(var k in this._hash){delete this._hash[k];}}
}
var a = new Hashtable();
a.add("aa");
a.add("bb",2342);
a.add("bb",2342);
a.remove("aa");
alert(a.count());
alert(a.contains("bb"));
alert(a.contains("aa"));
alert(a.items("bb"));
{
this._hash = new Object();
this.add = function(key,value){
if(typeof(key)!="undefined"){
if(this.contains(key)==false){
this._hash[key]=typeof(value)=="undefined"?null:value;
return true;
} else {
return false;
}
} else {
return false;
}
}
this.remove = function(key){delete this._hash[key];}
this.count = function(){var i=0;for(var k in this._hash){i++;} return i;}
this.items = function(key){return this._hash[key];}
this.contains = function(key){ return typeof(this._hash[key])!="undefined";}
this.clear = function(){for(var k in this._hash){delete this._hash[k];}}
}
var a = new Hashtable();
a.add("aa");
a.add("bb",2342);
a.add("bb",2342);
a.remove("aa");
alert(a.count());
alert(a.contains("bb"));
alert(a.contains("aa"));
alert(a.items("bb"));
您可能感興趣的文章:
- js實現(xiàn)HashTable(哈希表)的實例分析
- js模擬hashtable的簡單實例
- javascript hashtable 修正版 下載
- js 模擬實現(xiàn)類似c#下的hashtable的簡單功能代碼
- javascript 哈希表(hashtable)的簡單實現(xiàn)
- javascript hashtable實現(xiàn)代碼
- js數(shù)組去重的hash方法
- 淺談js多維數(shù)組和hash數(shù)組定義和使用
- javascript實現(xiàn)獲取字符串hash值
- javascript中實現(xiàn)兼容JAVA的hashCode算法代碼分享
- javascript實現(xiàn)的HashMap類代碼
- js實現(xiàn)hashtable的賦值、取值、遍歷操作實例詳解
相關文章
讓 JavaScript 輕松支持函數(shù)重載 (Part 2 - 實現(xiàn))
在上一篇文章里,我們設計了一套能在JavaScript中描述函數(shù)重載的方法,這套方法依賴于一個叫做Overload的靜態(tài)類,現(xiàn)在我們就來看看如何實現(xiàn)這個靜態(tài)類。2009-08-08用javascript實現(xiàn)gb2312轉(zhuǎn)utf-8的腳本
用javascript實現(xiàn)gb2312轉(zhuǎn)utf-8的腳本...2007-05-05