func (ts *timeseries) set(value int64) {
	ts.slots[ts.head] = value
}
set sets the current value of the timeseries.
package stats
import (
	"math"
	"time"
)
type timeseries struct {
	size       int            
	resolution time.Duration  
	stepCount  int64          
	head       int            
	time       time.Time      
	slots      []int64        
}
func newTimeSeries(initialTime time.Time, period, resolution time.Duration) *timeseries {
	size := int(period.Nanoseconds()/resolution.Nanoseconds()) + 1
	return &timeseries{
		size:       size,
		resolution: resolution,
		stepCount:  1,
		time:       initialTime,
		slots:      make([]int64, size),
	}
}
func (ts *timeseries) advanceTimeWithFill(t time.Time, value int64) {
	advanceTo := t.Truncate(ts.resolution)
	if !advanceTo.After(ts.time) {
		ts.time = advanceTo
		return
	}
	steps := int(advanceTo.Sub(ts.time).Nanoseconds() / ts.resolution.Nanoseconds())
	ts.stepCount += int64(steps)
	if steps > ts.size {
		steps = ts.size
	}
	for steps > 0 {
		ts.head = (ts.head + 1) % ts.size
		ts.slots[ts.head] = value
		steps--
	}
	ts.time = advanceTo
}
func (ts *timeseries) advanceTime(t time.Time) {
	ts.advanceTimeWithFill(t, ts.slots[ts.head])
}