// file: mm_new_5.cc
//
 
// isip include files
//
#include "memory_manager.h"
#include "memory_manager_constants.h"

#include <ngram_node.h>

// method: new_ngram_cc
//
// arguments: none
//
// return: a Ngram* pointer to a new ngram node
//
// this method outputs a new empty ngram node, and creates them whenever
// necessary
//
Ngram_node* Memory_manager::new_ngram_cc() {

  // if there are no free ngram nodes available, create a few
  //
  if (ngram_count_d == (int_4)0) {
    grow_ngram_cc();
  }

  // get a ngram node off the list
  //
  Link_node* lnd = ngram_list_d;
  ngram_list_d = ngram_list_d->get_next_cc();

  // adjust params
  //
  lnd->set_next_cc((Link_node*)NULL);

  if (ngram_list_d != (Link_node*)NULL) {
    ngram_list_d->set_prev_cc((Link_node*)NULL);
  }

  // get the ngram node here
  //
  Ngram_node* ngn = (Ngram_node*)(lnd->get_item_cc());
  
  // return the link node to the free node list
  //
  delete_cc(lnd);

  // decrement free ngram node count
  //
  ngram_count_d--;
  
  // return the ngram node and exit gracefully
  //
  return ngn;
}
