// file: tr_lat_arrange_0.cc
//

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

// method: lat_arrange_cc
//
// arguments:
//   Train_Lattice_node**& lnodes: (output) array of Train_Lattice nodes
//
// return: a logical_1 indicating status
//
// this method recursively arranges Train_Lattice nodes in order of index
//
logical_1 Train_Lattice::lat_arrange_cc(Train_Lattice_node**& lnodes_a) {
  
  // allocate correct amount of memory and initialize
  //
  if (lnodes_a != (Train_Lattice_node**)NULL) {
    delete [] lnodes_a;
  }
  lnodes_a = new Train_Lattice_node*[num_nodes_d];
  for (int_4 i = 0; i < num_nodes_d; i++) {
    lnodes_a[i] = (Train_Lattice_node*)NULL;
  }

  // define some local variables
  //
  Train_Lattice_node* latn = (Train_Lattice_node*)NULL;

  // get the hash cells of the Train_Lattice
  //
  Train_Hash_cell** lcells = lnode_d->get_cells_cc();
  int_4 hsize = lnode_d->get_size_cc();

  // loop over all cells and fill up array
  //
  for (int_4 k = 0; k < hsize; k++) {
    for (Train_Hash_cell* cell = lcells[k]; cell != (Train_Hash_cell*)NULL;
	 cell = cell->get_next_cc()) {
      latn = (Train_Lattice_node*)(cell->get_item_cc());
      lnodes_a[latn->get_node_index_cc()] = latn;
    }
  }
    
  // exit gracefully
  //
  return ISIP_TRUE;
}




  


  
