// file: ngrl_node_2.cc
//

// isip include files
//
#include "ngram_list.h"
#include "ngram_list_constants.h"

// method: add_node_cc
//
// arguments:
//  int_4 index: (input) the desired node position in the array
//  Word* word: (input) the word in the desired ngram node
//  Ngram_node** hist: (input) the ngram node from the previous
//                     level which is the parent for the desired node
//  float_4 lmscore: (input) the lm score for the ngram node
//  float_4 backoff: (input) the backoff score for the ngram node
//  
// return: a logical_1 indicating success
//
// this method creates an ngram node with the given parameters and
// adds it to the current list at the specified position
//
logical_1 Ngram_list::add_node_cc(int_4 index_a, Word* word_a,
				  Ngram_node** hist_a, float_4 lmscore_a,
				  float_4 backoff_a) {

  // the memory manager
  //
  Memory_manager* manager = Link_list::get_manager_cc();

  // get an ngram node and set parameters
  //
  Ngram_node* node = manager->new_ngram_cc();
  node->set_word_cc(word_a);
  node->set_lmscore_cc(lmscore_a);
  node->set_backoff_cc(backoff_a);
  
  // insert the new node in the list
  //
  set_node_cc(index_a, node);
  
  // set the pointer in the parent node if needed
  //
  if (hist_a != (Ngram_node**)NULL) {
    if ((*hist_a) != (Ngram_node*)NULL) {
      if ((*hist_a)->get_next_node_cc() == (Ngram_node**)NULL) {
	(*hist_a)->set_next_node_cc(nodes_d + index_a);
      }
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
