diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index e49a8ddbe5ab..e45e91b93ba4 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -26,6 +26,7 @@ use std::hash::{Writer, Hash}; use core::default::Default; use core::{iter, fmt, mem}; use core::fmt::Show; +use core::iter::Map; use ring_buf::RingBuf; @@ -107,12 +108,14 @@ pub struct MoveEntries { } /// An iterator over a BTreeMap's keys. -pub type Keys<'a, K, V> = - iter::Map<(&'a K, &'a V), &'a K, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>; +pub struct Keys<'a, K: 'a, V: 'a> { + inner: Map<(&'a K, &'a V), &'a K, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> +} /// An iterator over a BTreeMap's values. -pub type Values<'a, K, V> = - iter::Map<(&'a K, &'a V), &'a V, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>; +pub struct Values<'a, K: 'a, V: 'a> { + inner: Map<(&'a K, &'a V), &'a V, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> +} /// A view into a single entry in a map, which may either be vacant or occupied. pub enum Entry<'a, K:'a, V:'a> { @@ -1061,6 +1064,25 @@ impl DoubleEndedIterator<(K, V)> for MoveEntries { impl ExactSizeIterator<(K, V)> for MoveEntries {} +impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { + fn next(&mut self) -> Option<(&'a K)> { self.inner.next() } + fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } +} +impl<'a, K, V> DoubleEndedIterator<&'a K> for Keys<'a, K, V> { + fn next_back(&mut self) -> Option<(&'a K)> { self.inner.next_back() } +} +impl<'a, K, V> ExactSizeIterator<&'a K> for Keys<'a, K, V> {} + + +impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> { + fn next(&mut self) -> Option<(&'a V)> { self.inner.next() } + fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } +} +impl<'a, K, V> DoubleEndedIterator<&'a V> for Values<'a, K, V> { + fn next_back(&mut self) -> Option<(&'a V)> { self.inner.next_back() } +} +impl<'a, K, V> ExactSizeIterator<&'a V> for Values<'a, K, V> {} + impl<'a, K: Ord, V> VacantEntry<'a, K, V> { /// Sets the value of the entry with the VacantEntry's key, @@ -1211,7 +1233,7 @@ impl BTreeMap { pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } - self.iter().map(first) + Keys { inner: self.iter().map(first) } } /// Gets an iterator over the values of the map. @@ -1232,7 +1254,7 @@ impl BTreeMap { pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } - self.iter().map(second) + Values { inner: self.iter().map(second) } } /// Return the number of elements in the map.