-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add remove, contains functions to BinaryHeap #66724
Comments
But isn't that excactly the purpose of a BinaryHeap. You are most likely only interested in the biggest/smallest element. If you just want an ordered thing, use a |
There is no pop function in a BTreeSet although you could probably use Anyways, there are algorithms where you are interested in the minimum of a set in one step, then you remove it as well as items associated with it (which aren't neccessarily minima themselves). Then you are interested in the minimum again, etc. What I'm doing right now is to have a separate For me, the purpose of a BinaryHeap is not that its operations are restricted, but that the invariant of a minimum being quickly accessible is maintained. |
@billyrieger as you made #68378 , do you want to make this one next? |
I agree with this sentiment. On the other hand, one could argue adding these operations would unnecessarily clutter the |
One use case comes straight from Wikipedia: the A* algorithm specifically suggests using a heap for
IMO |
I am stuck right exactly here, for exactly what @coriolinus mentioned. I'm implementing a number of algorithms from the A* family and there's specifically no if !open.contains(neighbour) { // this would be great!
open.push(neighbour);
} |
a if open.insert(neighbour) {
// this would be great!
} Previously I made a mistake that think Edit: find it is much harder than I could handle (unsafe for better performance, extra space consuming, cache miss(the worst case, we should check every element in the heap in a strange order)) Maybe |
I think I'll close this because such functions would have bad (linear) performance characteristics: #82001 (comment) |
This is the top Google hit for "rust BinaryHeap contains" and the top DuckDuckGo hit under |
With |
BinaryHeap currently only has functions to pop the maximum element and push an arbitrary element to it. There is no function to remove a given element from the heap or to check whether the heap contains an element. Both are kinda common operations.
The text was updated successfully, but these errors were encountered: