// file: tr_mm_new_3.cc
//
 
// isip include files
//
#include "train_memory_manager.h"
#include "train_memory_manager_constants.h"

#include <train_lattice_node.h>

// method: new_lat_cc
//
// arguments: none
//
// return: a Lat* pointer to a new lattice node
//
// this method outputs a new empty lattice node, and creates them whenever
// necessary
//
Train_Lattice_node* Train_Memory_manager::new_lat_cc() {

  // if there are no free lattice nodes available, create a few
  //
  if (lat_count_d == (int_4)0) {
    grow_lat_cc();
  }

  // get a lattice node off the list
  //
  Train_Link_node* lnd = lat_list_d;
  lat_list_d = lat_list_d->get_next_cc();

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

  // get the lattice node here
  //
  Train_Lattice_node* ltn = (Train_Lattice_node*)(lnd->get_item_cc());
  
  // return the link node to the free node list
  //
  delete_cc(lnd);

  // decrement free lattice node count
  //
  lat_count_d --;
  
  // return the lattice node and exit gracefully
  //
  return ltn;
}
