Maputil = function () {
This.map = new Array ();
};
Maputil.prototype = {
Update or Insert
Add:function (key, value) {
for (var i = 0; i < this.map.length; i++)
{
if (this.map[i].key+ "" = = = key+ "")
{
This.map[i].value = value;
Return
}
}
This.map[this.map.length] = new struct (key, value);
},
Put:function (key, value) {
for (var i = 0; i < this.map.length; i++)
{
if (this.map[i].key+ "" = = = key+ "")
{
This.map[i].value = value;
Return
}
}
This.map[this.map.length] = new struct (key, value);
},
Query
Get:function (key) {
for (var i = 0; i < this.map.length; i++)
{
if (this.map[i].key+ "= = key +" ")
{
return this.map[i].value;
}
}
return undefined;
},
Getkeybyindex:function (index) {
if (index >= 0 && Index < this.map.length) {
return this.map[index].key;
}
return null;
},
Getbyindex:function (index) {
if (index >= 0 && Index < this.map.length) {
return this.map[index].value;
}
return null;
},
Getindexbykey:function (key) {
for (var i = 0; i < this.map.length; i++)
{
if (this.map[i].key+ "= = = key +")
{
return i;
}
}
},
Delete
Remove:function (key) {
var V;
var len = this.map.length;
for (var i = 0; i < len; ++i)
{
v = this.map.pop ();
if (V.key = = = key) {
Continue
}
This.map.unshift (v);
}
},
Removebyindex:function (index) {
var V;
var len = this.map.length;
for (var i = 0; i < len; i++)
{
v = this.map.shift ();
if (i = = = Index) {
Continue
}
This.map.push (v);
}
},
Clear
Clear:function () {
This.map.splice (0, this.map.length);
},
Removeall:function () {
This.map.splice (0, this.map.length);
},
Size:function () {
return this.map.length;
},
Isempty:function () {
Return (this.map.length <= 0);
},
Tostring:function () {
var v= "";
for (var i = 0; i < this.map.length; i++) {
v+=this.map[i].key+ ":" +this.map[i].value+ ";"
}
return v;
}
};
Analog <key, value> data structure
function struct (key, value) {
This.key = key;
This.value = value;
};
Construction of Map data object under JS