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

#include <lattice_path.h>

// method: new_lpath_cc
//
// arguments: none
//
// return: a Lat* pointer to a new lattice path
//
// this method outputs a new empty lattice path, and creates them whenever
// necessary
//
Lattice_path* Memory_manager::new_lpath_cc() {

  // if there are no free lattice paths available, create a few
  //
  if (lpath_count_d == (int_4)0) {
    grow_lpath_cc();
  }

  // get a lattice path off the list
  //
  Link_node* lnd = lpath_list_d;
  lpath_list_d = lpath_list_d->get_next_cc();

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

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

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

  // decrement free lattice path count
  //
  lpath_count_d--;
  
  // return the lattice path and exit gracefully
  //
  return lpth;
}
