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的賦值、取值、遍歷操作實例詳解
相關(guān)文章
5個可以幫你理解JavaScript核心閉包和作用域的小例子
這篇文章主要介紹了5個可以幫你理解JavaScript核心閉包和作用域的小例子,本文是翻譯自國外的一篇文章,短小精悍,需要的朋友可以參考下2014-10-10
js或jquery動態(tài)輸出select option的實現(xiàn)代碼
在 JavaScript 中動態(tài)生成 <option> 元素并添加到 <select> 下拉列表中,可以通過以下幾種方式實現(xiàn),以下是不同場景下的完整代碼示例2025-03-03

