JAVASCRIPT HashTable
更新時(shí)間: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實(shí)現(xiàn)HashTable(哈希表)的實(shí)例分析
- js模擬hashtable的簡(jiǎn)單實(shí)例
- javascript hashtable 修正版 下載
- js 模擬實(shí)現(xiàn)類似c#下的hashtable的簡(jiǎn)單功能代碼
- javascript 哈希表(hashtable)的簡(jiǎn)單實(shí)現(xiàn)
- javascript hashtable實(shí)現(xiàn)代碼
- js數(shù)組去重的hash方法
- 淺談js多維數(shù)組和hash數(shù)組定義和使用
- javascript實(shí)現(xiàn)獲取字符串hash值
- javascript中實(shí)現(xiàn)兼容JAVA的hashCode算法代碼分享
- javascript實(shí)現(xiàn)的HashMap類代碼
- js實(shí)現(xiàn)hashtable的賦值、取值、遍歷操作實(shí)例詳解
相關(guān)文章
js設(shè)置默認(rèn)時(shí)間跨度過(guò)程詳解
這篇文章主要介紹了js設(shè)置默認(rèn)時(shí)間跨度過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
基于Html+CSS+JS實(shí)現(xiàn)手動(dòng)放煙花效果
這篇文章主要介紹了利用Html+CSS+JavaScript實(shí)現(xiàn)的放煙花效果,文中一共實(shí)現(xiàn)了兩種方式:手動(dòng)和自動(dòng),文中的示例代碼講解詳細(xì),感興趣的可以試一試2022-01-01
5個(gè)可以幫你理解JavaScript核心閉包和作用域的小例子
這篇文章主要介紹了5個(gè)可以幫你理解JavaScript核心閉包和作用域的小例子,本文是翻譯自國(guó)外的一篇文章,短小精悍,需要的朋友可以參考下2014-10-10
javascript中json基礎(chǔ)知識(shí)詳解
本文主要介紹了json的基礎(chǔ)知識(shí)。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
js或jquery動(dòng)態(tài)輸出select option的實(shí)現(xiàn)代碼
在 JavaScript 中動(dòng)態(tài)生成 <option> 元素并添加到 <select> 下拉列表中,可以通過(guò)以下幾種方式實(shí)現(xiàn),以下是不同場(chǎng)景下的完整代碼示例2025-03-03
javascript 拖動(dòng)表格行實(shí)現(xiàn)代碼
用js實(shí)現(xiàn)的拖動(dòng)表格的tr行的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-05-05

