/**
 * Copyright 2005 Netfluid Ltd. All rights reserved.
 * Use is subject to license terms.
 *
 */

function SlotAllocator_allocate(object) {
  for (i=1; i<this._map.length; ++i)
    if (this._map[i] == null) {
      this._map[i] = object;
      return i;
    }
  return 0;
}

function SlotAllocator_free(slot) {
  this._map[slot] = null;
  /*
    for (i=1; i<this._map.length; ++i)
    if (this._map[i] == object) {
    this._map[i] = null;
    return;
    }
  */
}

function SlotAllocator_getObject(slot) {
  //alert("SlotAllocator_getObject " + slot + " " + this._map[slot]);
  return this._map[slot];
}

function SlotAllocator_getSlot(object) {
  //alert("SlotAllocator_getSlot");
  for (i=1; i<this._map.length; ++i)
    if (this._map[i] == object) {
      //alert("SlotAllocator_getSlot " + i);
      return i;
    }
  //alert("SlotAllocator_getSlot NOT FOUND");
  return 0;
}

function SlotAllocator() {
  this.allocate = SlotAllocator_allocate;
  this.free = SlotAllocator_free;
  this.getObject = SlotAllocator_getObject;
  this.getSlot = SlotAllocator_getSlot;

  var N_SLOTS = 256;
  this._map = new Array(N_SLOTS);
  for (i=0; i<this._map.length; ++i)
    this._map[i] = null;
}

