Skip to main content

MaxPriorityQueue

In a max priority queue, elements are inserted in the order in which they arrive the queue and the maximum value is always removed first from the queue.

Types

HeapEntry

interface HeapEntry {
Priority: number--

The priority of the entry.

Value: T--

The value of the entry.

}

This is the interface for the entries in the MaxPriorityQueue.

Properties

Length

MaxPriorityQueue.Length: int

The length of the MaxPriorityQueue.

Heap

MaxPriorityQueue.Heap: Array<HeapEntry<T>>

The heap data of the MaxPriorityQueue.

Functions

new

MaxPriorityQueue.new() → MaxPriorityQueue<T>

Creates a new MaxPriorityQueue.

Is

MaxPriorityQueue.Is(
Value: any--

The value to check.

) → boolean--

Whether or not the passed value is a MaxPriorityQueue.

Determines whether the passed value is a MaxPriorityQueue.

IsEmpty

MaxPriorityQueue:IsEmpty() → boolean--

This will be true iff the queue is empty.

Check whether the MaxPriorityQueue has no elements.

InsertWithPriority

MaxPriorityQueue:InsertWithPriority(
Value: T,--

The value of the element.

Priority: number--

The priority of the element.

) → int--

The inserted position.

Add an element to the MaxPriorityQueue with an associated priority.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.

ChangePriority

MaxPriorityQueue:ChangePriority(
Value: T,--

The value you are updating the priority of.

NewPriority: number--

The new priority of the value.

) → int?--

The new position of the HeapEntry if it was found. This function will error if it couldn't find the value.

Changes the priority of the given value in the MaxPriorityQueue.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.
"CouldNotFind"Thrown when the value couldn't be found.

GetFirstPriority

MaxPriorityQueue:GetFirstPriority() → number?--

The priority of the first value.

Gets the priority of the first value in the MaxPriorityQueue. This is the value that will be removed last.

GetLastPriority

MaxPriorityQueue:GetLastPriority() → number?--

The priority of the last value.

Gets the priority of the last value in the MaxPriorityQueue. This is the value that will be removed first.

Peek

MaxPriorityQueue:Peek(
Index: number--

The index of the value.

) → HeapEntry<T>?--

The value located at the given index.

Gets the value at the index.

Performance

If you want the maximum performance, ignore this function and index the Heap property directly.

PopElement

MaxPriorityQueue:PopElement(
OnlyValue: boolean?--

Whether or not to return only the value or the entire entry.

) → T | HeapEntry<T>?--

The removed element.

Remove the element from the MaxPriorityQueue that has the highest priority, and return it.

ToArray

MaxPriorityQueue:ToArray(
OnlyValues: boolean?--

Whether or not the array is just the values or the priorities as well.

) → Array<T> | Array<HeapEntry<T>>--

The MaxPriorityQueue's array.

Converts the entire MaxPriorityQueue to an array.

Iterator

MaxPriorityQueue:Iterator(
OnlyValues: boolean?--

Whether or not the iterator returns just the values or the priorities as well.

) → IteratorFunction--

The iterator function. Usage is for Index, Value in MaxPriorityQueue:Iterator(OnlyValues) do.

Returns an iterator function for iterating over the MaxPriorityQueue.

Performance

If you care about performance, do not use this function. Just do for Index, Value in ipairs(MaxPriorityQueue.Heap) do directly.

ReverseIterator

MaxPriorityQueue:ReverseIterator(
OnlyValues: boolean?--

Whether or not the iterator returns just the values or the priorities as well.

) → IteratorFunction--

The iterator function. Usage is for Index, Value in MaxPriorityQueue:ReverseIterator(OnlyValues) do.

Returns an iterator function for iterating over the MaxPriorityQueue in reverse.

Clear

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

The same MaxPriorityQueue.

Clears the entire MaxPriorityQueue.

Contains

MaxPriorityQueue:Contains(
Value: T--

The value you are searching for.

) → boolean--

Whether or not the value was found.

Determines if the MaxPriorityQueue contains the given value.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.

RemovePriority

MaxPriorityQueue:RemovePriority(
Priority: number--

The priority you are removing from the MaxPriorityQueue.

) → ()

Removes the HeapEntry with the given priority, if it exists.

RemoveValue

MaxPriorityQueue:RemoveValue(
Value: T--

The value you are removing from the MaxPriorityQueue.

) → ()

