Documentation
¶
Overview ¶
Package avg provides a thread-safe moving average calculator for time.Duration values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MovingAverage ¶
type MovingAverage struct {
// contains filtered or unexported fields
}
MovingAverage computes a moving average over a fixed-size sliding window of time.Duration values. It is safe for concurrent use.
func Moving ¶
func Moving(window int) *MovingAverage
Moving creates and returns a new MovingAverage with the specified window size.
The window determines how many recent duration values will be considered when calculating the moving average.
func (*MovingAverage) Last ¶
func (m *MovingAverage) Last() time.Duration
Last returns the most recently computed moving average without updating it.
This method is safe to call concurrently.
func (*MovingAverage) Next ¶
func (m *MovingAverage) Next(d time.Duration) time.Duration
Next adds a new duration value and updates the moving average.
If the window is already full, the oldest duration is removed before the new value is added. The method returns the updated moving average.
This method is safe to call concurrently.
func (*MovingAverage) Reset ¶
func (m *MovingAverage) Reset()
Reset clears all recorded durations and resets the moving average to zero.