Skip to main content

FastPriorityQueue<T>

A class in Alta.Timing.Runtime, Alta.Timing.PriorityQueue.

Fixed size binary heap of nodes with a float priority, lowest value first. Nodes store their own index, and there are no safety checks.

Constructors​

MemberWhat it is
FastPriorityQueue(int maxNodes)Creates a FastPriorityQueue from maxNodes.

Fields​

2 private and internal fields
MemberWhat it is
private T[] _nodesHeap array. Slot 0 is unused.
private int _numNodesBacking field for Count.

Properties​

MemberWhat it is
int Count { get; }Number of nodes in the queue.
T First { get; }The node with the lowest priority value, without removing it.
T Last { get; }Returns the node at array slot Count - 1, which is just a heap slot, not the lowest priority node.
int MaxSize { get; }How many nodes the queue can hold.

Methods​

MemberWhat it is
void Clear()Empties the queue without resizing it.
bool Contains(T node)True if the node is in this queue, checked through its stored index.
T Dequeue()Removes and returns the node with the lowest priority value. Does not check for an empty queue.
void Enqueue(T node, float priority)Adds a node with a priority. Does not check for a full queue or a node already queued.
IEnumerator<T> GetEnumerator() (iterator)Enumerates nodes in heap order, not priority order.
bool IsValidQueue()Debug check that every parent comes before its children.
void Remove(T node)Removes a node from anywhere in the queue.
void Resize(int maxNodes)Changes the capacity, dropping nodes beyond the new size.
void UpdatePriority(T node, float priority)Changes a queued node's priority and moves it to its new place.
6 private and internal methods
MemberWhat it is
private void CascadeDown(T node)Moves a node down the heap until both children have lower priority.
private void CascadeUp(T node)Moves a node up the heap past parents with lower priority.
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Enumerates nodes in heap order, not priority order.
private bool HasHigherOrEqualPriority(T higher, T lower)True if the first node's priority value is lower or equal.
private bool HasHigherPriority(T higher, T lower)True if the first node's priority value is strictly lower.
private void OnNodeUpdated(T node)Moves a node up or down after its priority changed.

Used in​

Members of other types that take, return or hold a FastPriorityQueue&lt;T>: