diff options
| author | Chase Southwood <chase.southwood@gmail.com> | 2014-11-25 20:57:32 -0600 |
|---|---|---|
| committer | Chase Southwood <chase.southwood@gmail.com> | 2014-11-25 21:41:23 -0600 |
| commit | d48886cc88944c51066742e72fe29b1bc6e004a3 (patch) | |
| tree | 7e3e842de7df9e8ed659d5034141f82c8f4f2457 | |
| parent | eedfc077964b811315589d9a70293d3ff2eb0e1d (diff) | |
Make BinaryHeap's Items iterator implement DoubleEnded and ExactSize
| -rw-r--r-- | src/libcollections/binary_heap.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 8efc4cd50c1..4abe555b0ea 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<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>, @@ -626,6 +633,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); let iterout = vec!(9i, 5, 3); |
