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

is it necessary to have restriction for IComparable? #52

Closed micampbell closed 3 years ago

micampbell commented 3 years ago

For using SimplePriorityQueue...As far as I can tell from the implemented constraint, where TPriority : IComparable<TPriority>, this is based on the fact that some constructors use Comparer<TPriority>.Default but what if I have only intend to use IComparer (instead of IComparable) and the TPriority object cannot inherit from IComparable<>? for example, I want to write something like: var priorityQueue = new SimplePriorityQueue<int, Vertex>(new VertexSorter()); where VertexSorter inherits from IComparer<Vertex>', and not change the classVertexto inherit fromIComparable`.

I'm not sure that the implementation can have it both ways, but I thought I'd pose the question to you. Otherwise, my options are to write a small wrapper class for Vertex or try to remove the restriction from a local version of your awesome library.

micampbell commented 3 years ago

Interestingly, I commented where TPriority : IComparable<TPriority> from SimplePriorityQueue (and related: Generic.., IPriorityQueue, and IFixedSize..) and it compiles and runs just fine with my code. However, I'm not going make a pull request because I'm not clear on the implications of this change.

BlueRaja commented 3 years ago

Good catch! I forgot to remove this restriction when I added the Comparer constructors. This is fixed in v5.1.0