#ifndef SampleDifference_h
#define SampleDifference_h

#include <vector>

class OneSample;

// OneDifference represents a period of time (length long) and a count of
// how many of the other samples are different in that time period.
//
struct OneDifference {
   unsigned int         count;
   unsigned short      length;
};

// SampleDifference represents the differences between one sample and
// several others. Note that being shorter doesn't count as a difference,
// differences are only accumulated during a comparson for the time span of
// the shorter of the sequences being compared.
//
class SampleDifference {
public:

   SampleDifference(OneSample * init_this_sample);

   ~SampleDifference();

   unsigned int
   Length() const {
         return diffs.size();
      }

   OneDifference
   operator[](unsigned int ndx) const {
         return diffs[ndx];
      }

      // Compare other sample to this samplem, accumulating differeces,
      // splitting the array of diffs where required, etc.
      //
   void
   CompareSample(OneSample * other_sample);

      // Call this after doing all the individual comparisons to
      // finish up all the diffs computations.
      //
   void
   FinishDiffs();

   unsigned long
   TotalTime() {
         return total_time;
      }

   double
   LogTotalTime() {
         return log_total_time;
      }

private:

      // Internal routine that is used to record the fact that the
      // comparison has determined the samples differ at time clock for
      // ticks additional clock ticks. That range of time gets its count
      // incremented by 1 in the differences array.
      //
   void
   IncrementRange(unsigned short clock, unsigned short ticks);

      // Split the diffs array entry at diffs_ndx, leaving it with length
      // tick_off and putting remainder of time in new entry following it.
      //
   void
   SplitDiffsAt(unsigned int diffs_ndx, unsigned short tick_off);

   std::vector<OneDifference>   diffs;

   OneSample * this_sample;

   unsigned long total_time;
   double        log_total_time;
};

#endif // SampleDifference_h
