-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement into_iter() for BinaryHeap. #19236
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. |
@@ -159,11 +159,9 @@ use core::default::Default; | |||
use core::mem::{zeroed, replace, swap}; | |||
use core::ptr; | |||
|
|||
use slice; | |||
use {slice, vec}; | |||
use vec::Vec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this could be use vec::{mod, Vec};
instead of putting the vec
import on line 162.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duly noted...I'll get this fixed up tomorrow. Thanks!
The implementation is 100% correct. Just some style/api/testing issues to hammer out. Thanks for doing this! |
Thanks for these reviews! When I get back to my computer in an hour or so I'll address all of these comments and update the pull request. |
OK, everyone. Sorry for the delay, but I've updated the commit based on all received feedback. |
#[inline] | ||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can/should also be able to implement DoubleEndedIterator and ExactSize.
All right, I've implemented DoubleEndedIterator and ExactSize, and added one additional test. Once again, this passes |
Whilst browsing the source for BinaryHeap, I saw a FIXME for implementing into_iter. I think, since the BinaryHeap is represented internally using just a Vec, just calling into_iter() on the BinaryHeap's data should be sufficient to do what we want here. If this actually isn't the right approach (e.g., I should write a struct MoveItems and appropriate implementation for BinaryHeap instead), let me know and I'll happily rework this. Both of the tests that I have added pass. This is my first contribution to Rust, so please let me know any ways I can improve this PR!
Whilst browsing the source for BinaryHeap, I saw a FIXME for implementing into_iter. I think, since the BinaryHeap is represented internally using just a Vec, just calling into_iter() on the BinaryHeap's data should be sufficient to do what we want here. If this actually isn't the right approach (e.g., I should write a struct MoveItems and appropriate implementation for BinaryHeap instead), let me know and I'll happily rework this.
Both of the tests that I have added pass. This is my first contribution to Rust, so please let me know any ways I can improve this PR!