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

#include <train_hash_cell.h>

// method: new_hash_cc
//
// arguments: none
//
// return: a Train_Hash_cell* pointer to a new hash table cell
//
// this method outputs a new empty hash table cell, and creates them
// whenever necessary
//
Train_Hash_cell* Train_Memory_manager::new_hash_cc() {

  // if there are no free hash table cells available, create a few
  //
  if (hash_count_d == (int_4)0) {
    grow_hash_cc();
  }
  
  // get a hash table cell off the list
  //
  Train_Link_node* lnd = hash_list_d;
  hash_list_d = hash_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 hash table cell here
  //
  Train_Hash_cell* hcell = (Train_Hash_cell*)(lnd->get_item_cc());
  
  // return the link node to the free node list
  //
  delete_cc(lnd);

  // decrement free hash table cell count
  //
  hash_count_d --;
  
  // return the hash table cell and exit gracefully
  //
  return hcell;
}
