The goog.structs.CircularBuffer Class

goog.structs.CircularBuffer(opt_maxSize)

Class for CircularBuffer.

opt_maxSize {number=}
The maximum size of the buffer.

.add(item)

Adds an item to the buffer. May remove the oldest item if the buffer is at max size.

item {*}
The item to add.

.clear()

Empties the current buffer.

.containsKey(key)

Whether the buffer contains the key/index.

key {number}
The key/index to check for.
returns {boolean}
Whether the buffer contains the key/index.

.containsValue(value)

Whether the buffer contains the given value.

value {*}
The value to check for.
returns {boolean}
Whether the buffer contains the given value.

.get(index)

Returns the item at the specified index.

index {number}
The index of the item. The index of an item can change after calls to {@code add()} if the buffer is at maximum size.
returns {*}
The item at the specified index.

.getCount()

Returns the current number of items in the buffer.

returns {number}
The current number of items in the buffer.

.getKeys()

returns {Array}
The indexes in the buffer.

.getLast()

Returns the last item inserted into the buffer.

returns {*}
The last item inserted into the buffer, or null if the buffer is empty.

.getNewestValues(maxCount)

Returns the newest values in the buffer up to {@code count}.

maxCount {number}
The maximum number of values to get. Should be a positive number.
returns {Array}
The newest values in the buffer up to {@code count}.

.getValues()

returns {Array}
The values in the buffer.

.isEmpty()

returns {boolean}
Whether the buffer is empty.

.set(index, item)

Sets the item at the specified index.

index {number}
The index of the item. The index of an item can change after calls to {@code add()} if the buffer is at maximum size.
item {*}
The item to add.