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

Implement into_iter() for BinaryHeap. #19236

Closed
wants to merge 1 commit into from
Closed

Conversation

csouth3
Copy link
Contributor

@csouth3 csouth3 commented Nov 23, 2014

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!

@rust-highfive
Copy link
Collaborator

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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!

@Gankra
Copy link
Contributor

Gankra commented Nov 23, 2014

The implementation is 100% correct. Just some style/api/testing issues to hammer out. Thanks for doing this!

@csouth3
Copy link
Contributor Author

csouth3 commented Nov 23, 2014

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.

@csouth3
Copy link
Contributor Author

csouth3 commented Nov 23, 2014

OK, everyone. Sorry for the delay, but I've updated the commit based on all received feedback. make check is passing with the updated tests. Thanks for the help!

#[inline]
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}

Copy link
Contributor

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.

@csouth3
Copy link
Contributor Author

csouth3 commented Nov 24, 2014

All right, I've implemented DoubleEndedIterator and ExactSize, and added one additional test. Once again, this passes make check.

bors added a commit that referenced this pull request Nov 24, 2014
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!
@bors bors closed this Nov 24, 2014
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.

7 participants