// file: tr_lat_index_0.cc
//

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

// method: index_nodes_cc
//
// arguments: none
//
// return: a logical_1 indicating status
//
// this method re-assigns the node indices of the Train_Lattice nodes to
// reflect the strt to end progression of the Train_Lattice
//
logical_1 Train_Lattice::index_nodes_cc() {

  // dummy variables
  //
  int_4 idx = (int_4)0;
  Train_Lattice_node* latn = (Train_Lattice_node*)NULL;

  // map for the new indices
  //
  int_4* map = new int_4[num_nodes_d];
  for (int_4 i = 0; i < num_nodes_d; i++) {
    map[i] = (int_4)-1;
  }
  
  // start with the start node of the Train_Lattice
  //
  update_index_cc(start_node_d, map, idx);

  // now update the node indices
  //
  Train_Hash_cell** lcells = lnode_d->get_cells_cc();
  int_4 hsize = lnode_d->get_size_cc();
  for (int_4 i = 0; i < hsize; i++) {
    for (Train_Hash_cell* cell = lcells[i]; cell != (Train_Hash_cell*)NULL;
	 cell = cell->get_next_cc()) {
      latn = (Train_Lattice_node*)(cell->get_item_cc());
      idx = latn->get_node_index_cc();
      latn->set_node_index_cc(map[idx]);
    }
  }    

  // free memory
  //
  delete map;
  map = (int_4*)NULL;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
