@@ -731,7 +731,7 @@ impl DefaultResizePolicy {
731
731
/// ```
732
732
///
733
733
/// The easiest way to use `HashMap` with a custom type is to derive `Eq` and `Hash`.
734
- /// We must also derive `PartialEq`, but this will in the future be implied by `Eq` .
734
+ /// We must also derive `PartialEq`.
735
735
///
736
736
/// ```
737
737
/// use std::collections::HashMap;
@@ -1056,7 +1056,7 @@ impl<K: Hash + Eq, V> HashMap<K, V, RandomSipHasher> {
1056
1056
///
1057
1057
/// ```
1058
1058
/// use std::collections::HashMap;
1059
- /// let mut map: HashMap<&str, int> = HashMap::with_capacity(10u );
1059
+ /// let mut map: HashMap<&str, int> = HashMap::with_capacity(10 );
1060
1060
/// ```
1061
1061
#[ inline]
1062
1062
pub fn with_capacity ( capacity : uint ) -> HashMap < K , V , RandomSipHasher > {
@@ -1100,7 +1100,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1100
1100
/// use std::hash::sip::SipHasher;
1101
1101
///
1102
1102
/// let h = SipHasher::new();
1103
- /// let mut map = HashMap::with_capacity_and_hasher(10u , h);
1103
+ /// let mut map = HashMap::with_capacity_and_hasher(10 , h);
1104
1104
/// map.insert(1i, 2u);
1105
1105
/// ```
1106
1106
#[ inline]
@@ -1123,7 +1123,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1123
1123
/// ```
1124
1124
/// use std::collections::HashMap;
1125
1125
/// let mut map: HashMap<&str, int> = HashMap::new();
1126
- /// map.reserve(10u );
1126
+ /// map.reserve(10 );
1127
1127
/// ```
1128
1128
pub fn reserve ( & mut self , new_minimum_capacity : uint ) {
1129
1129
let cap = num:: next_power_of_two (
@@ -1297,10 +1297,10 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1297
1297
/// let mut map = HashMap::new();
1298
1298
///
1299
1299
/// // Insert 1i with key "a"
1300
- /// assert_eq!(*map.find_or_insert("a", 1i), 1i );
1300
+ /// assert_eq!(*map.find_or_insert("a", 1i), 1 );
1301
1301
///
1302
1302
/// // Find the existing key
1303
- /// assert_eq!(*map.find_or_insert("a", -2i ), 1i );
1303
+ /// assert_eq!(*map.find_or_insert("a", -2 ), 1 );
1304
1304
/// ```
1305
1305
pub fn find_or_insert < ' a > ( & ' a mut self , k : K , v : V ) -> & ' a mut V {
1306
1306
self . find_with_or_insert_with ( k, v, |_k, _v, _a| ( ) , |_k, a| a)
@@ -1315,11 +1315,11 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1315
1315
/// use std::collections::HashMap;
1316
1316
/// let mut map = HashMap::new();
1317
1317
///
1318
- /// // Insert 10u with key 2i
1319
- /// assert_eq!(*map.find_or_insert_with(2i, |&key| { 5 * key as uint } ), 10u);
1318
+ /// // Insert 10 with key 2
1319
+ /// assert_eq!(*map.find_or_insert_with(2i, |&key| 5 * key as uint), 10u);
1320
1320
///
1321
1321
/// // Find the existing key
1322
- /// assert_eq!(*map.find_or_insert_with(2i , |&key| { key as uint } ), 10u );
1322
+ /// assert_eq!(*map.find_or_insert_with(2 , |&key| key as uint), 10 );
1323
1323
/// ```
1324
1324
pub fn find_or_insert_with < ' a > ( & ' a mut self , k : K , f: |& K | -> V )
1325
1325
-> & ' a mut V {
@@ -1336,12 +1336,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1336
1336
/// use std::collections::HashMap;
1337
1337
/// let mut map = HashMap::new();
1338
1338
///
1339
- /// // Insert 2u with key "a"
1340
- /// assert_eq!(*map.insert_or_update_with("a", 2u, |key , val| { *val = 3u; } ), 2u );
1339
+ /// // Insert 2 with key "a"
1340
+ /// assert_eq!(*map.insert_or_update_with("a", 2u, |_key , val| *val = 3 ), 2 );
1341
1341
///
1342
1342
/// // Update and return the existing value
1343
- /// assert_eq!(*map.insert_or_update_with("a", 9u , |key , val| { *val = 7u; } ), 7u );
1344
- /// assert_eq!(map.get(&"a"), &7u );
1343
+ /// assert_eq!(*map.insert_or_update_with("a", 9 , |_key , val| *val = 7 ), 7 );
1344
+ /// assert_eq!(map.get(&"a"), &7 );
1345
1345
/// ```
1346
1346
pub fn insert_or_update_with < ' a > (
1347
1347
& ' a mut self ,
@@ -1356,9 +1356,11 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1356
1356
/// insert and return a new value if it doesn't exist.
1357
1357
///
1358
1358
/// This method allows for all insertion behaviours of a hashmap;
1359
- /// see methods like `insert`, `find_or_insert` and
1360
- /// `insert_or_update_with` for less general and more friendly
1361
- /// variations of this.
1359
+ /// see methods like
1360
+ /// [`insert`](../trait.MutableMap.html#tymethod.insert),
1361
+ /// [`find_or_insert`](#method.find_or_insert) and
1362
+ /// [`insert_or_update_with`](#method.insert_or_update_with)
1363
+ /// for less general and more friendly variations of this.
1362
1364
///
1363
1365
/// # Example
1364
1366
///
@@ -1414,8 +1416,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1414
1416
}
1415
1417
}
1416
1418
1417
- /// Retrieves a value for the given key, failing if the key is not present.
1418
- /// See `find` for a non-failing alternative.
1419
+ /// Retrieves a value for the given key.
1420
+ /// See [`find`](../trait.Map.html#tymethod.find) for a non-failing alternative.
1421
+ ///
1422
+ /// # Failure
1423
+ ///
1424
+ /// Fails if the key is not present.
1419
1425
///
1420
1426
/// # Example
1421
1427
///
@@ -1424,7 +1430,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1424
1430
///
1425
1431
/// let mut map = HashMap::new();
1426
1432
/// map.insert("a", 1i);
1427
- /// assert_eq!(map.get(&"a"), &1i );
1433
+ /// assert_eq!(map.get(&"a"), &1 );
1428
1434
/// ```
1429
1435
pub fn get < ' a > ( & ' a self , k : & K ) -> & ' a V {
1430
1436
match self . find ( k) {
@@ -1433,8 +1439,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1433
1439
}
1434
1440
}
1435
1441
1436
- /// Retrieves a (mutable) value for the given key, failing if the key is not present.
1437
- /// See `find_mut` for a non-failing alternative.
1442
+ /// Retrieves a mutable value for the given key.
1443
+ /// See [`find_mut`](../trait.MutableMap.html#tymethod.find_mut) for a non-failing alternative.
1444
+ ///
1445
+ /// # Failure
1446
+ ///
1447
+ /// Fails if the key is not present.
1438
1448
///
1439
1449
/// # Example
1440
1450
///
@@ -1444,15 +1454,15 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1444
1454
/// let mut map = HashMap::new();
1445
1455
/// map.insert("a", 1i);
1446
1456
/// {
1447
- /// // val will freeze map to prevent usage during it's lifetime
1457
+ /// // val will freeze map to prevent usage during its lifetime
1448
1458
/// let val = map.get_mut(&"a");
1449
- /// *val = 40i ;
1459
+ /// *val = 40 ;
1450
1460
/// }
1451
- /// assert_eq!(map.get(&"a"), &40i );
1461
+ /// assert_eq!(map.get(&"a"), &40 );
1452
1462
///
1453
1463
/// // A more direct way could be:
1454
- /// *map.get_mut(&"a") = -2i ;
1455
- /// assert_eq!(map.get(&"a"), &-2i );
1464
+ /// *map.get_mut(&"a") = -2 ;
1465
+ /// assert_eq!(map.get(&"a"), &-2 );
1456
1466
/// ```
1457
1467
pub fn get_mut < ' a > ( & ' a mut self , k : & K ) -> & ' a mut V {
1458
1468
match self . find_mut ( k) {
@@ -1483,12 +1493,13 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1483
1493
}
1484
1494
}
1485
1495
1486
- /// Like `pop`, but can operate on any type that is equivalent to a key.
1496
+ /// Remove an equivalent key from the map, returning the value at the
1497
+ /// key if the key was previously in the map.
1487
1498
///
1488
1499
/// # Example
1489
1500
///
1490
1501
/// This is a slightly silly example where we define the number's parity as
1491
- /// the equivilance class. It is important that the values hash the same,
1502
+ /// the equivalence class. It is important that the values hash the same,
1492
1503
/// which is why we override `Hash`.
1493
1504
///
1494
1505
/// ```
@@ -1515,16 +1526,16 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1515
1526
/// }
1516
1527
///
1517
1528
/// let mut map = HashMap::new();
1518
- /// map.insert(EvenOrOdd { num: 3u }, "foo");
1529
+ /// map.insert(EvenOrOdd { num: 3 }, "foo");
1519
1530
///
1520
- /// assert!(map.contains_key_equiv(&EvenOrOdd { num: 1u }));
1521
- /// assert!(!map.contains_key_equiv(&EvenOrOdd { num: 4u }));
1531
+ /// assert!(map.contains_key_equiv(&EvenOrOdd { num: 1 }));
1532
+ /// assert!(!map.contains_key_equiv(&EvenOrOdd { num: 4 }));
1522
1533
///
1523
- /// assert_eq!(map.find_equiv(&EvenOrOdd { num: 5u }), Some(&"foo"));
1524
- /// assert_eq!(map.find_equiv(&EvenOrOdd { num: 2u }), None);
1534
+ /// assert_eq!(map.find_equiv(&EvenOrOdd { num: 5 }), Some(&"foo"));
1535
+ /// assert_eq!(map.find_equiv(&EvenOrOdd { num: 2 }), None);
1525
1536
///
1526
- /// assert_eq!(map.pop_equiv(&EvenOrOdd { num: 1u }), Some("foo"));
1527
- /// assert_eq!(map.pop_equiv(&EvenOrOdd { num: 2u }), None);
1537
+ /// assert_eq!(map.pop_equiv(&EvenOrOdd { num: 1 }), Some("foo"));
1538
+ /// assert_eq!(map.pop_equiv(&EvenOrOdd { num: 2 }), None);
1528
1539
///
1529
1540
/// ```
1530
1541
#[ experimental]
@@ -1545,7 +1556,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1545
1556
}
1546
1557
1547
1558
/// An iterator visiting all keys in arbitrary order.
1548
- /// Iterator element type is &'a K.
1559
+ /// Iterator element type is ` &'a K` .
1549
1560
///
1550
1561
/// # Example
1551
1562
///
@@ -1554,8 +1565,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1554
1565
///
1555
1566
/// let mut map = HashMap::new();
1556
1567
/// map.insert("a", 1i);
1557
- /// map.insert("b", 2i );
1558
- /// map.insert("c", 3i );
1568
+ /// map.insert("b", 2 );
1569
+ /// map.insert("c", 3 );
1559
1570
///
1560
1571
/// for key in map.keys() {
1561
1572
/// println!("{}", key);
@@ -1566,7 +1577,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1566
1577
}
1567
1578
1568
1579
/// An iterator visiting all values in arbitrary order.
1569
- /// Iterator element type is &'a V.
1580
+ /// Iterator element type is ` &'a V` .
1570
1581
///
1571
1582
/// # Example
1572
1583
///
@@ -1575,8 +1586,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1575
1586
///
1576
1587
/// let mut map = HashMap::new();
1577
1588
/// map.insert("a", 1i);
1578
- /// map.insert("b", 2i );
1579
- /// map.insert("c", 3i );
1589
+ /// map.insert("b", 2 );
1590
+ /// map.insert("c", 3 );
1580
1591
///
1581
1592
/// for key in map.values() {
1582
1593
/// println!("{}", key);
@@ -1587,7 +1598,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1587
1598
}
1588
1599
1589
1600
/// An iterator visiting all key-value pairs in arbitrary order.
1590
- /// Iterator element type is (&'a K, &'a V).
1601
+ /// Iterator element type is ` (&'a K, &'a V)` .
1591
1602
///
1592
1603
/// # Example
1593
1604
///
@@ -1596,8 +1607,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1596
1607
///
1597
1608
/// let mut map = HashMap::new();
1598
1609
/// map.insert("a", 1i);
1599
- /// map.insert("b", 2i );
1600
- /// map.insert("c", 3i );
1610
+ /// map.insert("b", 2 );
1611
+ /// map.insert("c", 3 );
1601
1612
///
1602
1613
/// for (key, val) in map.iter() {
1603
1614
/// println!("key: {} val: {}", key, val);
@@ -1609,7 +1620,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1609
1620
1610
1621
/// An iterator visiting all key-value pairs in arbitrary order,
1611
1622
/// with mutable references to the values.
1612
- /// Iterator element type is (&'a K, &'a mut V).
1623
+ /// Iterator element type is ` (&'a K, &'a mut V)` .
1613
1624
///
1614
1625
/// # Example
1615
1626
///
@@ -1618,8 +1629,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1618
1629
///
1619
1630
/// let mut map = HashMap::new();
1620
1631
/// map.insert("a", 1i);
1621
- /// map.insert("b", 2i );
1622
- /// map.insert("c", 3i );
1632
+ /// map.insert("b", 2 );
1633
+ /// map.insert("c", 3 );
1623
1634
///
1624
1635
/// // Update all values
1625
1636
/// for (_, val) in map.mut_iter() {
@@ -1645,8 +1656,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1645
1656
///
1646
1657
/// let mut map = HashMap::new();
1647
1658
/// map.insert("a", 1i);
1648
- /// map.insert("b", 2i );
1649
- /// map.insert("c", 3i );
1659
+ /// map.insert("b", 2 );
1660
+ /// map.insert("c", 3 );
1650
1661
///
1651
1662
/// // Not possible with .iter()
1652
1663
/// let vec: Vec<(&str, int)> = map.move_iter().collect();
@@ -1657,7 +1668,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1657
1668
}
1658
1669
1659
1670
impl < K : Eq + Hash < S > , V : Clone , S , H : Hasher < S > > HashMap < K , V , H > {
1660
- /// Like `find`, but returns a copy of the value.
1671
+ /// Return a copy of the value corresponding to the key .
1661
1672
///
1662
1673
/// # Example
1663
1674
///
@@ -1666,13 +1677,17 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
1666
1677
///
1667
1678
/// let mut map: HashMap<uint, String> = HashMap::new();
1668
1679
/// map.insert(1u, "foo".to_string());
1669
- /// let s: String = map.find_copy(&1u ).unwrap();
1680
+ /// let s: String = map.find_copy(&1 ).unwrap();
1670
1681
/// ```
1671
1682
pub fn find_copy ( & self , k : & K ) -> Option < V > {
1672
1683
self . find ( k) . map ( |v| ( * v) . clone ( ) )
1673
1684
}
1674
1685
1675
- /// Like `get`, but returns a copy of the value.
1686
+ /// Return a copy of the value corresponding to the key.
1687
+ ///
1688
+ /// # Failure
1689
+ ///
1690
+ /// Fails if the key is not present.
1676
1691
///
1677
1692
/// # Example
1678
1693
///
@@ -1681,7 +1696,7 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
1681
1696
///
1682
1697
/// let mut map: HashMap<uint, String> = HashMap::new();
1683
1698
/// map.insert(1u, "foo".to_string());
1684
- /// let s: String = map.get_copy(&1u );
1699
+ /// let s: String = map.get_copy(&1 );
1685
1700
/// ```
1686
1701
pub fn get_copy ( & self , k : & K ) -> V {
1687
1702
( * self . get ( k) ) . clone ( )
0 commit comments