// file: inst_clear_1.cc
//

// isip include files
//
#include "instance.h"
#include "instance_constants.h"

// method: prune_cc
//
// arguments:
//  float_4 beam: (input) the beam threshold for pruning
//  logical_1 flag: (input) alignment mode flag
//  int_4& ndel: (output) number of deleted traces
//
// return: a logical_1 flag indicating status
//
// this method prunes away all the traces in this instance that fall
// below the beam
//
logical_1 Instance::prune_cc(float_4 beam_a, logical_1 flag_a,
			     int_4& ndel_a) {

  // make sure the token list exists
  //
  if (token_list_d == (Link_list*)NULL) {
    return ISIP_TRUE;
  }

  // dummy variables
  //
  Token* tok = (Token*)NULL;

  // loop over all active tokens --- each corresponds to an
  // active state for this phone
  //
  for (Link_node* tok_node = token_list_d->get_head_cc();
       tok_node != (Link_node*)NULL; tok_node = tok_node->get_next_cc()) {
    
    // get the corresponding token
    //
    tok = (Token*)(tok_node->get_item_cc());
    
    // prune the token only if needed
    //
    //
    if (beam_a > INSTANCE_DEFAULT_SCORE) {
      tok->prune_cc(beam_a, flag_a, ndel_a);
    }

    // otherwise only reset the marker
    //
    else {
      tok->reset_marker_cc();
    }
  } // end loop over all tokens
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
