in core/src/main/java/com/spotify/metrics/core/LockFreeExponentiallyDecayingReservoir.java [117:135]
State rescale(long newTick) {
long durationNanos = newTick - startTick;
double scalingFactor = Math.exp(-alphaNanos * durationNanos);
int newCount = 0;
ConcurrentSkipListMap<Double, WeightedSample> newValues = new ConcurrentSkipListMap<>();
if (Double.compare(scalingFactor, 0) != 0) {
RescalingConsumer consumer = new RescalingConsumer(scalingFactor, newValues);
values.forEach(consumer);
// make sure the counter is in sync with the number of stored samples.
newCount = consumer.count;
}
// It's possible that more values were added while the map was scanned, those with the
// minimum priorities are removed.
while (newCount > size) {
Objects.requireNonNull(newValues.pollFirstEntry(), "Expected an entry");
newCount--;
}
return new State(alphaNanos, size, newTick, newCount, newValues);
}