BinaryHeap flexibility, BuildComparator #38886
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
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: