复制代码代码如下 :
var map = function () {
this._entrys = new Array ();
this.put = 함수 (키, 값) {
if (key == null || key == undefined) {
반품;
}
var index = this._getIndex (키);
if (index == -1) {
var entry = new Object ();
Entrys.key = 키;
Entry.Value = 값;
this._entrys [this._entrys.length] = Entry;
}또 다른{
this._entrys [index] .Value = value;
}
};
this.get = function (key) {
var index = this._getIndex (키);
return (index! = -1)? this._entrys [index] .Value : null;
};
this.remove = function (키) {
var index = this._getIndex (키);
if (index! = -1) {
this._entrys.splice (index, 1);
}
};
this.clear = function () {
this._entrys.length = 0 ;;
};
this.contains = function (키) {
var index = this._getIndex (키);
return (index! = -1)? 사실 : 거짓;
};
this.getCount = function () {
이 this._entrys.length;
};
this.getEntrys = function () {
이 this._entrys;
};
this._getIndex = function (키) {
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 === 키) {// 동일합니다
반환 i;
}
}
반품 -1;
};
this._tostring = function () {
var string = "";
for (var i = 0; i <this.getEntrys (). length; i ++) {
String+= this.getEntrys () [i] .key+"::"+this.getEntrys () [i] .Value;
if (i! = this.getEntrys (). length-1) {
문자열 += ";";
}
}
리턴 문자열;
};
};