Class: Redd::Utilities::Stream::RingBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/redd/utilities/stream.rb

Overview

A simple fixed-size ring buffer.

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ RingBuffer


9
10
11
12
13
# File 'lib/redd/utilities/stream.rb', line 9

def initialize(size)
  @size = size
  @backing_array = Array.new(size)
  @pointer = 0
end

Instance Method Details

#add(el) ⇒ Object


19
20
21
22
# File 'lib/redd/utilities/stream.rb', line 19

def add(el)
  @backing_array[@pointer] = el
  @pointer = (@pointer + 1) % @size
end

#include?(el) ⇒ Boolean


15
16
17
# File 'lib/redd/utilities/stream.rb', line 15

def include?(el)
  @backing_array.include?(el)
end