// file: latn_add_5.cc
//

// isip include files
//
#include "lattice_node.h"
#include "lattice_node_constants.h"

// method: add_node_cc
//
// arguments:
//  Lattice_node* lat_node : (input) lattice node to add to next node
//  Lattice_node** lnode : (input) array of lattice nodes
//  int_4*& map_list : (input / output) the map from the old lattice to new
//  int_4& node_count : (input/output) the count of new lattice nodes
//  int_4& arc_count : (input/output) the count of new lattice arcs
//
// return: logical_1 indicating status
//
// this method adds all descendants of the input lattice node to the
// next words list --- it is used when compacting a large lattice to a
// smaller form
//
logical_1 Lattice_node::add_node_cc(Lattice_node* lat_node_a,
				    Lattice_node** lnode_a,
				    int_4*& map_list_a,
				    int_4& node_count_a,
				    int_4& arc_count_a) {
  
  float_4* lscore = lat_node_a->get_lm_scores_cc();
  float_4* ascore = lat_node_a->get_ac_scores_cc();
  float_4 lsc = (float_4)0;
  float_4 asc = (float_4)0;
  int_4 lcnt = (int_4)0;
  
  // get list of possible next words from the lattice node
  //
  Lattice_node* temp_node = (Lattice_node*)NULL;
  Link_list* next_list = lat_node_a->next_nodes_d;
  if (next_list != (Link_list*)NULL) {
    
    // loop through all the next words
    //
    for (Link_node* node = next_list->get_head_cc();
	 node != (Link_node*)NULL; node = node->get_next_cc()) {
      
      // set the language and acoustic scores
      //
      if (lscore != (float_4*)NULL) {
	lsc = lscore[lcnt];
      }
      if (ascore != (float_4*)NULL) {
	asc = ascore[lcnt];
      }
      
      // get the lattice node
      //
      temp_node = (Lattice_node*)(node->get_item_cc());
      
      // add these nodes to the new lattice
      //	
      add_node_cc(temp_node, lsc, asc, lnode_a, map_list_a,
		  node_count_a, arc_count_a);

      // increment count
      //
      lcnt++;
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
