
#include <AtomList.h>

 AtomList::AtomList()
{
  nAtoms = 0;
  atomHash = nil;
}



AtomList *AtomList::duplicate(AtomList *atomListPtr)
{ int i;

  atomListPtr->~atomList();
  forall_defined(i,atomArray) if (atomArray[i])
    atomListPtr->addAtom (atomHash[i], &atomArray[i]);

  return(atomListPtr);
}

AtomList &AtomList::operator=(const AtomList &atomList)
{
  atomList.duplicate(this);
  /* is this OK, Q?, what do i return Q? */
}

int AtomList::addAtom(E atom)
{
  if (atomHash->lookup(atom->label))
       ERROR(1," Asking to add already added element in AtomList::addAtom");
  else
    atomHash->insert(atom->label, nAtoms+1); /* Q? +1 */

  nAtoms++;
 
   /* once the label,index pair is inserted in the hash
    add the index,pointer pair to the lookup table */
 if (int index = atomHash->inf(atomHash->lookup(element->label)))
   elementArray[index] = atom;
 else
   ERROR(3," unknown fatal error in AtomList::addAtom");

  return(1);
}

int AtomList::deleteAtom(const string &atomId)
{
  if (int index = atomHash->inf(atomHash->lookup(localId)))
    {
      atomHash->del_item(atomHash->lookup(localId));
      delete atomArray[index]; /* Q? */
      atomArray[index] = nil;
      return (1);
    }
  else
    return (0);
}

int AtomList::index(const string &atomId)
{
  return(atomHash->inf(atomHash->lookup(stomId)));
}
