/**
|
* @author Ryan
|
*/
|
function HashMap(){
|
this.map = {};
|
this.length = 0;
|
};
|
|
HashMap.prototype.exist = function(key){
|
return typeof this.map[key] != "undefined";
|
};
|
|
HashMap.prototype.put = function(key, val){
|
if(!this.exist(key)){
|
this.length++;
|
}
|
this.map[key] = val;
|
};
|
|
HashMap.prototype.get = function(key){
|
if(this.exist(key)){
|
return this.map[key];
|
}
|
|
return null;
|
};
|
|
HashMap.prototype.remove = function(key){
|
if(this.exist(key)){
|
this.length--;
|
delete this.map[key];
|
}
|
};
|
|
HashMap.prototype.clear = function(){
|
this.map = {};
|
this.length = 0;
|
};
|
|
HashMap.prototype.size = function(){
|
return this.length;
|
};
|
|
HashMap.prototype.keySet = function(){
|
var keys = new Array();
|
for(var key in this.map){
|
keys.push(key);
|
}
|
|
return keys;
|
};
|
|
HashMap.prototype.valSet = function(){
|
var vals = new Array();
|
for(var key in this.map){
|
vals.push(this.map[key]);
|
}
|
|
return vals;
|
};
|
|
HashMap.prototype.showMe = function(){
|
var sb = "";
|
for(var key in this.map){
|
sb = sb + " [" + key + "]=" + this.map[key];
|
}
|
|
return sb;
|
};
|