Namespace: Priority_Queue
An implementation of a min-Priority Queue using a heap. Has O(1) .Contains()! See https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp/wiki/Getting-Started for more information
public sealed class FastPriorityQueue<T> : IFixedSizePriorityQueue`2, IPriorityQueue`2, , System.Collections.IEnumerable
T
The values in the queue. Must extend the FastPriorityQueueNode class
Inheritance Object → FastPriorityQueue<T>
Implements IFixedSizePriorityQueue<T, Single>, IPriorityQueue<T, Single>, IEnumerable<T>, IEnumerable
Returns the number of nodes in the queue. O(1)
public int Count { get; }
Returns the maximum number of items that can be enqueued at once in this queue. Once you hit this number (ie. once Count == MaxSize), attempting to enqueue another item will cause undefined behavior. O(1)
public int MaxSize { get; }
Returns the head of the queue, without removing it (use Dequeue() for that). If the queue is empty, behavior is undefined. O(1)
public T First { get; }
T
Instantiate a new Priority Queue
public FastPriorityQueue(int maxNodes)
maxNodes
Int32
The max nodes ever allowed to be enqueued (going over this will cause undefined behavior)
Removes every node from the queue. O(n) (So, don't do this often!)
public void Clear()
Returns (in O(1)!) whether the given node is in the queue. If node is or has been previously added to another queue, the result is undefined unless oldQueue.ResetNode(node) has been called O(1)
public bool Contains(T node)
node
T
Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken arbitrarily. If the queue is full, the result is undefined. If the node is already enqueued, the result is undefined. If node is or has been previously added to another queue, the result is undefined unless oldQueue.ResetNode(node) has been called O(log n)
public void Enqueue(T node, float priority)
node
T
priority
Single
Removes the head of the queue and returns it. If queue is empty, result is undefined O(log n)
public T Dequeue()
T
Resize the queue so it can accept more nodes. All currently enqueued nodes are remain. Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior O(n)
public void Resize(int maxNodes)
maxNodes
Int32
This method must be called on a node every time its priority changes while it is in the queue. Forgetting to call this method will result in a corrupted queue! Calling this method on a node not in the queue results in undefined behavior O(log n)
public void UpdatePriority(T node, float priority)
node
T
priority
Single
Removes a node from the queue. The node does not need to be the head of the queue. If the node is not in the queue, the result is undefined. If unsure, check Contains() first O(log n)
public void Remove(T node)
node
T
By default, nodes that have been previously added to one queue cannot be added to another queue. If you need to do this, please call originalQueue.ResetNode(node) before attempting to add it in the new queue If the node is currently in the queue or belongs to another queue, the result is undefined
public void ResetNode(T node)
node
T
public IEnumerator<T> GetEnumerator()
IEnumerator<T>
Should not be called in production code. Checks to make sure the queue is still in a valid state. Used for testing/debugging the queue.
public bool IsValidQueue()