// file: tr_lat_cstr_0.cc
//

// isip include files
//
#include "train_lattice.h"
#include "train_lattice_constants.h"

// method: destructor
//
// arguments: none
//
// return: none
//
// this is the default destructor
//
Train_Lattice::~Train_Lattice() {

  // dummy variables
  //
  Train_Lattice_node* ltn = (Train_Lattice_node*)NULL;
  Train_Hash_cell* next = (Train_Hash_cell*)NULL;

  // memory manager
  //
  Train_Memory_manager* manager = Train_Link_list::get_manager_cc();

  // delete Train_Lattice node pointers
  //
  Train_Hash_cell** hcells = lnode_d->get_cells_cc();
  int_4 hash_size = lnode_d->get_size_cc();
  for (int_4 k = 0; k < hash_size; k++) {
    for (Train_Hash_cell* lcell = hcells[k]; lcell != (Train_Hash_cell*)NULL;
         lcell = next) {
      next = lcell->get_next_cc();
      ltn = (Train_Lattice_node*)(lcell->get_item_cc());
      ltn->clear_cc();
      manager->delete_cc(ltn);
      manager->delete_cc(lcell);
    }
    hcells[k] = (Train_Hash_cell*)NULL;
  }
  delete lnode_d;
  
  // delete start node of the Train_Lattice
  //
  if (start_node_d != (Train_Lattice_node*)NULL) {
    start_node_d = (Train_Lattice_node*)NULL;
  }
  
  // delete Train_Lattice generation information
  //
  if (lang_model_d != (char_1*)NULL) {
    delete [] lang_model_d;
    lang_model_d = (char_1*)NULL;
  }
  if (utterance_d != (char_1*)NULL) {
    delete [] utterance_d;
    utterance_d = (char_1*)NULL;
  }
  if (model_set_d != (char_1*)NULL) {
    delete [] model_set_d;
    model_set_d = (char_1*)NULL;
  }
  
  // reset likelihood scale factors
  //
  lm_scale_d = TRAIN_LATTICE_DEFAULT_SCALE;
  word_penalty_d = TRAIN_LATTICE_DEFAULT_PENALTY;
  
  // reset node statistics
  //
  num_arcs_d = TRAIN_LATTICE_DEFAULT_NUM_ARCS;
  num_nodes_d = TRAIN_LATTICE_DEFAULT_NUM_NODES;

  // exit gracefully
  //
}
