// file: tr_lat_set_8.cc
//

// isip include files
//
#include "train_lattice.h"
#include "train_lattice_constants.h"

// method: set_lat_node_cc
//
// arguments:
//  Train_Lattice_node* lnode: (input) Train_Lattice node to add to hash table
//
// return: a logical_1 indicating status
//
// this method adds a Train_Lattice node to the Train_Lattice table
//
logical_1 Train_Lattice::set_lat_node_cc(Train_Lattice_node* lnode_a) {

  // if this is a null node return
  //
  if (lnode_a == (Train_Lattice_node*)NULL) {
    return ISIP_FALSE;
  }
  
  // initialize the hash table if not created so far
  //
  if (lnode_d == (Train_Hash_table*)NULL) {
    lnode_d = new Train_Hash_table(TRAIN_HASH_TABLE_SIZE);
  }

  // memory manager
  //
  Train_Memory_manager* manager = Train_Link_list::get_manager_cc();
  
  // create a hash cell for the Train_Lattice node
  //
  char_1* key_str = new char_1[TRAIN_LATTICE_KEYSTR_LENGTH];
  sprintf((char*)key_str, "%p", lnode_a);
  Train_Hash_cell* hcell = manager->new_hash_cc();
  hcell->set_cc(key_str, (void_p)lnode_a);
  
  // insert the hash cell in the Train_Lattice node table
  //
  lnode_d->hash_insert_cc(hcell);

  // free memory
  //
  delete [] key_str;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
