structs.CircularBuffer Extends
Class for CircularBuffer.

Inheritance

Constructor

goog.structs.CircularBuffer(opt_maxSize)

Parameters

opt_maxSize : number=
The maximum size of the buffer.

Instance Methods

Public Protected Private
add(item) T | undefined
Adds an item to the buffer. May remove the oldest item if the buffer is at max size.
Arguments:
item : T
The item to add.
Returns: T | undefined  The removed old item, if the buffer is at max size. Return undefined, otherwise.
code »
clear()
Empties the current buffer.
code »
containsKey(key) boolean
Whether the buffer contains the key/index.
Arguments:
key : number
The key/index to check for.
Returns: boolean  Whether the buffer contains the key/index.
code »
containsValue(value) boolean
Whether the buffer contains the given value.
Arguments:
value : T
The value to check for.
Returns: boolean  Whether the buffer contains the given value.
code »
get(index) T
Returns the item at the specified index.
Arguments:
index : number
The index of the item. The index of an item can change after calls to add() if the buffer is at maximum size.
Returns: T  The item at the specified index.
code »
getCount() number
Returns the current number of items in the buffer.
Returns: number  The current number of items in the buffer.
code »
getKeys() !Array.<number>
No description.
Returns: !Array.<number>  The indexes in the buffer.
code »
getLast() T | null
Returns the last item inserted into the buffer.
Returns: T | null  The last item inserted into the buffer, or null if the buffer is empty.
code »
getNewestValues(maxCount) !Array.<T>
Returns the newest values in the buffer up to count.
Arguments:
maxCount : number
The maximum number of values to get. Should be a positive number.
Returns: !Array.<T>  The newest values in the buffer up to count.
code »
getValues() !Array.<T>
No description.
Returns: !Array.<T>  The values in the buffer.
code »
isEmpty() boolean
No description.
Returns: boolean  Whether the buffer is empty.
code »
normalizeIndex_(index) number
Helper function to convert an index in the number space of oldest to newest items in the array to the position that the element will be at in the underlying array.
Arguments:
index : number
The index of the item in a list ordered from oldest to newest.
Returns: number  The index of the item in the CircularBuffer's underlying array.
code »
set(indexitem)
Sets the item at the specified index.
Arguments:
index : number
The index of the item. The index of an item can change after calls to add() if the buffer is at maximum size.
item : T
The item to add.
code »

Instance Properties

buff_ :
Underlying array for the CircularBuffer.
Code »
maxSize_ :
Maximum size of the the circular array structure.
Code »
nextPtr_ :
Index of the next element in the circular array structure.
Code »

Package structs

Package Reference