// file: $isip/class/search/History/hist_05.cc
//

// isip include files
//
#include "History.h"

// method: hash
//
// arguments:
//   long capacity: (input) hash table capacity
//
// return: logical error status
//
// hash function for the hypothesis path class
//
long History::hash(long capacity_a) const {

  // declare local variables
  //
  ulong hash_index = 0;

  // when the history is empty return zero
  //
  if (isEmpty()) {
    return hash_index;
  }

  // save the current state
  //
  const_cast<History *>(this)->setMark();
  
  // loop over all elemenst in the stack
  //
  for (boolean more = const_cast<History *>(this)->gotoFirst();
       more;
       more = const_cast<History *>(this)->gotoNext()) {

    ulong index = const_cast<History *>(this)->getCurr()->getHashIndex();    
    hash_index = (hash_index << 5) ^ (hash_index >> 27) ^ index;
  }

  // restore the saved state
  //
  const_cast<History *>(this)->gotoMark();  
  
  // return the hash index
  //  
  return (hash_index % (capacity_a - 1));
}

