// file: dec_prune_1.cc
//

// isip include files
//
#include "decoder.h"
#include "decoder_constants.h"

// method: beam_prune_cc
//
// arguments: none
//
// return: a logical_1 to indicate status
//
// this method loops over all state level traces and prunes them based
// on the state level beam
//
logical_1 Decoder::beam_prune_cc() {
  
  // dummy variables
  //
  Instance* inst = (Instance*)NULL;
  float_4 score = (float_4)0;
  Link_node* nd = (Link_node*)NULL;
  Link_node* pd = (Link_node*)NULL;
  
  // set up flag for align mode
  //
  logical_1 flag = ISIP_FALSE;
  if (align_mode_d == DEC_STATE_ALIGN_MODE) {
    flag = ISIP_TRUE;
  }
  
  // loop over all instances in the active instance list
  //
  for (nd = inst_list_d->get_head_cc(); nd != (Link_node*)NULL; nd = pd) {
    
    // get the instance here
    //
    pd = nd->get_next_cc();
    inst = (Instance*)(nd->get_item_cc());
      
    // check if this instance is active
    //
    score = inst->get_score_cc();
    if (score >= INSTANCE_DEFAULT_SCORE) {
      
      // check if this instance can be pruned completely
      //
      if (beam_thresh_d[DEC_STATE_LEVEL] > score) {
	
	// remove all traces here and remove this instance from the active
	// instance list
	//
	inst->prune_cc(flag, num_traces_del_d[DEC_STATE_LEVEL]);
	inst_list_d->remove_cc(nd);
	inst_count_d--;
      }
      
      // otherwise prune individual traces
      //
      else {
	inst->prune_cc(beam_thresh_d[DEC_STATE_LEVEL], flag,
		       num_traces_del_d[DEC_STATE_LEVEL]);
      }
    } // end if this is a valid instance
  } // end loop over all active instances
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
