Module: Semian::SlidingWindowBehavior
- Extended by:
- Forwardable
- Included in:
- Semian::Simple::SlidingWindow, ThreadSafe::SlidingWindow
- Defined in:
- lib/semian/simple_sliding_window.rb
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Instance Method Summary collapse
- #clear ⇒ Object (also: #destroy)
- #push(value) ⇒ Object (also: #<<)
-
#reject!(&block) ⇒ Object
A sliding window is a structure that stores the most @max_size recent timestamps like this: if @max_size = 4, current time is 10, @window =[5,7,9,10].
Instance Attribute Details
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size.
11 12 13 |
# File 'lib/semian/simple_sliding_window.rb', line 11 def max_size @max_size end |
Instance Method Details
#clear ⇒ Object Also known as: destroy
29 30 31 32 |
# File 'lib/semian/simple_sliding_window.rb', line 29 def clear @window.clear self end |
#push(value) ⇒ Object Also known as: <<
22 23 24 25 26 |
# File 'lib/semian/simple_sliding_window.rb', line 22 def push(value) resize_to(@max_size - 1) # make room @window << value self end |
#reject!(&block) ⇒ Object
A sliding window is a structure that stores the most @max_size recent timestamps like this: if @max_size = 4, current time is 10, @window =[5,7,9,10]. Another push of (11) at 11 sec would make @window [7,9,10,11], shifting off 5.
17 18 19 20 |
# File 'lib/semian/simple_sliding_window.rb', line 17 def reject!(&block) @window.reject!(&block) self end |