use default::Default;
use fmt::{mod, Show};
use hash::{Hash, Hasher, RandomSipHasher};
-use iter::{mod, Iterator, IteratorExt, FromIterator, Extend};
+use iter::{mod, Iterator, IteratorExt, FromIterator, Extend, Map};
use kinds::Sized;
use mem::{mod, replace};
use num::{Int, UnsignedInt};
pub fn keys(&self) -> Keys<K, V> {
fn first<A, B>((a, _): (A, B)) -> A { a }
- self.iter().map(first)
+ Keys { inner: self.iter().map(first) }
}
/// An iterator visiting all values in arbitrary order.
pub fn values(&self) -> Values<K, V> {
fn second<A, B>((_, b): (A, B)) -> B { b }
- self.iter().map(second)
+ Values { inner: self.iter().map(second) }
}
/// An iterator visiting all key-value pairs in arbitrary order.
>
}
+/// HashMap keys iterator
+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>
+}
+
+/// HashMap values iterator
+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 occupied location in a HashMap
pub struct OccupiedEntry<'a, K:'a, V:'a> {
elem: FullBucket<K, V, &'a mut RawTable<K, V>>,
}
impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> {
- #[inline]
- fn next(&mut self) -> Option<(&'a K, &'a V)> {
- self.inner.next()
- }
- #[inline]
- fn size_hint(&self) -> (uint, Option<uint>) {
- self.inner.size_hint()
- }
+ #[inline] fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() }
+ #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> {
- #[inline]
- fn next(&mut self) -> Option<(&'a K, &'a mut V)> {
- self.inner.next()
- }
- #[inline]
- fn size_hint(&self) -> (uint, Option<uint>) {
- self.inner.size_hint()
- }
+ #[inline] fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() }
+ #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
impl<K, V> Iterator<(K, V)> for MoveEntries<K, V> {
- #[inline]
- fn next(&mut self) -> Option<(K, V)> {
- self.inner.next()
- }
- #[inline]
- fn size_hint(&self) -> (uint, Option<uint>) {
- self.inner.size_hint()
- }
+ #[inline] fn next(&mut self) -> Option<(K, V)> { self.inner.next() }
+ #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
+}
+
+impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> {
+ #[inline] fn next(&mut self) -> Option<(&'a K)> { self.inner.next() }
+ #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
+}
+
+impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> {
+ #[inline] fn next(&mut self) -> Option<(&'a V)> { self.inner.next() }
+ #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
impl<'a, K, V> OccupiedEntry<'a, K, V> {
}
}
-/// HashMap keys iterator
-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>;
-
-/// HashMap values iterator
-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>;
-
impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> FromIterator<(K, V)> for HashMap<K, V, H> {
fn from_iter<T: Iterator<(K, V)>>(iter: T) -> HashMap<K, V, H> {
let (lower, _) = iter.size_hint();
use option::Option::{Some, None, mod};
use result::Result::{Ok, Err};
-use super::map::{HashMap, Entries, MoveEntries, INITIAL_CAPACITY};
+use super::map::{HashMap, MoveEntries, Keys, INITIAL_CAPACITY};
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
}
/// HashSet iterator
-pub type SetItems<'a, K> =
- iter::Map<(&'a K, &'a ()), &'a K, Entries<'a, K, ()>, fn((&'a K, &'a ())) -> &'a K>;
+pub type SetItems<'a, K> = Keys<'a, K, ()>;
/// HashSet move iterator
pub type SetMoveItems<K> = iter::Map<(K, ()), K, MoveEntries<K, ()>, fn((K, ())) -> K>;