rollup merge of #19330: csouth3/binaryheap-iter

There's no reason that BinaryHeap's iterator can't implement DoubleEnded and ExactSize, so add these implementations.
This commit is contained in:
Alex Crichton 2014-11-26 09:47:11 -08:00
commit 8f94ea0823

View File

@ -567,6 +567,13 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<(&'a T)> { self.iter.next_back() }
}
impl<'a, T> ExactSize<&'a T> for Items<'a, T> {}
/// An iterator that moves out of a `BinaryHeap`.
pub struct MoveItems<T> {
iter: vec::MoveItems<T>,
@ -625,6 +632,16 @@ mod tests {
}
}
#[test]
fn test_iterator_reverse() {
let data = vec!(5i, 9, 3);
let iterout = vec!(3i, 5, 9);
let pq = BinaryHeap::from_vec(data);
let v: Vec<int> = pq.iter().rev().map(|&x| x).collect();
assert_eq!(v, iterout);
}
#[test]
fn test_move_iter() {
let data = vec!(5i, 9, 3);