// file: ht_hash_3.cc
//

// isip include files
//
#include "hash_table.h"
#include "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
//
int_4 Hash_table::hash_string_cc(char_1* str_a) {

  // index variable
  //
  uint_4 index = (uint_4)0;
  char_1* pos = (char_1*)NULL;
  uint_4 mask = size_d;
  
  // create the index for the given string using the universal hash
  // function obtained at
  // http://ourworld.compuserve.com/homepages/bob_jenkins/doobs.htm
  //
  for (pos = str_a; *pos != (char_1)ISIP_NULL; pos++) {
    index += (uint_4)*pos;
    index += (index << 10);
    index ^= (index >> 6);
  }
  index += (index << 3);
  index ^= (index >> 11);
  index += (index << 15);

  // mask the hash index
  //
  index %= mask;
      
  // exit gracefully
  //
  return (int_4)index;
}
