// file: lat_arrange_0.cc
//

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

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

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

  // get the hash cells of the lattice
  //
  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 (Hash_cell* cell = lcells[k]; cell != (Hash_cell*)NULL;
	 cell = cell->get_next_cc()) {
      latn = (Lattice_node*)(cell->get_item_cc());
      lnodes_a[latn->get_node_index_cc()] = latn;
    }
  }
    
  // exit gracefully
  //
  return ISIP_TRUE;
}
