/*
* MAP object to implement the MAP function
*
* Interface:
* Size () gets the number of MAP elements
* IsEmpty () determines whether the MAP is empty.
* Clear () deletes all MAP elements.
* Add an element (key, value) to the MAP using put (key, value)
* Remove (key) deletes the element of the specified KEY. If the key is successfully deleted, True is returned. If the KEY is failed, False is returned.
* Get (key) gets the element VALUE of the specified KEY. If the VALUE fails, NULL is returned.
* Element (index) obtains the elements of the specified index (using element. key, element. value to obtain KEY and VALUE). If the element fails, NULL is returned.
* ContainsKey (key) determines whether the MAP contains elements of the specified KEY.
* ContainsValue (value) determines whether the MAP contains the element of the specified VALUE.
* Values () obtains the ARRAY (ARRAY) of all values in the MAP)
* Keys () obtains the ARRAY (ARRAY) of all keys in the MAP)
*
* Example:
* Var map = new Map ();
*
* Map. put ("key", "value ");
* Var val = map. get ("key ")
*......
*
*/
Function Map (){
This. elements = new Array ();
// Obtain the number of MAP elements
This. size = function (){
Return this. elements. length;
};
// Determine whether the MAP is empty
This. isEmpty = function (){
Return (this. elements. length <1 );
};
// Delete All MAP elements
This. clear = function (){
This. elements = new Array ();
};
// Add the element (key, value) to the MAP)
This. put = function (_ key, _ value ){
This. elements. push ({
Key: _ key,
Value: _ value
});
};
// Delete the element of the specified KEY. If the KEY is successfully deleted, True is returned. If the KEY fails to be deleted, False is returned.
This. remove = function (_ key ){
Var bln = false;
Try {
For (I = 0; I <this. elements. length; I ++ ){
If (this. elements [I]. key = _ key ){
This. elements. splice (I, 1 );
Return true;
}
}
} Catch (e ){
Bln = false;
}
Return bln;
};
// Obtain the element VALUE of the specified KEY. If the VALUE fails, NULL is returned.
This. get = function (_ key ){
Try {
For (I = 0; I <this. elements. length; I ++ ){
If (this. elements [I]. key = _ key ){
Return this. elements [I]. value;
}
}
} Catch (e ){
Return null;
}
};
// Obtain the elements of the specified index (using element. key, element. value to obtain KEY and VALUE). If the index fails, NULL is returned.
This. element = function (_ index ){
If (_ index <0 | _ index> = this. elements. length ){
Return null;
}
Return this. elements [_ index];
};
// Determine whether the MAP contains the specified KEY element.
This. containsKey = function (_ key ){
Var bln = false;
Try {
For (I = 0; I <this. elements. length; I ++ ){
If (this. elements [I]. key = _ key ){
Bln = true;
}
}
} Catch (e ){
Bln = false;
}
Return bln;
};
// Determine whether the MAP contains the specified VALUE element.
This. containsValue = function (_ value ){
Var bln = false;
Try {
For (I = 0; I <this. elements. length; I ++ ){
If (this. elements [I]. value = _ value ){
Bln = true;
}
}
} Catch (e ){
Bln = false;
}
Return bln;
};
// Obtain the ARRAY (ARRAY) of all values in the MAP)
This. values = function (){
Var arr = new Array ();
For (I = 0; I <this. elements. length; I ++ ){
Arr. push (this. elements [I]. value );
}
Return arr;
};
// Obtain the ARRAY (ARRAY) of all keys in the MAP)
This. keys = function (){
Var arr = new Array ();
For (I = 0; I <this. elements. length; I ++ ){
Arr. push (this. elements [I]. key );
}
Return arr;
};
}
From Moving