// FingerSet.H
//	JR
//	4/16/96
//	4/17/96	Tested.


typedef int Key;


class FingerSet
{
	private:
		LinList<Key> kys;
		LinList<Finger> fngrs;
		Boolean vld;

	public:
		
		FingerSet()
		:	kys(), fngrs(), vld(1)
		{}

		LinList<Finger>& fingers()
		{
			if(!fngrs.isEmpty()) assert(vld);
			return fngrs;
		}

		Finger& finger(Key key)
		{
			assert(vld);
			assert(kys.has(key));
			return fngrs[kys.indexOf(key)];
		}

		Key add(const DE& e,int n)
		{
					// generate a new key
			Finger f(e,n);
			Key k=0;
			while(kys.has(k)) k++;
					// append new item to list
			kys.append(k);
			fngrs.append(f);
					// return key to new item
			return k;
		}
		
		Key add(const Finger& f)
		{
					// generate a new key
			Key k=0;
			while(kys.has(k)) k++;
					// append new item to list
			kys.append(k);
			fngrs.append(f);
					// return key to new item
			return k;
		}
		
		Boolean remove(Key key)
		{
			LinListIterator<Key> ik(kys);
			LinListIterator<Finger> ifngr(fngrs);
			for(ik.init(),ifngr.init();ik.ok();++ik,++ifngr)
			{
				if(ik.ahead()==key)
				{
					ik.deletef();
					ifngr.deletef();
					return 1;
				}
			}
			return 0;
		}
		
		Boolean valid() const
		{
			return vld;
		}

		void markInvalid()
		{
			vld=0;
		}

		void clear()
		{
			fngrs.clear();
			kys.clear();
			vld=1;
		}

	friend ostream& operator<<(ostream& out,const FingerSet& fs);

};

ostream& operator<<(ostream& out,const FingerSet& fs)
{
	out << fs.kys << "  " << fs.fngrs ;
	return out;
}	
