fix outdated docs

Conflicts:
	src/libstd/collections/mod.rs
This commit is contained in:
Alexis 2015-02-06 13:57:13 -05:00 committed by Manish Goregaokar
parent 3a9b4e5f8d
commit e15538d7ac
7 changed files with 88 additions and 88 deletions

View file

@ -183,7 +183,7 @@ impl<T: Ord> BinaryHeap<T> {
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
/// heap.push(4u);
/// heap.push(4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BinaryHeap<T> { BinaryHeap { data: vec![] } }
@ -198,7 +198,7 @@ impl<T: Ord> BinaryHeap<T> {
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::with_capacity(10);
/// heap.push(4u);
/// heap.push(4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: usize) -> BinaryHeap<T> {
@ -292,7 +292,7 @@ impl<T: Ord> BinaryHeap<T> {
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::with_capacity(100);
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// heap.push(4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> usize { self.data.capacity() }
@ -315,7 +315,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::new();
/// heap.reserve_exact(100);
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// heap.push(4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: usize) {
@ -336,7 +336,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::new();
/// heap.reserve(100);
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// heap.push(4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: usize) {

View file

@ -173,7 +173,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut a = BTreeMap::new();
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// a.clear();
/// assert!(a.is_empty());
/// ```
@ -203,7 +203,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.get(&1), Some(&"a"));
/// assert_eq!(map.get(&2), None);
/// ```
@ -235,7 +235,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.contains_key(&1), true);
/// assert_eq!(map.contains_key(&2), false);
/// ```
@ -255,7 +255,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// match map.get_mut(&1) {
/// Some(x) => *x = "b",
/// None => (),
@ -317,7 +317,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// assert_eq!(map.insert(37u, "a"), None);
/// assert_eq!(map.insert(37, "a"), None);
/// assert_eq!(map.is_empty(), false);
///
/// map.insert(37, "b");
@ -429,7 +429,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.remove(&1), Some("a"));
/// assert_eq!(map.remove(&1), None);
/// ```
@ -1170,16 +1170,16 @@ impl<K, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(2u, "b");
/// map.insert(3u, "c");
/// map.insert(1, "a");
/// map.insert(2, "b");
/// map.insert(3, "c");
///
/// for (key, value) in map.iter() {
/// println!("{}: {}", key, value);
/// }
///
/// let (first_key, first_value) = map.iter().next().unwrap();
/// assert_eq!((*first_key, *first_value), (1u, "a"));
/// assert_eq!((*first_key, *first_value), (1, "a"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<K, V> {
@ -1203,9 +1203,9 @@ impl<K, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert("a", 1u);
/// map.insert("b", 2u);
/// map.insert("c", 3u);
/// map.insert("a", 1);
/// map.insert("b", 2);
/// map.insert("c", 3);
///
/// // add 10 to the value if the key isn't "a"
/// for (key, value) in map.iter_mut() {
@ -1235,9 +1235,9 @@ impl<K, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1u, "a");
/// map.insert(2u, "b");
/// map.insert(3u, "c");
/// map.insert(1, "a");
/// map.insert(2, "b");
/// map.insert(3, "c");
///
/// for (key, value) in map.into_iter() {
/// println!("{}: {}", key, value);
@ -1264,11 +1264,11 @@ impl<K, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut a = BTreeMap::new();
/// a.insert(1u, "a");
/// a.insert(2u, "b");
/// a.insert(1, "a");
/// a.insert(2, "b");
///
/// let keys: Vec<usize> = a.keys().cloned().collect();
/// assert_eq!(keys, vec![1u,2,]);
/// assert_eq!(keys, vec![1,2,]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
@ -1286,8 +1286,8 @@ impl<K, V> BTreeMap<K, V> {
/// use std::collections::BTreeMap;
///
/// let mut a = BTreeMap::new();
/// a.insert(1u, "a");
/// a.insert(2u, "b");
/// a.insert(1, "a");
/// a.insert(2, "b");
///
/// let values: Vec<&str> = a.values().cloned().collect();
/// assert_eq!(values, vec!["a","b"]);
@ -1309,7 +1309,7 @@ impl<K, V> BTreeMap<K, V> {
///
/// let mut a = BTreeMap::new();
/// assert_eq!(a.len(), 0);
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -1324,7 +1324,7 @@ impl<K, V> BTreeMap<K, V> {
///
/// let mut a = BTreeMap::new();
/// assert!(a.is_empty());
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// assert!(!a.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -1474,13 +1474,13 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// use std::collections::Bound::{Included, Unbounded};
///
/// let mut map = BTreeMap::new();
/// map.insert(3u, "a");
/// map.insert(5u, "b");
/// map.insert(8u, "c");
/// map.insert(3, "a");
/// map.insert(5, "b");
/// map.insert(8, "c");
/// for (&key, &value) in map.range(Included(&4), Included(&8)) {
/// println!("{}: {}", key, value);
/// }
/// assert_eq!(Some((&5u, &"b")), map.range(Included(&4), Unbounded).next());
/// assert_eq!(Some((&5, &"b")), map.range(Included(&4), Unbounded).next());
/// ```
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
@ -1539,7 +1539,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// }
/// }
///
/// assert_eq!(count["a"], 3u);
/// assert_eq!(count["a"], 3);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn entry(&mut self, mut key: K) -> Entry<K, V> {

View file

@ -114,14 +114,14 @@ impl<T> BTreeSet<T> {
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().map(|&x| x).collect();
///
/// for x in set.iter() {
/// println!("{}", x);
/// }
///
/// let v: Vec<usize> = set.iter().map(|&x| x).collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// assert_eq!(v, vec![1,2,3,4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
@ -135,10 +135,10 @@ impl<T> BTreeSet<T> {
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().map(|&x| x).collect();
///
/// let v: Vec<usize> = set.into_iter().collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// assert_eq!(v, vec![1,2,3,4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
@ -162,13 +162,13 @@ impl<T: Ord> BTreeSet<T> {
/// use std::collections::Bound::{Included, Unbounded};
///
/// let mut set = BTreeSet::new();
/// set.insert(3u);
/// set.insert(5u);
/// set.insert(8u);
/// set.insert(3);
/// set.insert(5);
/// set.insert(8);
/// for &elem in set.range(Included(&4), Included(&8)) {
/// println!("{}", elem);
/// }
/// assert_eq!(Some(&5u), set.range(Included(&4), Unbounded).next());
/// assert_eq!(Some(&5), set.range(Included(&4), Unbounded).next());
/// ```
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
@ -189,15 +189,15 @@ impl<T: Ord> BTreeSet<T> {
/// use std::collections::BTreeSet;
///
/// let mut a = BTreeSet::new();
/// a.insert(1u);
/// a.insert(2u);
/// a.insert(1);
/// a.insert(2);
///
/// let mut b = BTreeSet::new();
/// b.insert(2u);
/// b.insert(3u);
/// b.insert(2);
/// b.insert(3);
///
/// let diff: Vec<usize> = a.difference(&b).cloned().collect();
/// assert_eq!(diff, vec![1u]);
/// assert_eq!(diff, vec![1]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> {
@ -212,15 +212,15 @@ impl<T: Ord> BTreeSet<T> {
/// use std::collections::BTreeSet;
///
/// let mut a = BTreeSet::new();
/// a.insert(1u);
/// a.insert(2u);
/// a.insert(1);
/// a.insert(2);
///
/// let mut b = BTreeSet::new();
/// b.insert(2u);
/// b.insert(3u);
/// b.insert(2);
/// b.insert(3);
///
/// let sym_diff: Vec<usize> = a.symmetric_difference(&b).cloned().collect();
/// assert_eq!(sym_diff, vec![1u,3]);
/// assert_eq!(sym_diff, vec![1,3]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>)
@ -236,15 +236,15 @@ impl<T: Ord> BTreeSet<T> {
/// use std::collections::BTreeSet;
///
/// let mut a = BTreeSet::new();
/// a.insert(1u);
/// a.insert(2u);
/// a.insert(1);
/// a.insert(2);
///
/// let mut b = BTreeSet::new();
/// b.insert(2u);
/// b.insert(3u);
/// b.insert(2);
/// b.insert(3);
///
/// let intersection: Vec<usize> = a.intersection(&b).cloned().collect();
/// assert_eq!(intersection, vec![2u]);
/// assert_eq!(intersection, vec![2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a BTreeSet<T>)
@ -260,13 +260,13 @@ impl<T: Ord> BTreeSet<T> {
/// use std::collections::BTreeSet;
///
/// let mut a = BTreeSet::new();
/// a.insert(1u);
/// a.insert(1);
///
/// let mut b = BTreeSet::new();
/// b.insert(2u);
/// b.insert(2);
///
/// let union: Vec<usize> = a.union(&b).cloned().collect();
/// assert_eq!(union, vec![1u,2]);
/// assert_eq!(union, vec![1,2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T> {

View file

@ -388,7 +388,7 @@ impl<T> RingBuf<T> {
/// use std::collections::RingBuf;
///
/// let mut buf = RingBuf::with_capacity(15);
/// buf.extend(0u..4);
/// buf.extend(0..4);
/// assert_eq!(buf.capacity(), 15);
/// buf.shrink_to_fit();
/// assert!(buf.capacity() >= 4);

View file

@ -90,7 +90,7 @@ impl DefaultResizePolicy {
fn test_resize_policy() {
use prelude::v1::*;
let rp = DefaultResizePolicy;
for n in 0u..1000 {
for n in 0..1000 {
assert!(rp.min_capacity(rp.usable_capacity(n)) <= n);
assert!(rp.usable_capacity(rp.min_capacity(n)) <= n);
}
@ -287,9 +287,9 @@ fn test_resize_policy() {
/// // Use a HashMap to store the vikings' health points.
/// let mut vikings = HashMap::new();
///
/// vikings.insert(Viking::new("Einar", "Norway"), 25u);
/// vikings.insert(Viking::new("Olaf", "Denmark"), 24u);
/// vikings.insert(Viking::new("Harald", "Iceland"), 12u);
/// vikings.insert(Viking::new("Einar", "Norway"), 25);
/// vikings.insert(Viking::new("Olaf", "Denmark"), 24);
/// vikings.insert(Viking::new("Harald", "Iceland"), 12);
///
/// // Use derived implementation to print the status of the vikings.
/// for (viking, health) in vikings.iter() {
@ -537,7 +537,7 @@ impl<K, V, S, H> HashMap<K, V, S>
///
/// let s = RandomState::new();
/// let mut map = HashMap::with_hash_state(s);
/// map.insert(1, 2u);
/// map.insert(1, 2);
/// ```
#[inline]
#[unstable(feature = "std_misc", reason = "hasher stuff is unclear")]
@ -565,7 +565,7 @@ impl<K, V, S, H> HashMap<K, V, S>
///
/// let s = RandomState::new();
/// let mut map = HashMap::with_capacity_and_hash_state(10, s);
/// map.insert(1, 2u);
/// map.insert(1, 2);
/// ```
#[inline]
#[unstable(feature = "std_misc", reason = "hasher stuff is unclear")]
@ -947,7 +947,7 @@ impl<K, V, S, H> HashMap<K, V, S>
///
/// let mut a = HashMap::new();
/// assert_eq!(a.len(), 0);
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -962,7 +962,7 @@ impl<K, V, S, H> HashMap<K, V, S>
///
/// let mut a = HashMap::new();
/// assert!(a.is_empty());
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// assert!(!a.is_empty());
/// ```
#[inline]
@ -978,8 +978,8 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut a = HashMap::new();
/// a.insert(1u, "a");
/// a.insert(2u, "b");
/// a.insert(1, "a");
/// a.insert(2, "b");
///
/// for (k, v) in a.drain().take(1) {
/// assert!(k == 1 || k == 2);
@ -1009,7 +1009,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut a = HashMap::new();
/// a.insert(1u, "a");
/// a.insert(1, "a");
/// a.clear();
/// assert!(a.is_empty());
/// ```
@ -1031,7 +1031,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut map = HashMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.get(&1), Some(&"a"));
/// assert_eq!(map.get(&2), None);
/// ```
@ -1054,7 +1054,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut map = HashMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.contains_key(&1), true);
/// assert_eq!(map.contains_key(&2), false);
/// ```
@ -1077,7 +1077,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut map = HashMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// match map.get_mut(&1) {
/// Some(x) => *x = "b",
/// None => (),
@ -1100,7 +1100,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut map = HashMap::new();
/// assert_eq!(map.insert(37u, "a"), None);
/// assert_eq!(map.insert(37, "a"), None);
/// assert_eq!(map.is_empty(), false);
///
/// map.insert(37, "b");
@ -1132,7 +1132,7 @@ impl<K, V, S, H> HashMap<K, V, S>
/// use std::collections::HashMap;
///
/// let mut map = HashMap::new();
/// map.insert(1u, "a");
/// map.insert(1, "a");
/// assert_eq!(map.remove(&1), Some("a"));
/// assert_eq!(map.remove(&1), None);
/// ```

View file

@ -81,10 +81,10 @@ use super::state::HashState;
///
/// let mut vikings = HashSet::new();
///
/// vikings.insert(Viking { name: "Einar", power: 9u });
/// vikings.insert(Viking { name: "Einar", power: 9u });
/// vikings.insert(Viking { name: "Olaf", power: 4u });
/// vikings.insert(Viking { name: "Harald", power: 8u });
/// vikings.insert(Viking { name: "Einar", power: 9 });
/// vikings.insert(Viking { name: "Einar", power: 9 });
/// vikings.insert(Viking { name: "Olaf", power: 4 });
/// vikings.insert(Viking { name: "Harald", power: 8 });
///
/// // Use derived implementation to print the vikings.
/// for x in vikings.iter() {
@ -146,7 +146,7 @@ impl<T, S, H> HashSet<T, S>
///
/// let s = RandomState::new();
/// let mut set = HashSet::with_hash_state(s);
/// set.insert(2u);
/// set.insert(2);
/// ```
#[inline]
#[unstable(feature = "std_misc", reason = "hasher stuff is unclear")]
@ -169,7 +169,7 @@ impl<T, S, H> HashSet<T, S>
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// let mut set = HashSet::with_capacity_and_hash_state(10u, s);
/// let mut set = HashSet::with_capacity_and_hash_state(10, s);
/// set.insert(1);
/// ```
#[inline]
@ -398,7 +398,7 @@ impl<T, S, H> HashSet<T, S>
///
/// let mut v = HashSet::new();
/// assert_eq!(v.len(), 0);
/// v.insert(1u);
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -413,7 +413,7 @@ impl<T, S, H> HashSet<T, S>
///
/// let mut v = HashSet::new();
/// assert!(v.is_empty());
/// v.insert(1u);
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -438,7 +438,7 @@ impl<T, S, H> HashSet<T, S>
/// use std::collections::HashSet;
///
/// let mut v = HashSet::new();
/// v.insert(1u);
/// v.insert(1);
/// v.clear();
/// assert!(v.is_empty());
/// ```
@ -545,7 +545,7 @@ impl<T, S, H> HashSet<T, S>
///
/// let mut set = HashSet::new();
///
/// assert_eq!(set.insert(2u), true);
/// assert_eq!(set.insert(2), true);
/// assert_eq!(set.insert(2), false);
/// assert_eq!(set.len(), 1);
/// ```
@ -566,7 +566,7 @@ impl<T, S, H> HashSet<T, S>
///
/// let mut set = HashSet::new();
///
/// set.insert(2u);
/// set.insert(2);
/// assert_eq!(set.remove(&2), true);
/// assert_eq!(set.remove(&2), false);
/// ```

View file

@ -306,7 +306,7 @@
//!
//! for c in message.chars() {
//! match count.entry(c) {
//! Entry::Vacant(entry) => { entry.insert(1u); },
//! Entry::Vacant(entry) => { entry.insert(1); },
//! Entry::Occupied(mut entry) => *entry.get_mut() += 1,
//! }
//! }