Map.constructor = Map;

function Map(){
    this.mainMap = new Array();
    this.referenceMap = new Array();
	
}

Map.prototype.getKeyIndex = function(keyObject){
  	var index = -1;
	for(var i = 0, len = this.referenceMap.length; index < 0 && i < len; i++){
		if(this.referenceMap[i] == keyObject) index = i;
	}    
    return index;
};

Map.prototype.add= function(keyObject, object){
    var existingIndex = this.getKeyIndex(keyObject);
    if(existingIndex >= 0) return -1;
    this.referenceMap.push(keyObject);
    this.mainMap.push(object);
    return this.getKeyIndex(keyObject);
};
Map.prototype.get= function(keyObject){;
    var index = this.getKeyIndex(keyObject);
	if(index < 0) return null;
    return this.mainMap[index];
};
Map.prototype.remove = function(keyObject){
	var index = this.getKeyIndex(keyObject);
	if(index < 0) return;
	this.referenceMap = this.referenceMap.removeByIndex(index);
	this.mainMap = this.mainMap.removeByIndex(index);
};
Map.prototype.getKeys = function(){
	var array = new Array();
	for(var i = 0, len = this.referenceMap.length; i < len; i++) array.push(this.referenceMap[i]);
	return array;
};
Map.prototype.getValues = function(){
	var array = new Array();
	for(var i = 0, len = this.mainMap.length; i < len; i++) array.push(this.mainMap[i]);
	return array;
};
Map.prototype.clear= function(){
   this.mainMap = new Array();
   this.referenceMap = new Array();
};

Map.prototype.size= function(){
    return this.refCounter;
};
Map.prototype.getByIndex= function(i){
    return this.mainMap[i];
};

Map.prototype.debug= function(){
    for(var i = 0, len = this.referenceMap.length; i < len; i++){
        Utils.debug("["+i+"] "+this.referenceMap[i]+" : "+this.mainMap[i]);
    }
    
};




/*HashMap.constructor = HashMap;

function HashMap(){
    this.mainMap = new Object();
    this.referenceMap = new Object();
    this.refCounter = 0;
}
HashMap.prototype.keyObjectToKey = function(keyObject){
    var ref= this.refCounter;
    this.referenceMap[ref] = keyObject;
    this.refCounter++;
    return ref;
};
HashMap.prototype.getRefFromKeyObject = function(keyObject){
    var ref = -1;
    for(i in this.referenceMap){
        var obj = this.referenceMap[i];
        
        if(obj == keyObject){
            ref = i;
            break;
        }    
    }
    
    return ref;
};

HashMap.prototype.add= function(keyObject, object){
    var ref = this.keyObjectToKey(keyObject);
    this.mainMap[ref] = object;
};
HashMap.prototype.get= function(keyObject){
    var ref = this.getRefFromKeyObject(keyObject);
    return this.mainMap[ref];
};

HashMap.prototype.getKeys = function(){
	var array = new Array();
	for(var i = 0; i < this.refCounter; i++) array.push(this.referenceMap[i]);
	return array;
};
HashMap.prototype.getValues = function(){
	var array = new Array();
	for(var i = 0; i < this.refCounter; i++) array.push(this.mainMap[i]);
	return array;
};
HashMap.prototype.clear= function(){
   this.mainMap = new Object();
   this.referenceMap = new Object();
   this.refCounter = 0;
};

HashMap.prototype.size= function(){
    return this.refCounter;
};
HashMap.prototype.getByNum= function(i){
    return this.mainMap[i];
};

HashMap.prototype.debug= function(){
    for(i in this.mainMap){
        Utils.debug(i+" "+this.referenceMap[i]+" : "+this.mainMap[i])
    }
    
};*/

