RingBuffer:
Filter:
Classes | Collections > Ordered

RingBuffer : SequenceableCollection : Collection : Object

Fixed size ringbuffer

Description

A circular buffer that holds a fixed-size collection. Can be used as a queue.

Class Methods

RingBuffer.new(size, collectionClass)

Create a new buffer.

Arguments:

size

Initial size. The collection will be able to hold one minus this number of values.

collectionClass

Defaults to the Array class.

Inherited class methods

Instance Methods

.array

The collection.

.readPos

Current read position.

.writePos

Current write position.

.maxSize

Maximum capacity.

.size

Alias of -readable.

.readable

Number of readble items.

.writable

Number of writable items.

.add(value)

Add value and increase -writePos. Do nothing if no items can be written.

.pop

Return next readable item and increase -readPos. Return nil if no items can be read.

.overwrite(value)

Add value and increase -writePos by overwriting oldest readable item.

.do(function)

Iterate over the currently readable items.

Inherited instance methods

Examples