function Map()
{
this.elements = {};
this.size = 0;
}
// get the size of the Map
Map.prototype.size = function(){
return this.size;
};
// judge the Map's empty
Map.prototype.isEmpty = function(){
return (this.size < 1);
};
//clear the map
Map.prototype.clear = function() {
this.elements = {};
this.size = 0;
}
//add the elements
Map.prototype.put = function(key, value)
{
var oldValue = this.elements[key];
if(oldValue == undefined)
{
this.size++;
}
this.elements[key] = value;
return oldValue;
};
//get the value according to the key
Map.prototype.get = function(key)
{
return this.elements[key];
};
//remove the elements according to the key
Map.prototype.remove = function(key)
{
var oldValue = this.elements[key];
if(oldValue != undefined)
{
this.size--;
delete this.elements[key];
}
return oldValue;
};
//get all the keys of Map
Map.prototype.keys = function(){
var keyArray = new Array();
for(var j in this.elements){
keyArray.push(j);
}
return keyArray;
};
//get all the values of Map
Map.prototype.values = function(){
var valueArray = new Array();
for(var j in this.elements){
valueArray.push(this.elements[j]);
}
return valueArray;
};
//contain key
Map.prototype.containsKey = function(key) {
for(var j in this.elements){
if(j == value)return true;
}
return false;
}
//contain value
Map.prototype.containsValue = function(value) {
for(var j in this.elements){
if(this.elements[j] == value)return true;
}
return false;
}
function Set(getKey)
{
this.map = new Map();
this.getKey = getKey;
}
Set.prototype.add = function(value)
{
var key = this.getKey(value);
this.map.put(key, value);
}
Set.prototype.remove = function(value)
{
var key = this.getKey(value);
this.map.remove(key);
}
Set.protorype.getAll=function()
{
var tempArray=new Array();
for(var i in this.obj)
{
tempArray.push(i);
}
return tempArray;
}
Set.prototype.size = function()
{
return this.map.size();
}