// file: tr_lxn_node_1.cc
//

// isip include files
//
#include "train_lex_node.h"
#include "train_lex_node_constants.h"

// method: get_node_cc
//
// arguments:
//  int_4 phone : (input) the monophone index
//
// return: a Train_Lex_node* pointing to the lexical tree node with this
// phone
//
// this method searches all the child nodes of the current node for
// the specified phone and returns the match. if no such node exists,
// returns NULL
//
Train_Lex_node* Train_Lex_node::get_node_cc(int_4 phone_a) {

  // dummy variables
  //
  Train_Lex_node* node = (Train_Lex_node*)NULL;
  Train_Lex_node* lxn = (Train_Lex_node*)NULL;

  // make sure the link list of children exists
  //
  if (child_d != (Train_Link_list*)NULL) {
    
    // loop over all the child lex nodes
    //
    for (Train_Link_node* nd = child_d->get_head_cc(); nd != (Train_Link_node*)NULL;
	 nd = nd->get_next_cc()) {
      
      // get the lexical node in this node
      //
      lxn = (Train_Lex_node*)(nd->get_item_cc());

      // stop if the phone here matches the input phone
      //
      if (lxn->get_phone_cc() == phone_a) {
	node = lxn;
	break;
      }
    } // end for loop
  } // end if child_d is not NULL

  // return child node and exit gracefully
  //
  return node;
}
