// file: tr_ht_hash_2.cc
//

// isip include files
//
#include "train_hash_table.h"
#include "train_hash_table_constants.h"
 
// method: hash_string_cc
//
// arguments:
//  char_1* str : (input) the string to be hashed
//
// return: an int_4 with the hash index
//
// this method computes the hash index for the given string using the
// standard hash function in Kernighan & Ritchie (pp 144)
//
int_4 Train_Hash_table::hash_string_cc(char_1* str_a) {

  // index variable
  //
  uint_4 index = (uint_4)0;

  // create the index for the given string
  //
  for (char_1* pos = str_a; *pos != (char_1)ISIP_NULL; pos++) {
    index = *pos + TRAIN_HASH_TABLE_FACTOR * index;
  }
  index = index % (uint_4)size_d;
  
  // exit gracefully
  //
  return (int_4)index;
}
