Skip to main content

StablePriorityQueue<T>

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

Fast fixed-size priority queue of StablePriorityQueueNode items with float priorities. Equal priorities come out in the order they went in. No safety checks: queuing past MaxSize, or passing a node that is not in this queue, breaks it.

Constructors​

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

Fields​

3 private and internal fields
MemberWhat it is
private T[] _nodesThe heap array; slot 0 is unused.
private int _numNodesNumber of queued nodes.
private long _numNodesEverEnqueuedCounter used to stamp each node's insertion order.

Properties​

MemberWhat it is
int Count { get; }Number of queued nodes.
T First { get; }The node Dequeue would return, or null if empty.
int MaxSize { get; }Capacity of the queue.

Methods​

MemberWhat it is
void Clear()Empties the queue.
bool Contains(T node)True if the node sits in this queue at its QueueIndex.
T Dequeue()Removes and returns the node with the lowest priority value. No empty check.
void Enqueue(T node, float priority)Adds a node with a priority and stamps its insertion order. No capacity check.
IEnumerator<T> GetEnumerator() (iterator)Goes through the queued nodes in heap order (not sorted).
bool IsValidQueue()Debug check that the heap order holds.
void Remove(T node)Removes a node from anywhere in the queue.
void Resize(int maxNodes)Changes the capacity, keeping the queued nodes.
void UpdatePriority(T node, float priority)Changes a queued node's priority and re-sorts it.
5 private and internal methods
MemberWhat it is
private void CascadeDown(T node)Moves a node down the heap until its children have lower priority.
private void CascadeUp(T node)Moves a node up the heap until its parent has higher priority.
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Goes through the queued nodes in heap order (not sorted).
private bool HasHigherPriority(T higher, T lower)True if the first node should come out before the second: lower priority, or equal and queued earlier.
private void OnNodeUpdated(T node)Moves a node up or down after its priority changed.