#[inline]
fn clone_from(&mut self, source: &SmallIntMap<V>) {
self.v.reserve(source.v.len());
- for (i, w) in self.v.mut_iter().enumerate() {
+ for (i, w) in self.v.iter_mut().enumerate() {
*w = source.v[i].clone();
}
}
}
}
+ /// Deprecated: use `iter_mut`
+ #[deprecated = "use iter_mut"]
+ pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> {
+ self.iter_mut()
+ }
+
/// Returns an iterator visiting all key-value pairs in ascending order by the keys,
/// with mutable references to the values.
/// The iterator's element type is `(uint, &'r mut V)`.
/// map.insert(2, "b");
/// map.insert(3, "c");
///
- /// for (key, value) in map.mut_iter() {
+ /// for (key, value) in map.iter_mut() {
/// *value = "x";
/// }
///
/// assert_eq!(value, &"x");
/// }
/// ```
- pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> {
+ pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> {
MutEntries {
front: 0,
back: self.v.len(),
- iter: self.v.mut_iter()
+ iter: self.v.iter_mut()
}
}
+ /// Deprecated: use `into_iter` instead.
+ #[deprecated = "use into_iter"]
+ pub fn move_iter(&mut self)
+ -> FilterMap<(uint, Option<V>), (uint, V),
+ Enumerate<vec::MoveItems<Option<V>>>> {
+ self.into_iter()
+ }
+
/// Returns an iterator visiting all key-value pairs in ascending order by
/// the keys, emptying (but not consuming) the original `SmallIntMap`.
/// The iterator's element type is `(uint, &'r V)`.
/// map.insert(2, "b");
///
/// // Not possible with .iter()
- /// let vec: Vec<(uint, &str)> = map.move_iter().collect();
+ /// let vec: Vec<(uint, &str)> = map.into_iter().collect();
///
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
/// ```
- pub fn move_iter(&mut self)
+ pub fn into_iter(&mut self)
-> FilterMap<(uint, Option<V>), (uint, V),
Enumerate<vec::MoveItems<Option<V>>>>
{
let values = replace(&mut self.v, vec!());
- values.move_iter().enumerate().filter_map(|(i, v)| {
+ values.into_iter().enumerate().filter_map(|(i, v)| {
v.map(|v| (i, v))
})
}
/// Updates a value in the map. If the key already exists in the map,
/// modifies the value with `ff` taking `oldval, newval`.
/// Otherwise, sets the value to `newval`.
- /// Returasn `true` if the key did not already exist in the map.
+ /// Returns `true` if the key did not already exist in the map.
///
/// # Example
///
}
}
-/// Note: stage0-specific version that lacks bound on A.
-#[cfg(stage0)]
-pub struct Entries<'a, T> {
- front: uint,
- back: uint,
- iter: slice::Items<'a, Option<T>>
-}
-
/// Forward iterator over a map.
-#[cfg(not(stage0))]
pub struct Entries<'a, T:'a> {
front: uint,
back: uint,
iterator!(impl Entries -> (uint, &'a T), get_ref)
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
-/// Note: stage0-specific version that lacks bound on A.
-#[cfg(stage0)]
-pub struct MutEntries<'a, T> {
- front: uint,
- back: uint,
- iter: slice::MutItems<'a, Option<T>>
-}
-
/// Forward iterator over the key-value pairs of a map, with the
/// values being mutable.
-#[cfg(not(stage0))]
pub struct MutEntries<'a, T:'a> {
front: uint,
back: uint,
assert_eq!(m.iter().size_hint(), (0, Some(11)));
assert_eq!(m.iter().rev().size_hint(), (0, Some(11)));
- assert_eq!(m.mut_iter().size_hint(), (0, Some(11)));
- assert_eq!(m.mut_iter().rev().size_hint(), (0, Some(11)));
+ assert_eq!(m.iter_mut().size_hint(), (0, Some(11)));
+ assert_eq!(m.iter_mut().rev().size_hint(), (0, Some(11)));
}
#[test]
assert!(m.insert(6, 10));
assert!(m.insert(10, 11));
- for (k, v) in m.mut_iter() {
+ for (k, v) in m.iter_mut() {
*v += k as int;
}
assert!(m.insert(6, 10));
assert!(m.insert(10, 11));
- for (k, v) in m.mut_iter().rev() {
+ for (k, v) in m.iter_mut().rev() {
*v += k as int;
}
let mut m = SmallIntMap::new();
m.insert(1, box 2i);
let mut called = false;
- for (k, v) in m.move_iter() {
+ for (k, v) in m.into_iter() {
assert!(!called);
called = true;
assert_eq!(k, 1);