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