///
/// If the map did not have this key present, `None` is returned.
///
- /// If the map did have this key present, the key is not updated, the
- /// value is updated and the old value is returned.
- /// See the [module-level documentation] for more.
+ /// If the map did have this key present, the value is updated, and the old
+ /// value is returned. The key is not updated, though; this matters for
+ /// types that can be `==` without being identical. See the [module-level
+ /// documentation] for more.
///
/// [module-level documentation]: index.html#insert-and-complex-keys
///
}
impl<K, V> BTreeMap<K, V> {
- /// Gets an iterator over the entries of the map.
+ /// Gets an iterator over the entries of the map, sorted by key.
///
/// # Examples
///
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
- /// map.insert(1, "a");
- /// map.insert(2, "b");
/// map.insert(3, "c");
+ /// map.insert(2, "b");
+ /// map.insert(1, "a");
///
/// for (key, value) in map.iter() {
/// println!("{}: {}", key, value);
}
}
- /// Gets a mutable iterator over the entries of the map.
+ /// Gets a mutable iterator over the entries of the map, sorted by key.
///
/// # Examples
///
}
}
- /// Gets an iterator over the keys of the map.
+ /// Gets an iterator over the keys of the map, in sorted order.
///
/// # Examples
///
/// use std::collections::BTreeMap;
///
/// let mut a = BTreeMap::new();
- /// a.insert(1, "a");
/// a.insert(2, "b");
+ /// a.insert(1, "a");
///
/// let keys: Vec<_> = a.keys().cloned().collect();
/// assert_eq!(keys, [1, 2]);
Keys { inner: self.iter() }
}
- /// Gets an iterator over the values of the map.
+ /// Gets an iterator over the values of the map, in order by key.
///
/// # Examples
///
/// use std::collections::BTreeMap;
///
/// let mut a = BTreeMap::new();
- /// a.insert(1, "a");
- /// a.insert(2, "b");
+ /// a.insert(1, "hello");
+ /// a.insert(2, "goodbye");
///
/// let values: Vec<&str> = a.values().cloned().collect();
- /// assert_eq!(values, ["a", "b"]);
+ /// assert_eq!(values, ["hello", "goodbye"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values<'a>(&'a self) -> Values<'a, K, V> {