Removes the HeapEntry with the given value, if it exists.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new `MaxPriorityQueue`.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MaxPriorityQueue<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 45,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Is",
            "desc": "Determines whether the passed value is a MaxPriorityQueue.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value to check.",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the passed value is a MaxPriorityQueue.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 57,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "IsEmpty",
            "desc": "Check whether the `MaxPriorityQueue` has no elements.",
            "params": [],
            "returns": [
                {
                    "desc": "This will be true iff the queue is empty.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 65,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "InsertWithPriority",
            "desc": "Add an element to the `MaxPriorityQueue` with an associated priority.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value of the element.",
                    "lua_type": "T"
                },
                {
                    "name": "Priority",
                    "desc": "The priority of the element.",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "The inserted position.",
                    "lua_type": "int"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidValue\"",
                    "desc": "Thrown when the value is nil."
                }
            ],
            "source": {
                "line": 112,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "ChangePriority",
            "desc": "Changes the priority of the given value in the `MaxPriorityQueue`.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value you are updating the priority of.",
                    "lua_type": "T"
                },
                {
                    "name": "NewPriority",
                    "desc": "The new priority of the value.",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "The new position of the HeapEntry if it was found. This function will error if it couldn't find the value.",
                    "lua_type": "int?"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidValue\"",
                    "desc": "Thrown when the value is nil."
                },
                {
                    "lua_type": "\"CouldNotFind\"",
                    "desc": "Thrown when the value couldn't be found."
                }
            ],
            "source": {
                "line": 144,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "GetFirstPriority",
            "desc": "Gets the priority of the first value in the `MaxPriorityQueue`. This is the value that will be removed last.",
            "params": [],
            "returns": [
                {
                    "desc": "The priority of the first value.",
                    "lua_type": "number?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 165,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "GetLastPriority",
            "desc": "Gets the priority of the last value in the `MaxPriorityQueue`. This is the value that will be removed first.",
            "params": [],
            "returns": [
                {
                    "desc": "The priority of the last value.",
                    "lua_type": "number?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 177,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Peek",
            "desc": "Gets the value at the index.\n\n:::warning Performance\nIf you want the maximum performance, ignore this function and index the `Heap` property directly.\n:::",
            "params": [
                {
                    "name": "Index",
                    "desc": "The index of the value.",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "The value located at the given index.",
                    "lua_type": "HeapEntry<T>?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 196,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "PopElement",
            "desc": "Remove the element from the `MaxPriorityQueue` that has the highest priority, and return it.",
            "params": [
                {
                    "name": "OnlyValue",
                    "desc": "Whether or not to return only the value or the entire entry.",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "The removed element.",
                    "lua_type": "T | HeapEntry<T>?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 207,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "ToArray",
            "desc": "Converts the entire `MaxPriorityQueue` to an array.",
            "params": [
                {
                    "name": "OnlyValues",
                    "desc": "Whether or not the array is just the values or the priorities as well.",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "The `MaxPriorityQueue`'s array.",
                    "lua_type": "Array<T> | Array<HeapEntry<T>>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 225,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Iterator",
            "desc": "Returns an iterator function for iterating over the `MaxPriorityQueue`.\n\n:::warning Performance\nIf you care about performance, do not use this function. Just do `for Index, Value in ipairs(MaxPriorityQueue.Heap) do` directly.\n:::",
            "params": [
                {
                    "name": "OnlyValues",
                    "desc": "Whether or not the iterator returns just the values or the priorities as well.",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "The iterator function. Usage is `for Index, Value in MaxPriorityQueue:Iterator(OnlyValues) do`.",
                    "lua_type": "IteratorFunction"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 254,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "ReverseIterator",
            "desc": "Returns an iterator function for iterating over the `MaxPriorityQueue` in reverse.",
            "params": [
                {
                    "name": "OnlyValues",
                    "desc": "Whether or not the iterator returns just the values or the priorities as well.",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "The iterator function. Usage is `for Index, Value in MaxPriorityQueue:ReverseIterator(OnlyValues) do`.",
                    "lua_type": "IteratorFunction"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 272,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Clear",
            "desc": "Clears the entire `MaxPriorityQueue`.",
            "params": [],
            "returns": [
                {
                    "desc": "The same `MaxPriorityQueue`.",
                    "lua_type": "MaxPriorityQueue<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 300,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Contains",
            "desc": "Determines if the `MaxPriorityQueue` contains the given value.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value you are searching for.",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the value was found.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidValue\"",
                    "desc": "Thrown when the value is nil."
                }
            ],
            "source": {
                "line": 313,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "RemovePriority",
            "desc": "Removes the `HeapEntry` with the given priority, if it exists.",
            "params": [
                {
                    "name": "Priority",
                    "desc": "The priority you are removing from the `MaxPriorityQueue`.",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 331,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "RemoveValue",
            "desc": "Removes the `HeapEntry` with the given value, if it exists.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value you are removing from the `MaxPriorityQueue`.",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidValue\"",
                    "desc": "Thrown when the value is nil."
                }
            ],
            "source": {
                "line": 347,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Length",
            "desc": "The length of the MaxPriorityQueue.",
            "lua_type": "int",
            "source": {
                "line": 26,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        },
        {
            "name": "Heap",
            "desc": "The heap data of the MaxPriorityQueue.",
            "lua_type": "Array<HeapEntry<T>>",
            "source": {
                "line": 32,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        }
    ],
    "types": [
        {
            "name": "HeapEntry",
            "desc": "This is the interface for the entries in the MaxPriorityQueue.",
            "fields": [
                {
                    "name": "Priority",
                    "lua_type": "number",
                    "desc": "The priority of the entry."
                },
                {
                    "name": "Value",
                    "lua_type": "T",
                    "desc": "The value of the entry."
                }
            ],
            "source": {
                "line": 40,
                "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
            }
        }
    ],
    "name": "MaxPriorityQueue",
    "desc": "In a max priority queue, elements are inserted in the order in which they arrive the queue and the maximum value is always removed first from the queue.",
    "source": {
        "line": 8,
        "path": "src/DataStructures/PriorityQueues/MaxPriorityQueue/init.lua"
    }
}