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

#include <ngram_node.h>

// method: grow_ngram_cc
//
// arguments: none
//
// return: a logical_1 indicating success
//
// this method grows the number of empty ngram nodes by the ngram node
// grow size
//
logical_1 Memory_manager::grow_ngram_cc() {

  // create new empty ngram nodes
  //
  Ngram_node** ngn = new Ngram_node*[ngram_grow_size_d];
  Link_node* lnd = (Link_node*)NULL;
  
  // insert the ngram nodes in a list
  //
  for (int_4 i = 0; i < ngram_grow_size_d; i++) {
    lnd = new_node_cc();
    ngn[i] = new Ngram_node();
    lnd->set_item_cc((void_p)ngn[i]);
    if ((i == (int_4)0) && (ngram_count_d == (int_4)0)) {
      ngram_list_d = lnd;
    }
    else {
      ngram_list_d->insert_cc(lnd);
    }
  }
  
  // update the count of free ngrams
  //
  ngram_count_d += ngram_grow_size_d;
  num_ngram_d += ngram_grow_size_d;

  // free pointer memory since the objects will be deleted seperately
  //
  delete [] ngn;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
