class Concurrent::RingBuffer
non-thread safe buffer
def capacity
-
(Integer)- the capacity of the buffer
def capacity @buffer.size end
def count
-
(Integer)- the number of elements currently in the buffer
def count @count end
def empty?
-
(Boolean)- true if buffer is empty, false otherwise
def empty? @count == 0 end
def full?
-
(Boolean)- true if buffer is full, false otherwise
def full? @count == capacity end
def initialize(capacity)
def initialize(capacity) @buffer = Array.new(capacity) @first = @last = 0 @count = 0 end
def offer(value)
-
(Boolean)- true if value has been inserted, false otherwise
Parameters:
-
value(Object) --
def offer(value) return false if full? @buffer[@last] = value @last = (@last + 1) % @buffer.size @count += 1 true end
def peek
-
(Object)- the first available value and without removing it from the buffer. If buffer is empty returns nil
def peek @buffer[@first] end
def poll
-
(Object)- the first available value and removes it from the buffer. If buffer is empty returns nil
def poll result = @buffer[@first] @buffer[@first] = nil @first = (@first + 1) % @buffer.size @count -= 1 result end