use clone::Clone;
use cmp::{max, Eq, PartialEq};
use default::Default;
-use fmt::{self, Show};
+use fmt::{self, Debug};
use hash::{self, Hash, SipHasher};
-use iter::{self, Iterator, IteratorExt, FromIterator, Extend, Map};
+use iter::{self, Iterator, ExactSizeIterator, IteratorExt, FromIterator, Extend, Map};
use marker::Sized;
use mem::{self, replace};
use num::{Int, UnsignedInt};
/// ```
/// use std::collections::HashMap;
///
-/// #[derive(Hash, Eq, PartialEq, Show)]
+/// #[derive(Hash, Eq, PartialEq, Debug)]
/// struct Viking {
/// name: String,
/// country: String,
{}
#[stable]
-impl<K, V, S, H> Show for HashMap<K, V, S>
- where K: Eq + Hash<H> + Show, V: Show,
+impl<K, V, S, H> Debug for HashMap<K, V, S>
+ where K: Eq + Hash<H> + Debug, V: Debug,
S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64>
{
type Item = (&'a K, &'a 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 size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[stable]
type Item = (&'a K, &'a mut 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 size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[stable]
type Item = (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 size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<K, V> ExactSizeIterator for IntoIter<K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[stable]
type Item = &'a K;
#[inline] fn next(&mut self) -> Option<(&'a K)> { self.inner.next() }
- #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
+ #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[stable]
type Item = &'a V;
#[inline] fn next(&mut self) -> Option<(&'a V)> { self.inner.next() }
- #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
+ #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[stable]
-impl<'a, K: 'a, V: 'a> Iterator for Drain<'a, K, V> {
+impl<'a, K, V> Iterator for Drain<'a, K, V> {
type Item = (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) -> (usize, Option<usize>) { self.inner.size_hint() }
+}
+#[stable]
+impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
+ #[inline] fn len(&self) -> usize { self.inner.len() }
}
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
let map_str = format!("{:?}", map);
- assert!(map_str == "HashMap {1i: 2i, 3i: 4i}" ||
- map_str == "HashMap {3i: 4i, 1i: 2i}");
+ assert!(map_str == "HashMap {1: 2, 3: 4}" ||
+ map_str == "HashMap {3: 4, 1: 2}");
assert_eq!(format!("{:?}", empty), "HashMap {}");
}
assert_eq!(m.remove(&0), Some(0));
}
- #[test]
- fn test_find_equiv() {
- let mut m = HashMap::new();
-
- let (foo, bar, baz) = (1i,2i,3i);
- m.insert("foo".to_string(), foo);
- m.insert("bar".to_string(), bar);
- m.insert("baz".to_string(), baz);
-
-
- assert_eq!(m.get("foo"), Some(&foo));
- assert_eq!(m.get("bar"), Some(&bar));
- assert_eq!(m.get("baz"), Some(&baz));
-
- assert_eq!(m.get("qux"), None);
- }
-
#[test]
fn test_from_iter() {
let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
assert_eq!(iter.size_hint(), (3, Some(3)));
}
+ #[test]
+ fn test_iter_len() {
+ let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
+
+ let map: HashMap<int, int> = xs.iter().map(|&x| x).collect();
+
+ let mut iter = map.iter();
+
+ for _ in iter.by_ref().take(3) {}
+
+ assert_eq!(iter.len(), 3);
+ }
+
#[test]
fn test_mut_size_hint() {
let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
assert_eq!(iter.size_hint(), (3, Some(3)));
}
+ #[test]
+ fn test_iter_mut_len() {
+ let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
+
+ let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect();
+
+ let mut iter = map.iter_mut();
+
+ for _ in iter.by_ref().take(3) {}
+
+ assert_eq!(iter.len(), 3);
+ }
+
#[test]
fn test_index() {
let mut map: HashMap<int, int> = HashMap::new();