// file: $isip/class/search/HierarchicalSearch/hsrch_10.cc
// version: $Id: hsrch_10.cc 8145 2002-05-27 04:48:58Z alphonso $
//

// isip include files
//
#include "HierarchicalSearch.h"

// method: pathsRemainTrace
//
// arguments: none
//
// return: logical flag indicating whether or not there are any search paths
// which remain to be searched at any level
//
// check for remaining paths at all levels in the hiererchy
//
boolean HierarchicalSearch::pathsRemainTrace() {

  // sum up the lengths of all trace lists
  //
  long traces_left = 0;
  long levels = getNumLevels();
  for (long j = 0; j < levels; j++) {
    if ((traces_left += trace_lists_d(j).length()) > 0) {
      return true;
    }
  }
  
  // if we have reached thus far no traces remain in the hierarchy
  //
  return false;
}

// method: pathsRemainInstance
//
// arguments: none
//
// return: logical flag indicating whether or not there are any search paths
// which remain to be searched at any level
//
// check for remaining paths at all levels in the hiererchy
//
boolean HierarchicalSearch::pathsRemainInstance() {

  // sum up the lengths of all instance lists
  //
  long instances_left = 0;
  long levels = getNumLevels();
  for (long j = 0; j < levels; j++) {
    if ((instances_left += instance_lists_d(j).length()) > 0) {
      return true;
    }
  }

  // if we have reached thus far no instances remain in the hierarchy
  //
  return false;
}

// method: getActiveTraces
//
// arguments:
//  long level_num: (input) level whose number of active traces we need
//
// return: logical flag indicating status
//
// determines the number of active traces at a particular level or at all 
// levels
//
long HierarchicalSearch::getActiveTraces(long level_num_a) {

  // declare local variables
  //
  long traces_left = 0;

  // sum up the lengths of all trace lists
  //
  if (level_num_a == ALL_LEVELS) {
    long levels = getNumLevels();
    for (long j = 0; j < levels; j++) {
      traces_left += trace_lists_d(j).length();
    }
  }
  else {
    if ((level_num_a >= 0) && (level_num_a < getNumLevels())) {
      traces_left += trace_lists_d(level_num_a).length();
    }
  }

  // exit gracefully:
  //
  return traces_left;
}

// method: getActiveInstances
//
// arguments:
//  long level_num: (input) level whose number of active instances we need
//
// return: logical flag indicating status
//
// determines the number of active instances at a particular level or at all 
// levels
//
long HierarchicalSearch::getActiveInstances(long level_num_a) {

  // declare local variables
  //
  long instances_left = 0;

  // sum up the lengths of all instance lists
  //
  if (level_num_a == ALL_LEVELS) {
    long levels = getNumLevels();
    for (long j = 0; j < levels; j++) {
      instances_left += instance_lists_d(j).length();
    }
  }
  else {
    if ((level_num_a >= 0) && (level_num_a < getNumLevels())) {
      instances_left += instance_lists_d(level_num_a).length();
    }
  }

  // exit gracefully:
  //
  return instances_left;
}
