-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why doesn't PriorityQueue have the Remove(TElement element) method #65928
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsThe current PriorityQueue Implementation for .NET PriorityQueue Implementation for .NET does not have the Remove(TElement element) method as written on the original contract defined in this #14032 I perused the history of #14032 spanning half a decade+ worth of discussions (!) and unfortunately didn't find the post which proposed to remove the the Remove method from the final implementation. Can someone shed some light on this? I would have expected the .NET Priority Queue implementation to have a certain degree of parity to [Java's implementation] (https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html) Also, +💯 this #14032 (comment) - would be great if the history of this API was written up as a blog entry on DevDiv :)
|
The Priority Queue was implemented according to the API proposed at #43957, which states:
|
Thanks @Joe4evr - what was the design rationale for not allowing duplicates? PriorityQueues in Java allow duplicates.... |
var pq = new PriorityQueue<int, int>();
pq.Enqueue(1, 1);
pq.Enqueue(1, 2);
// pq.Remove(1); <-- which of the above should be removed? |
Presumably the one where the equality comparer determines equality. Sure, the default comparer for integer means that 1 equals 1, but in collections, 1 is not an integer - it is a key - and keys do not necessarily have value equality. Since .NET has a very simplistic equality comparer interface where it is only possible to compare keys and not position/key hash/priority/value, it gives the developer some difficult decisions with potential side effects when it comes to duplicates. Therefore I agree that it is not exactly straightforward, but also not an issue that the data structure necessarily should concern itself with. However, it makes me think that a RemoveAt() method would be suitable and is a paradigm in .NET collections already. Was RemoveAt() discussed before? |
This issue might be a duplicate of this: Add a priority queue that supports priority updates |
It might be worth pointing out that the Closing in favor of #44871. |
The current PriorityQueue Implementation for .NET PriorityQueue Implementation for .NET does not have the Remove(TElement element) method as written on the original contract defined in this #14032
I perused the history of #14032 spanning half a decade+ worth of discussions (!) and unfortunately didn't find the post which proposed to remove the the Remove method from the final implementation.
Can someone shed some light on this? I would have expected the .NET Priority Queue implementation to have a certain degree of parity to [Java's implementation] (https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html)
Also, +💯 this #14032 (comment) - would be great if the history of this API was written up as a blog entry on DevDiv :)
The text was updated successfully, but these errors were encountered: