#include "CacheIterator.h"

CacheIterator::CacheIterator(Cache* initCache)
{
  cache = initCache;
  entry = NULL;
  prev = NULL;
  slot = -1;
}

  
CacheEntry* CacheIterator::getCurrent()
{
  return entry;
}
  

int CacheIterator::moveNext()
{
  prev = entry;
  
  // entry is NULL if we just initialized.
  if (entry != NULL)
    entry = entry->getNext();

  while (entry == NULL)
    {
      slot++;
      if (slot == (1 << cache->hashTableBits))
	return 0;

      prev = NULL;
      entry = cache->cacheArray[slot];
    }
  
  // printf("CacheIterator::moveNext: next is %p\n", getCurrent());

  return 1;
}
