CircularBuffer
A circular buffer is a data structure that stores a fixed number of elements, removing ones when you reach the maximum capacity.
Properties
Capacity
CircularBuffer.Capacity: intThe capacity of the CircularBuffer.
Data
CircularBuffer.Data: Array<T>The data of the CircularBuffer.
Functions
new
CircularBuffer.new(MaxCapacity:Â int--
The maximum size of the CircularBuffer before it starts removing values.
) → CircularBuffer<T>--
Returns a new CircularBuffer.
Creates a new CircularBuffer.
Clear
Clears the CircularBuffer.
GetCapacity
CircularBuffer:GetCapacity() → int--
The maximum capacity of the CircularBuffer.
Gets the capacity of the CircularBuffer.
GetMaxCapacity
CircularBuffer:GetMaxCapacity() → int--
The maximum capacity of the CircularBuffer.
Gets the capacity of the CircularBuffer.
IsEmpty
CircularBuffer:IsEmpty() → boolean--
Whether or not the CircularBuffer is empty.
Returns whether or not the CircularBuffer is empty.
IsFull
CircularBuffer:IsFull() → boolean--
Whether or not the CircularBuffer is full.
Returns whether or not the CircularBuffer is full.
Push
CircularBuffer:Push(NewData:Â T--
The data you are pushing.
) → T?--
Returns the removed data, if there was any.
Pushes the passed data to the front of the CircularBuffer.
Errors
| Type | Description |
|---|---|
| "InvalidData" | Thrown when NewData is null. |
Replace
CircularBuffer:Replace(Index:Â int,--
The index you are replacing.
NewData:Â T--
The data you are replacing with.
) → T--
The replaced data.
Replaces the index in the CircularBuffer with the passed data. This function errors if there is no index to replace.
Errors
| Type | Description |
|---|---|
| "InvalidData" | Thrown when NewData is null. |
| "InvalidIndex" | Thrown when Index is not a number. |
| "IndexTooLarge" | Thrown when Index is greater than the CircularBuffer's capacity. |
Insert
CircularBuffer:Insert(Index:Â int,--
The index you are replacing.
NewData:Â T--
The data you are replacing with.
) → T?--
The replaced data.
Inserts the data at the index in the CircularBuffer.
Errors
| Type | Description |
|---|---|
| "InvalidData" | Thrown when NewData is null. |
| "InvalidIndex" | Thrown when Index is not a number. |
| "IndexTooLarge" | Thrown when Index is greater than the CircularBuffer's capacity. |
PeekAt
CircularBuffer:PeekAt(Index:Â int?--
The index you are getting. Defaults to 1.
) → T?--
The value at the given index.
Returns the value at the given index.
Errors
| Type | Description |
|---|---|
| "InvalidIndex" | Thrown when Index is not a number or nil. |
Iterator
CircularBuffer:Iterator() → Iterator--
The ipairs iterator.
Returns an iterator for iterating over the CircularBuffer. Just a wrapper for ipairs(self.Data).
Performance
If you care about performance, do not use this function. Just do for Index, Value in ipairs(CircularBuffer.Data) do directly.