The PriorityQueue is a collection similar to the
from the .NET Framework: You add items at the end and remove items from the top.
But the priority queue adds a twist to this scheme: the order in which items come out again is determined by their ''priority''. A priority can be anything you can implement an
for - the size of a number, the time-to-impact of incoming rockets, the time at which a task will be due and so on.
The Nuclex.Support library provides two versions of the PriorityQueue:
- One requires the items themselves to be comparable to each other through an IComparer - useful if the items themselves already provide the value you want to use as priority and you don't want to store it redundantly. Though you have to be careful not
to change an item's priority while it is contained in a PriorityQueue.
- The other one uses a helper structure, PriorityItemPair, similar to the
KeyValuePair, to store the priority external to the item - useful if you want to prioritize items based on some other criterion without breaking up the implementation of the item class.
Of course, both use the same code internally, since nobody is fond of code duplication :)