// JavaScript Document
// Map Class
function struct(key, value)
{
  this.key = key;
  this.value = value;
}

function setAt(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 lookUp(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();
    if ( v.key === key )
      continue;
    this.map.unshift(v);
  }
}

function getCount(){
  return this.map.length;
}

function isEmpty(){
  return this.map.length <= 0;
}
function getKeys()
{
	if (this.map.length == 0)
		return null;
	var temp = new Array();
	for (var i = 0 ;i < this.map.length; i++)
	{
		temp.push(this.map[i].key);
	}
	return temp;
}
function classMap() {

  this.map = new Array();
  this.lookUp = lookUp;
  this.setAt = setAt;
  this.removeKey = removeKey;
  this.getCount = getCount;
  this.isEmpty = isEmpty;
  this.getKeys = getKeys;
}


function getResult(parentArray,gCat)
{
	var restArray =  new Array();
	var keys = parentArray.getKeys();
	for (var i=0; i < keys.length; i++)
	{
		var key = keys[i];
		var subCat = parentArray.lookUp(key);
		if (subCat.pCat==gCat)
		{
			restArray.push(subCat);
		}
	}
	return restArray;
}