Skip to content
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

Added mutable peeking #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Added mutable peeking #15

wants to merge 1 commit into from

Conversation

Zagitta
Copy link

@Zagitta Zagitta commented Jul 31, 2017

I've added mutable peeking similar to how ´std::collections::BinaryHeap` does it and has the same caveat that if the mutable reference is leaked the heap might end up in an invalid state.
I'm not sure if this is a desirable feature for you but I figured I'd share the code either way and if not feel free to reject the PR.

Best regards, Simon.

@FlashCat
Copy link
Contributor

Thanks for the pull request, and welcome! The contain-rs team is excited to review your changes, and you should hear from @gankro (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

@sellibitze
Copy link

👍

That looks really cool and useful! And I don't worry about invalid states. The way you implemented it, it's really hard to put the data structure into an invalid state. And even if the user mutates the min/max item and leaks a MutPeek, it's not going to blow up in our faces (w.r.t. memory safety). So, that's good.

@Zagitta
Copy link
Author

Zagitta commented Aug 1, 2017

I won't take any credit for designing anything 😄 I'm still very new to rust and more or less straight up copied the implementation from BinaryHeap, I just did some bike-shedding and renamed PeekMut to MutPeek 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants