class Leafy::Core::SlidingWindowReservoir
Public Class Methods
new(size)
click to toggle source
Creates a new {@link SlidingWindowReservoir} which stores the last {@code size} measurements.
@param size the number of measurements to store
Calls superclass method
# File lib/leafy/core/sliding_window_reservoir.rb, line 14 def initialize(size) super() # for cheap_lockable @measurements = Array.new size @count = 0 end
Public Instance Methods
size()
click to toggle source
# File lib/leafy/core/sliding_window_reservoir.rb, line 20 def size cheap_synchronize do [@count, @measurements.size].min end end
snapshot()
click to toggle source
# File lib/leafy/core/sliding_window_reservoir.rb, line 33 def snapshot values = nil cheap_synchronize do values = @measurements.dup end UniformSnapshot.new(*values) end
update(value)
click to toggle source
# File lib/leafy/core/sliding_window_reservoir.rb, line 26 def update(value) cheap_synchronize do @measurements[(@count % @measurements.size)] = value; @count += 1 end end