複製代碼代碼如下:
var map = function(){
this._entrys = new Array();
this.put =函數(鍵,值){
if(key == null || key == undefined){
返回;
}
var index = this._getIndex(key);
if(index == -1){
var entry = new Object();
entry.key = key;
entry.value = value;
this._entrys [this._entrys.length] = entry;
}別的{
this._entrys [index] .value = value;
}
};
this.get = function(key){
var index = this._getIndex(key);
返回(index!= -1)? this._entrys [index] .value:null;
};
this.remove = function(key){
var index = this._getIndex(key);
如果(index!= -1){
this._entrys.splice(index,1);
}
};
this.clear = function(){
this._entrys.length = 0 ;;
};
this.contains = function(key){
var index = this._getIndex(key);
返回(index!= -1)? true:false;
};
this.getCount = function(){
返回this._entrys.length;
};
this.getEntrys = function(){
返回this._entrys;
};
this._getIndex = function(key){
if(key == null || key == undefined){
返回-1;
}
var _length = this._entrys.length;
for(var i = 0; i <_length; i ++){
var entry = this._entrys [i];
if(entry == null || entry == undefined){
繼續;
}
if(entry.key ===鍵){//等於
返回我;
}
}
返回-1;
};
this._tostring = function(){
var string =“”;
for(var i = 0; i <this.getEntrys()。長度; i ++){
string+= this.getEntrys()[i] .key+“ ::”+this.getEntrys()[i] .value;
if(i!= this.getEntrys()。長度-1){
字符串 +=“;”;
}
}
返回字符串;
};
};