public void addSample(int weight,float value){
  ensureSortedByIndex();
  Sample newSample=recycledSampleCount > 0 ? recycledSamples[--recycledSampleCount] : new Sample();
  newSample.index=nextSampleIndex++;
  newSample.weight=weight;
  newSample.value=value;
  samples.add(newSample);
  totalWeight+=weight;
  while (totalWeight > maxWeight) {
    int excessWeight=totalWeight - maxWeight;
    Sample oldestSample=samples.get(0);
    if (oldestSample.weight <= excessWeight) {
      totalWeight-=oldestSample.weight;
      samples.remove(0);
      if (recycledSampleCount < MAX_RECYCLED_SAMPLES) {
        recycledSamples[recycledSampleCount++]=oldestSample;
      }
    }
 else {
      oldestSample.weight-=excessWeight;
      totalWeight-=excessWeight;
    }
  }
}

public void addSample ( int weight , float value ) { ensureSortedByIndex ( ) ; Sample newSample = recycledSampleCount > 0 ? recycledSamples [ -- recycledSampleCount ] : new Sample ( ) ; newSample . index = nextSampleIndex ++ ; newSample . weight = weight ; newSample . value = value ; samples . add ( newSample ) ; totalWeight += weight ; while ( totalWeight > maxWeight ) { int excessWeight = totalWeight - maxWeight ; Sample oldestSample = samples . get ( 0 ) ; if ( oldestSample . weight <= excessWeight ) { totalWeight -= oldestSample . weight ; samples . remove ( 0 ) ; if ( recycledSampleCount < MAX_RECYCLED_SAMPLES ) { recycledSamples [ recycledSampleCount ++ ] = oldestSample ; } } else { oldestSample . weight -= excessWeight ; totalWeight -= excessWeight ; } } }
record a new observation . respect the configured total weight by reducing in weight or removing the oldest observations as required .
