Skip to main content

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: int

The 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

CircularBuffer:Clear() → CircularBuffer<T>--

Returns self.

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

TypeDescription
"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

TypeDescription
"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

TypeDescription
"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

TypeDescription
"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.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new CircularBuffer.",
            "params": [
                {
                    "name": "MaxCapacity",
                    "desc": "The maximum size of the CircularBuffer before it starts removing values.",
                    "lua_type": "int"
                }
            ],
            "returns": [
                {
                    "desc": "Returns a new CircularBuffer.",
                    "lua_type": "CircularBuffer<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 35,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Clear",
            "desc": "Clears the CircularBuffer.",
            "params": [],
            "returns": [
                {
                    "desc": "Returns self.",
                    "lua_type": "CircularBuffer<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 59,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "GetCapacity",
            "desc": "Gets the capacity of the CircularBuffer.",
            "params": [],
            "returns": [
                {
                    "desc": "The maximum capacity of the CircularBuffer.",
                    "lua_type": "int"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 68,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "GetMaxCapacity",
            "desc": "Gets the capacity of the CircularBuffer.",
            "params": [],
            "returns": [
                {
                    "desc": "The maximum capacity of the CircularBuffer.",
                    "lua_type": "int"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 76,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "IsEmpty",
            "desc": "Returns whether or not the CircularBuffer is empty.",
            "params": [],
            "returns": [
                {
                    "desc": "Whether or not the CircularBuffer is empty.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 84,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "IsFull",
            "desc": "Returns whether or not the CircularBuffer is full.",
            "params": [],
            "returns": [
                {
                    "desc": "Whether or not the CircularBuffer is full.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 92,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Push",
            "desc": "Pushes the passed data to the front of the CircularBuffer.",
            "params": [
                {
                    "name": "NewData",
                    "desc": "The data you are pushing.",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "Returns the removed data, if there was any.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidData\"",
                    "desc": "Thrown when NewData is null."
                }
            ],
            "source": {
                "line": 103,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Replace",
            "desc": "Replaces the index in the CircularBuffer with the passed data. This function errors if there is no index to replace.",
            "params": [
                {
                    "name": "Index",
                    "desc": "The index you are replacing.",
                    "lua_type": "int"
                },
                {
                    "name": "NewData",
                    "desc": "The data you are replacing with.",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "The replaced data.",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidData\"",
                    "desc": "Thrown when NewData is null."
                },
                {
                    "lua_type": "\"InvalidIndex\"",
                    "desc": "Thrown when Index is not a number."
                },
                {
                    "lua_type": "\"IndexTooLarge\"",
                    "desc": "Thrown when Index is greater than the CircularBuffer's capacity."
                }
            ],
            "source": {
                "line": 123,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Insert",
            "desc": "Inserts the data at the index in the CircularBuffer.",
            "params": [
                {
                    "name": "Index",
                    "desc": "The index you are replacing.",
                    "lua_type": "int"
                },
                {
                    "name": "NewData",
                    "desc": "The data you are replacing with.",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "The replaced data.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidData\"",
                    "desc": "Thrown when NewData is null."
                },
                {
                    "lua_type": "\"InvalidIndex\"",
                    "desc": "Thrown when Index is not a number."
                },
                {
                    "lua_type": "\"IndexTooLarge\"",
                    "desc": "Thrown when Index is greater than the CircularBuffer's capacity."
                }
            ],
            "source": {
                "line": 162,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "PeekAt",
            "desc": "Returns the value at the given index.",
            "params": [
                {
                    "name": "Index",
                    "desc": "The index you are getting. Defaults to `1`.",
                    "lua_type": "int?"
                }
            ],
            "returns": [
                {
                    "desc": "The value at the given index.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidIndex\"",
                    "desc": "Thrown when Index is not a number or nil."
                }
            ],
            "source": {
                "line": 187,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Iterator",
            "desc": "Returns an iterator for iterating over the CircularBuffer. Just a wrapper for `ipairs(self.Data)`.\n\n:::warning Performance\nIf you care about performance, do not use this function. Just do `for Index, Value in ipairs(CircularBuffer.Data) do` directly.\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "The ipairs iterator.",
                    "lua_type": "Iterator"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 204,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Capacity",
            "desc": "The capacity of the CircularBuffer.",
            "lua_type": "int",
            "source": {
                "line": 23,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        },
        {
            "name": "Data",
            "desc": "The data of the CircularBuffer.",
            "lua_type": "Array<T>",
            "source": {
                "line": 29,
                "path": "src/DataStructures/CircularBuffer/init.lua"
            }
        }
    ],
    "types": [],
    "name": "CircularBuffer",
    "desc": "A circular buffer is a data structure that stores a fixed number of elements, removing ones when you reach the maximum capacity.",
    "source": {
        "line": 9,
        "path": "src/DataStructures/CircularBuffer/init.lua"
    }
}