// file: tr_ht_hash_1.cc
//

// isip include files
//
#include "train_hash_table.h"
#include "train_hash_table_constants.h"
 
// method: hash_lookup_cc
//
// arguments:
//  char_1* str : (input) the string to be looked up in the hash table
//
// return: a Train_Hash_cell pointer to the cell containing this entry
//
// this method looks up an entry for the given string in the hash table
// using the standard hash function in Kernighan & Ritchie (pp 145)
//
Train_Hash_cell* Train_Hash_table::hash_lookup_cc(char_1* str_a) {

  // index variables
  //
  char_1* wstr = (char_1*)NULL;
  Train_Hash_cell* cell = (Train_Hash_cell*)NULL;
  
  // find the cell containing this string
  //
  int_4 index = hash_string_cc(str_a);
  for (cell = cells_d[index]; cell != (Train_Hash_cell*)NULL;
       cell = cell->get_next_cc()) {
    
    // get the key string in this cell
    //
    cell->get_key_cc(wstr);
    
    // compare with the input string
    //
    if (strcmp((char*)wstr, (char*)str_a) == 0) {
      break;
    }
  }
  
  // exit gracefully
  //
  return cell;
}

