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
The heap data of the MinPriorityQueue.
Functions
new
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
Type | Description |
---|---|
"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
Type | Description |
---|---|
"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
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
Type | Description |
---|---|
"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
Type | Description |
---|---|
"InvalidValue" | Thrown when the value is nil. |