Add BinaryHeap::retain - #668
Conversation
87e788b to
64e77df
Compare
How so? |
The implementation doesn't preserve the order invariant of the binary heap. |
Huh? Is it? 🤔 https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=98dfdde25b2a102d7146761f6d5294db |
|
I will add some tests for |
Your example is wrong because you called |
Ah right. That was from the std doc example I started off from. |
4c41991 to
d8e3a5c
Compare
985fee8 to
beb1189
Compare
58678fe to
1535316
Compare
|
Ready for review! |
zeenix
left a comment
There was a problem hiding this comment.
Only tiny nits and then it's good from my side.
|
@zeenix Is there any concerns preventing merging this feature? |
Not from my side but I was hoping for another review from someone else. |
sgued
left a comment
There was a problem hiding this comment.
LGTM besides two small nits.
Thank you!
|
@sgued Fixed. I took the opportunity of making unsafe the relevant functions, adding missing unsafe blocks and SAFETY comments. This improves compatibility with I added Last, I turned some conditionals into early returns to make them cold paths. |
9fb7ae8 to
7de39e5
Compare
Implement #666
This PR adds the
BinaryHeap::retainmethod.I didn't base my work on #345 because the implementation seems wrong to me.
I added an internal method
BinaryHeap::removethat is now used by bothBinaryHeap::retainandBinaryHeap::pop_unchecked.In the process I improved its implementation.
One alternative implementation could be to traverse the internal vector in reverse order. This could reduce the number of shifted elements if
retainremoves multiple elements. However, this would make the implementation much more complex.