BlueRaja / High-Speed-Priority-Queue-for-C-Sharp

A C# priority queue optimized for pathfinding applications
MIT License
1.15k stars 169 forks source link

Please add support for BlockingCollection #39

Closed tesfabpel closed 5 years ago

tesfabpel commented 6 years ago

Please add support for BlockingCollection.
BlockingCollection is very useful in multi-threaded code since it allows you to do something like this:

while(running) { 
    var next = queue.Take();
 }

Thanks.

BlueRaja commented 6 years ago

I have no experience with this. It looks like to "support it", we just need to implement IProducerConsumerCollection<T>. Is that correct?

tesfabpel commented 6 years ago

It seems so since the constructor of Blocking Collection takes an instance of an object implementing that interface. Sadly, I don't know how to implement it myself.

BlueRaja commented 5 years ago

I attempted to implement this tonight. Unfortunately, it would require upgrading from .Net Standard 1.0 to 1.1, which would alienate some users.

Additionally, the TryAdd() method causes problems - it only supports adding a single value, without a priority, which doesn't work for a priority queue. I tried using KeyValuePair or Tuple instead, but the former isn't available in UWP, and the latter isn't available prior to .Net 4.0. I also considered simply marking TryAdd() as not implemented, but that means items can no longer be added through the BlockingCollection, which defeats the use-case for this suggestion.

So unfortunately, I'm going to have to close this as "will not implement" :(