// file: tok_trace_0.cc
//

// isip include files
//
#include "token.h"
#include "token_constants.h"
 
// method: insert_trace_cc
//
// arguments:
//  Trace* trace : (input) the new trace to be added to list
//  logical_1 flag: (input) flag to indicate update of ref counts
//  float_4& score : (input) the max score so far
//
// return: a logical_1 indicating success
//
// this method adds the input trace to the list
//
logical_1 Token::insert_trace_cc(Trace* trace_a, logical_1 flag_a,
				 float_4& score_a) {

  // dummy variables
  //
  Trace* betr = (Trace*)NULL;

  // update score
  //
  float_4 score = trace_a->get_score_cc();
  if (score > score_a) {
    score_a = score;
  }

  // if no other trace is present, insert this and return
  //
  if (trace_d == (Trace*)NULL) {
    trace_d = trace_a;
    return ISIP_TRUE;
  }

  // compare the current trace with the input
  //
  betr = trace_d->compare_cc(trace_a);
  
  // if this was a valid comparison
  //
  if (betr != (Trace*)NULL) {
    
    // memory manager
    //
    Memory_manager* manager = Link_list::get_manager_cc();
    
    // if the input trace is the better path substitute traces
    //
    if (betr == trace_a) {

      // remove the original trace
      //
      if (flag_a == ISIP_TRUE) {
	trace_d->decr_ref_cc();
      }
      manager->delete_cc(trace_d);
      
      // substitute new trace
      //
      trace_d = trace_a;
    }
      
    // if the other trace is the better path
    //
    else {

      // remove the new trace
      //
      if (flag_a == ISIP_TRUE) {
	trace_a->decr_ref_cc();
      }
      manager->delete_cc(trace_a);
    }
  } // end if valid comparison

  // return with status to indicate no change in number of traces
  //
  return ISIP_FALSE;
}
