class Crystallabs::Helpers::RunningAverage

Overview

An O(1) running average over the last capacity values pushed into it.

Wraps a deque rather than subclassing Deque(Int32): subclassing a stdlib generic is deprecated and promotes every Deque(Int32) in the program (including unrelated shards) to the virtual type Deque(Int32)+, causing confusing compile errors elsewhere.

Defined in:

crystallabs-helpers.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(capacity : Int32) #

[View source]

Instance Method Detail

def avg(value : Int32) : Int64 #

Pushes value and returns the average over the retained window.


[View source]