复制代码代码如下:
var map = function () {
this._entrys = new Array ();
this.put = function (chave, valor) {
if (key == null || key == indefinido) {
retornar;
}
var index = this._getIndex (chave);
if (index == -1) {
var entrada = new Object ();
entrada.Key = Key;
entrada.value = value;
this._entrys [this._entrys.length] = entrada;
}outro{
this._entrys [index] .Value = value;
}
};
this.get = function (key) {
var index = this._getIndex (chave);
retornar (índice! = -1)? this._entrys [index] .Value: null;
};
this.remove = function (key) {
var index = this._getIndex (chave);
if (index! = -1) {
this._entrys.splice (índice, 1);
}
};
this.clear = function () {
this._entrys.length = 0 ;;
};
this.contains = function (key) {
var index = this._getIndex (chave);
retornar (índice! = -1)? Verdadeiro: falso;
};
this.getCount = function () {
return this._entrys.length;
};
this.getEntrys = function () {
devolver this._entrys;
};
this._getIndex = function (key) {
if (key == null || key == indefinido) {
retornar -1;
}
var _length = this._entrys.length;
for (var i = 0; i <_length; i ++) {
var entrada = this._entrys [i];
if (entradas == null || entrada == indefinido) {
continuar;
}
if (Entry.key === key) {// igual
retornar i;
}
}
retornar -1;
};
this._toString = function () {
var string = "";
for (var i = 0; i <this.getEntrys (). comprimento; i ++) {
string+= this.getEntrys () [i] .Key+"::"+this.getEntrys () [i] .Value;
if (i! = this.getEntrys (). comprimento-1) {
String += ";";
}
}
retornar string;
};
};