#include "oop.h"

IdentityDictionary::IdentityDictionary(int size) : Dictionary(size)
{
}

oop IdentityDictionary::classNew(int size)
{
  return new IdentityDictionary(size);
}

int IdentityDictionary::scanFor(oop anObject)
{
  int finish= mArray->size();
  int start= anObject->identityHash() % finish;
  // Search from (hash mod size) to the end.
  for (int index= start;  index < finish;  ++index)
    {
      oop element= mArray->at(index);
      if ((!element) || (element->key() == anObject))
	return index;
    }
  for (int index= 0;  index < start;  ++index)
    {
      oop element= mArray->at(index);
      if ((!element) || (element->key() == anObject))
	return index;
    }
  return -1;  // No match AND no empty slot
}

oop IdentityDictionary::keys(void)
{
  oop keys= new IdentitySet(mArray->size());
  iterate(this, iterator)
    keys->add(iterator.element()->key());
  return keys;
}

