-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Min-Max Heap to std::collections
#76250
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
Comments
This can be written as an external crate, has that been done already? |
Also, if this really ends up being a more powerful and faster |
https://crates.io/crates/min-max-heap seems to be an existing implementation |
Hmm, can it? I thought that |
I wonder if it's possible to do better than min-max heap by forgoing min-max property? Ie, an array can pack three interleaving tetrary max heaps.This give you the same parallel comparisons + four consequtive chilren in a row property. EDIT: very quick&dirty benchmark did not disprove hypothesis that just making the heap four way makes it faster: https://github.com/matklad/quadheap/blob/91eb33870fc49280dda1e9be1fa904fc93d7364c/src/quad_heap.rs EDIT EDIT: this is stupid and overly complicated. We can pack just one tetray heap into the array (i -> 4i + 1, 4i + 2, 4i + 3, 4i + 4) and that should be the best impl. |
The current comment for @matklad if you want to benchmark that you should probably remove those bound checks. We should also consider removing branches from |
After the conversation about trying to stabilize Having such a heap would address a bunch of things:
In a way it'd be like the |
Closing this as it is better for this to be in a crate |
I just read a blog post about the Min-Max heap being faster than the Binary Heap on modern processors, while being strictly more powerful since you can pop from both ends: https://probablydance.com/2020/08/31/on-modern-hardware-the-min-max-heap-beats-a-binary-heap/
Given these benefits, and since
BinaryHeap
is included instd::collections
, I wonder if it would make sense to include aMinMaxHeap
as well?The text was updated successfully, but these errors were encountered: