Skip to main content

MinPriorityQueue

In a min priority queue, elements are inserted in the order in which they arrive the queue and the smallest 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 MinPriorityQueue.

Properties

Length

MinPriorityQueue.Length: int

The length of the MinPriorityQueue.

Heap

MinPriorityQueue.Heap: Array<HeapEntry<T>>

The heap data of the MinPriorityQueue.

Functions

new

MinPriorityQueue.new() → MinPriorityQueue<T>

Creates a new MinPriorityQueue.

Is

MinPriorityQueue.Is(
Value: any--

The value to check.

) → boolean--

Whether or not the passed value is a MinPriorityQueue.

Determines whether the passed value is a MinPriorityQueue.

IsEmpty

MinPriorityQueue:IsEmpty() → boolean--

This will be true iff the queue is empty.

Check whether the MinPriorityQueue has no elements.

InsertWithPriority

MinPriorityQueue:InsertWithPriority(
Value: T,--

The value of the element.

Priority: number--

The priority of the element.

) → int--

The inserted position.

Add an element to the MinPriorityQueue with an associated priority.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.

ChangePriority

MinPriorityQueue: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 MinPriorityQueue.

Errors

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

GetFirstPriority

MinPriorityQueue:GetFirstPriority() → number?--

The priority of the first value.

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

GetLastPriority

MinPriorityQueue:GetLastPriority() → number?--

The priority of the last value.

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

Peek

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

MinPriorityQueue: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 MinPriorityQueue that has the highest priority, and return it.

ToArray

MinPriorityQueue:ToArray(
OnlyValues: boolean?--

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

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

The MinPriorityQueue's array.

Converts the entire MinPriorityQueue to an array.

Iterator

MinPriorityQueue: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 MinPriorityQueue:Iterator(OnlyValues) do.

Returns an iterator function for iterating over the MinPriorityQueue.

Performance

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

ReverseIterator

MinPriorityQueue: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 MinPriorityQueue:ReverseIterator(OnlyValues) do.

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

Clear

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

The same MinPriorityQueue.

Clears the entire MinPriorityQueue.

Contains

MinPriorityQueue:Contains(
Value: T--

The value you are searching for.

) → boolean--

Whether or not the value was found.

Determines if the MinPriorityQueue contains the given value.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.

RemovePriority

MinPriorityQueue:RemovePriority(
Priority: number--

The priority you are removing from the MinPriorityQueue.

) → ()

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

RemoveValue

MinPriorityQueue:RemoveValue(
Value: T--

The value you are removing from the MinPriorityQueue.

) → ()

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 `MinPriorityQueue`.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MinPriorityQueue<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 45,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "Is",
            "desc": "Determines whether the passed value is a MinPriorityQueue.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value to check.",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the passed value is a MinPriorityQueue.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 57,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "IsEmpty",
            "desc": "Check whether the `MinPriorityQueue` 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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "InsertWithPriority",
            "desc": "Add an element to the `MinPriorityQueue` 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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "ChangePriority",
            "desc": "Changes the priority of the given value in the `MinPriorityQueue`.",
            "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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "GetFirstPriority",
            "desc": "Gets the priority of the first value in the `MinPriorityQueue`. 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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "GetLastPriority",
            "desc": "Gets the priority of the last value in the `MinPriorityQueue`. 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/MinPriorityQueue/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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "PopElement",
            "desc": "Remove the element from the `MinPriorityQueue` 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/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "ToArray",
            "desc": "Converts the entire `MinPriorityQueue` 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 `MinPriorityQueue`'s array.",
                    "lua_type": "Array<T> | Array<HeapEntry<T>>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 225,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "Iterator",
            "desc": "Returns an iterator function for iterating over the `MinPriorityQueue`.\n\n:::warning Performance\nIf you care about performance, do not use this function. Just do `for Index, Value in ipairs(MinPriorityQueue.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 MinPriorityQueue:Iterator(OnlyValues) do`.",
                    "lua_type": "IteratorFunction"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 254,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "ReverseIterator",
            "desc": "Returns an iterator function for iterating over the `MinPriorityQueue` 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 MinPriorityQueue:ReverseIterator(OnlyValues) do`.",
                    "lua_type": "IteratorFunction"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 272,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "Clear",
            "desc": "Clears the entire `MinPriorityQueue`.",
            "params": [],
            "returns": [
                {
                    "desc": "The same `MinPriorityQueue`.",
                    "lua_type": "MinPriorityQueue<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 300,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "Contains",
            "desc": "Determines if the `MinPriorityQueue` 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/MinPriorityQueue/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 `MinPriorityQueue`.",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 331,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/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 `MinPriorityQueue`.",
                    "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/MinPriorityQueue/init.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Length",
            "desc": "The length of the MinPriorityQueue.",
            "lua_type": "int",
            "source": {
                "line": 26,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        },
        {
            "name": "Heap",
            "desc": "The heap data of the MinPriorityQueue.",
            "lua_type": "Array<HeapEntry<T>>",
            "source": {
                "line": 32,
                "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
            }
        }
    ],
    "types": [
        {
            "name": "HeapEntry",
            "desc": "This is the interface for the entries in the MinPriorityQueue.",
            "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/MinPriorityQueue/init.lua"
            }
        }
    ],
    "name": "MinPriorityQueue",
    "desc": "In a min priority queue, elements are inserted in the order in which they arrive the queue and the smallest value is always removed first from the queue.",
    "source": {
        "line": 8,
        "path": "src/DataStructures/PriorityQueues/MinPriorityQueue/init.lua"
    }
}