-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
BinaryHeap flexibility, BuildComparator #38886
Comments
The general case might still feel like annoying boiler plate with what I suggested, having to implement a |
I would love to support this better. That D code is really slick! I believe this is going to require an RFC in which someone proposes a concrete API for how this would work in Rust. The BuildComparator approach sounds promising. |
In D language when you create a binary heap you can optionally specify the comparison function:
This is handy. Similar code in Rust:
If you just have to reverse the ordering (a min-heap) you can sometimes wrap your items with this:
https://docs.rs/revord/0.0.2/revord/struct.RevOrd.html
But in general the cmp function can be more complex (or it can involve just one field of each item). Currently to solve this problem you need to write a lot of boilerplate code, a newtype and implement the four Eq/Ord traits on it (but a binary heap doesn't need to test the equality of the the items).
So can we add something more handy to BinaryHeap to specify a different comparison function?
A comment by cuviper:
The text was updated successfully, but these errors were encountered: