// file: lat_set_8.cc
//

// system include files
//
#include <string.h>

// isip include files
//
#include "lattice.h"
#include "lattice_constants.h"

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

  // if this is a null node return
  //
  if (lnode_a == (Lattice_node*)NULL) {
    return ISIP_FALSE;
  }

  // initialize the hash table if not created so far
  //
  if (lnode_d == (Hash_table*)NULL) {
    lnode_d = new Hash_table(num_nodes_d);
  }

  // memory manager
  //
  Memory_manager* manager = Link_list::get_manager_cc();
  
  // create a hash cell for the lattice node
  //
  static char_1 key_str[LATTICE_KEYSTR_LENGTH];
  strcpy((char*)key_str, "");
  sprintf((char*)key_str, "%p", lnode_a);
  Hash_cell* hcell = manager->new_hash_cc();
  hcell->set_cc(key_str, (void_p)lnode_a);
  
  // insert the hash cell in the lattice node table
  //
  lnode_d->hash_insert_cc(hcell);

  // exit gracefully
  //
  return ISIP_TRUE;
}
