diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 8efc4cd50c1a6..4abe555b0eaea 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -567,6 +567,13 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> { fn size_hint(&self) -> (uint, Option) { 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 { iter: vec::MoveItems, @@ -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 = pq.iter().rev().map(|&x| x).collect(); + assert_eq!(v, iterout); + } + #[test] fn test_move_iter() { let data = vec!(5i, 9, 3);