I am looking for a .Net (preferably C#) implementation of a priority queue or heap.
Unless I am looking in the wrong place, there isn't one in the framework. Is anyone aware of a good one, or should I roll my own?
I am looking for a .Net (preferably C#) implementation of a priority queue or heap.
Unless I am looking in the wrong place, there isn't one in the framework. Is anyone aware of a good one, or should I roll my own?
Pretty trivial to roll your own if the priorities are pre-defined.
I found one at CodeProject that looks like it fits well in the .NET framework. I didn't test it, though.
http://www.codeproject.com/KB/recipes/priorityqueue.aspx
You may want to write your own, though. It could be fun.
I like using the OrderedBag and OrderedSet classes in PowerCollections as priority queues.
Use a Java to C# translator on the Java implementation (java.util.PriorityQueue) in the Java Collections framework, or more intelligently use the algorithm and core code and plug it into a C# class of your own making that adheres to the C# Collections framework API for Queues, or at least Collections.
I found one by Julian Bucknall on his blog here - http://www.boyet.com/Articles/PriorityQueueCSharp3.html
We modified it slightly so that low-priority items on the queue would eventually 'bubble-up' to the top over time, so they wouldn't suffer starvation.
Check out the "C5 Generic Collection Library" http://www.itu.dk/research/c5/
there you can use the IntervalHeap