// file: ngrl_node_0.cc
//

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

// method: get_node_cc
//
// arguments:
//  Word* word: (input) the word in the desired ngram node
//  Ngram_node**& node: (input/output) the ngram node from the previous
//                     level which is the parent for the desired node
//
// return: a logical_1 indicating success
//
// this method gets the node from the current list based on the word
// stored in it and its parent ngram node from the previous level
//
logical_1 Ngram_list::get_node_cc(Word* word_a, Ngram_node**& node_a) {

  // the end points of the search
  //
  Ngram_node** start = (Ngram_node**)NULL;
  Ngram_node** end = (Ngram_node**)NULL;

  // if the input node is null, or this is a unigram level then this
  // is a direct search
  //
  if (node_a == (Ngram_node**)NULL) {
    start = nodes_d;
    end = nodes_d + num_d - 1;
    while ((*end) == (Ngram_node*)NULL) {
      end--;
    }
  }

  // otherwise get the end points of the search
  //
  else {

    // start at the first child of the parent node
    //
    start = (*node_a)->get_next_node_cc();

    // stop at the first child of the next parent node
    //
    end = start + ((*node_a)->get_num_next_nodes_cc() - 1);

  } // end else

  // reset the output node
  //
  node_a = (Ngram_node**)NULL;

  // find the node in this range with the given word
  //
  node_a = search_node_cc(start, end, word_a);

  // exit gracefully
  //
  return ISIP_TRUE;
}
