欢迎来到福编程网,本站提供各种互联网专业知识!

JAVASCRIPT HashTable

发布时间:2007-01-22 作者: 来源:转载
functionHashtable(){this._hash=newObject();this.add=function(key,value){if(typeof(key)!="undefined"){if(this.contains(key)==false){this._hash[key]=typeof(value)=="undefined"?null:value;returntrue;}else{returnfalse;}}else{returnfalse;}}t
functionHashtable()
{
this._hash=newObject();
this.add=function(key,value){
if(typeof(key)!="undefined"){
if(this.contains(key)==false){
this._hash[key]=typeof(value)=="undefined"?null:value;
returntrue;
}else{
returnfalse;
}
}else{
returnfalse;
}
}
this.remove=function(key){deletethis._hash[key];}
this.count=function(){vari=0;for(varkinthis._hash){i++;}returni;}
this.items=function(key){returnthis._hash[key];}
this.contains=function(key){returntypeof(this._hash[key])!="undefined";}
this.clear=function(){for(varkinthis._hash){deletethis._hash[k];}}

}

vara=newHashtable();

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"));

相关推荐