Namespace: Priority_Queue
A copy of StablePriorityQueue which also has generic priority-type
public sealed class GenericPriorityQueue<TItem, TPriority> : IFixedSizePriorityQueue`2, IPriorityQueue`2, , System.Collections.IEnumerable
TItem
The values in the queue. Must extend the GenericPriorityQueueNode class
TPriority
The priority-type. Must extend IComparable
Inheritance Object → GenericPriorityQueue<TItem, TPriority>
Implements IFixedSizePriorityQueue<TItem, TPriority>, IPriorityQueue<TItem, TPriority>, IEnumerable<TItem>, 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 TItem First { get; }
TItem
Instantiate a new Priority Queue
public GenericPriorityQueue(int maxNodes)
maxNodes
Int32
The max nodes ever allowed to be enqueued (going over this will cause undefined behavior)
Instantiate a new Priority Queue
public GenericPriorityQueue(int maxNodes, IComparer<TPriority> comparer)
maxNodes
Int32
The max nodes ever allowed to be enqueued (going over this will cause undefined behavior)
comparer
IComparer<TPriority>
The comparer used to compare TPriority values.
Instantiate a new Priority Queue
public GenericPriorityQueue(int maxNodes, Comparison<TPriority> comparer)
maxNodes
Int32
The max nodes ever allowed to be enqueued (going over this will cause undefined behavior)
comparer
Comparison<TPriority>
The comparison function to use to compare TPriority values
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(TItem node)
node
TItem
Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out. 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(TItem node, TPriority priority)
node
TItem
priority
TPriority
Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. If queue is empty, result is undefined O(log n)
public TItem Dequeue()
TItem
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(TItem node, TPriority priority)
node
TItem
priority
TPriority
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(TItem node)
node
TItem
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
public void ResetNode(TItem node)
node
TItem
public IEnumerator<TItem> GetEnumerator()
IEnumerator<TItem>
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()