function struct(key, value){
this.key = key;
this.value = value;
}
function put(key, value){
// for (var i = 0; i < this.map.length; i++)
// {
//if ( this.map[i].key === key )
//{
// this.map[i].value = value;
// return;
//}
// }
this.removeKey(key);
this.map[this.map.length] = new struct(key, value);
}
function putUnique(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);
}
function getFirstKey(){
if(this.map) {
return this.map[0].key;
} else {
return 0;
}
}
function getValue(i){
return this.map[i].value ;
}
function get(key)
{
for (var i = 0; i < this.map.length; i++) {
if ( this.map[i].key === key ) {
return this.map[i].value;
}
}
return null;
}
function removeKey(key)
{
var v;
for (var i = 0; i < this.map.length; i++) {
v = this.map.pop(); //pop() 移除数组中的最后一个元素并返回该元素;
if ( v.key === key )
continue;
this.map.unshift(v); //unshift() 将指定的元素插入数组开始位置并返回该数组
}
}
function getCount(){
return this.map.length;
}
function isEmpty(){
return this.map.length <= 0;
}
function removeAll(){
var v;
for (var i = 0; i < this.map.length; i++)
{
v = this.map.pop();
removeKey(v.key);
}
}
function getAllKey() {
var keyArr = new Array();
if (this.map) {
for (i=0; i<this.map.length; i++) {
keyArr[i] = this.map[i].key;
}
}
return keyArr;
}
function Mapping() {
this.map = new Array();
this.get = get;
this.put = put;
this.putUnique = putUnique;
this.removeKey = removeKey;
this.getCount = getCount;
this.isEmpty = isEmpty;
//this.removeAll=removeAll;
this.getFirstKey=getFirstKey;
this.getValue=getValue;
this.getAllKey = getAllKey;
}