Uh oh!
There was an error while loading. Please reload this page.
Add BinaryHeap::retain - #668
Conversation
87e788b to
64e77dfComparezeenix
commented
Jul 8, 2026
How so? |
The implementation doesn't preserve the order invariant of the binary heap. |
zeenix
commented
Jul 8, 2026
Huh? Is it? 🤔 https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=98dfdde25b2a102d7146761f6d5294db |
Conaclos
commented
Jul 8, 2026
I will add some tests for |
Conaclos
commented
Jul 8, 2026
Your example is wrong because you called |
zeenix
commented
Jul 8, 2026
Ah right. That was from the std doc example I started off from. |
58678fe to
1535316CompareConaclos
commented
Jul 21, 2026
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Conaclos
commented
Jul 27, 2026
@zeenix Is there any concerns preventing merging this feature? |
zeenix
commented
Jul 27, 2026
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!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@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
7de39e5Comparesgued
commented
Aug 5, 2026
I rebased it and force pushed a typo fix and CI fixes |
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.