@@ -1486,13 +1486,13 @@ where
1486
1486
/// libraries.insert("Library of Congress".to_string(), 1800);
1487
1487
///
1488
1488
/// // Get Athenæum and Bodleian Library
1489
- /// let [Some(a), Some(b)] = libraries.get_many_mut ([
1489
+ /// let [Some(a), Some(b)] = libraries.get_disjoint_mut ([
1490
1490
/// "Athenæum",
1491
1491
/// "Bodleian Library",
1492
1492
/// ]) else { panic!() };
1493
1493
///
1494
1494
/// // Assert values of Athenæum and Library of Congress
1495
- /// let got = libraries.get_many_mut ([
1495
+ /// let got = libraries.get_disjoint_mut ([
1496
1496
/// "Athenæum",
1497
1497
/// "Library of Congress",
1498
1498
/// ]);
@@ -1505,7 +1505,7 @@ where
1505
1505
/// );
1506
1506
///
1507
1507
/// // Missing keys result in None
1508
- /// let got = libraries.get_many_mut ([
1508
+ /// let got = libraries.get_disjoint_mut ([
1509
1509
/// "Athenæum",
1510
1510
/// "New York Public Library",
1511
1511
/// ]);
@@ -1525,16 +1525,26 @@ where
1525
1525
/// libraries.insert("Athenæum".to_string(), 1807);
1526
1526
///
1527
1527
/// // Duplicate keys panic!
1528
- /// let got = libraries.get_many_mut ([
1528
+ /// let got = libraries.get_disjoint_mut ([
1529
1529
/// "Athenæum",
1530
1530
/// "Athenæum",
1531
1531
/// ]);
1532
1532
/// ```
1533
+ pub fn get_disjoint_mut < Q , const N : usize > ( & mut self , ks : [ & Q ; N ] ) -> [ Option < & ' _ mut V > ; N ]
1534
+ where
1535
+ Q : Hash + Equivalent < K > + ?Sized ,
1536
+ {
1537
+ self . get_disjoint_mut_inner ( ks)
1538
+ . map ( |res| res. map ( |( _, v) | v) )
1539
+ }
1540
+
1541
+ /// Attempts to get mutable references to `N` values in the map at once.
1542
+ #[ deprecated( note = "use `get_disjoint_mut` instead" ) ]
1533
1543
pub fn get_many_mut < Q , const N : usize > ( & mut self , ks : [ & Q ; N ] ) -> [ Option < & ' _ mut V > ; N ]
1534
1544
where
1535
1545
Q : Hash + Equivalent < K > + ?Sized ,
1536
1546
{
1537
- self . get_many_mut_inner ( ks) . map ( |res| res . map ( | ( _ , v ) | v ) )
1547
+ self . get_disjoint_mut ( ks)
1538
1548
}
1539
1549
1540
1550
/// Attempts to get mutable references to `N` values in the map at once, without validating that
@@ -1543,7 +1553,7 @@ where
1543
1553
/// Returns an array of length `N` with the results of each query. `None` will be used if
1544
1554
/// the key is missing.
1545
1555
///
1546
- /// For a safe alternative see [`get_many_mut `](`HashMap::get_many_mut `).
1556
+ /// For a safe alternative see [`get_disjoint_mut `](`HashMap::get_disjoint_mut `).
1547
1557
///
1548
1558
/// # Safety
1549
1559
///
@@ -1564,13 +1574,13 @@ where
1564
1574
/// libraries.insert("Library of Congress".to_string(), 1800);
1565
1575
///
1566
1576
/// // SAFETY: The keys do not overlap.
1567
- /// let [Some(a), Some(b)] = (unsafe { libraries.get_many_unchecked_mut ([
1577
+ /// let [Some(a), Some(b)] = (unsafe { libraries.get_disjoint_unchecked_mut ([
1568
1578
/// "Athenæum",
1569
1579
/// "Bodleian Library",
1570
1580
/// ]) }) else { panic!() };
1571
1581
///
1572
1582
/// // SAFETY: The keys do not overlap.
1573
- /// let got = unsafe { libraries.get_many_unchecked_mut ([
1583
+ /// let got = unsafe { libraries.get_disjoint_unchecked_mut ([
1574
1584
/// "Athenæum",
1575
1585
/// "Library of Congress",
1576
1586
/// ]) };
@@ -1583,24 +1593,37 @@ where
1583
1593
/// );
1584
1594
///
1585
1595
/// // SAFETY: The keys do not overlap.
1586
- /// let got = unsafe { libraries.get_many_unchecked_mut ([
1596
+ /// let got = unsafe { libraries.get_disjoint_unchecked_mut ([
1587
1597
/// "Athenæum",
1588
1598
/// "New York Public Library",
1589
1599
/// ]) };
1590
1600
/// // Missing keys result in None
1591
1601
/// assert_eq!(got, [Some(&mut 1807), None]);
1592
1602
/// ```
1593
- pub unsafe fn get_many_unchecked_mut < Q , const N : usize > (
1603
+ pub unsafe fn get_disjoint_unchecked_mut < Q , const N : usize > (
1594
1604
& mut self ,
1595
1605
ks : [ & Q ; N ] ,
1596
1606
) -> [ Option < & ' _ mut V > ; N ]
1597
1607
where
1598
1608
Q : Hash + Equivalent < K > + ?Sized ,
1599
1609
{
1600
- self . get_many_unchecked_mut_inner ( ks)
1610
+ self . get_disjoint_unchecked_mut_inner ( ks)
1601
1611
. map ( |res| res. map ( |( _, v) | v) )
1602
1612
}
1603
1613
1614
+ /// Attempts to get mutable references to `N` values in the map at once, without validating that
1615
+ /// the values are unique.
1616
+ #[ deprecated( note = "use `get_disjoint_unchecked_mut` instead" ) ]
1617
+ pub unsafe fn get_many_unchecked_mut < Q , const N : usize > (
1618
+ & mut self ,
1619
+ ks : [ & Q ; N ] ,
1620
+ ) -> [ Option < & ' _ mut V > ; N ]
1621
+ where
1622
+ Q : Hash + Equivalent < K > + ?Sized ,
1623
+ {
1624
+ self . get_disjoint_unchecked_mut ( ks)
1625
+ }
1626
+
1604
1627
/// Attempts to get mutable references to `N` values in the map at once, with immutable
1605
1628
/// references to the corresponding keys.
1606
1629
///
@@ -1622,7 +1645,7 @@ where
1622
1645
/// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
1623
1646
/// libraries.insert("Library of Congress".to_string(), 1800);
1624
1647
///
1625
- /// let got = libraries.get_many_key_value_mut ([
1648
+ /// let got = libraries.get_disjoint_key_value_mut ([
1626
1649
/// "Bodleian Library",
1627
1650
/// "Herzogin-Anna-Amalia-Bibliothek",
1628
1651
/// ]);
@@ -1634,7 +1657,7 @@ where
1634
1657
/// ],
1635
1658
/// );
1636
1659
/// // Missing keys result in None
1637
- /// let got = libraries.get_many_key_value_mut ([
1660
+ /// let got = libraries.get_disjoint_key_value_mut ([
1638
1661
/// "Bodleian Library",
1639
1662
/// "Gewandhaus",
1640
1663
/// ]);
@@ -1649,30 +1672,43 @@ where
1649
1672
/// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
1650
1673
///
1651
1674
/// // Duplicate keys result in panic!
1652
- /// let got = libraries.get_many_key_value_mut ([
1675
+ /// let got = libraries.get_disjoint_key_value_mut ([
1653
1676
/// "Bodleian Library",
1654
1677
/// "Herzogin-Anna-Amalia-Bibliothek",
1655
1678
/// "Herzogin-Anna-Amalia-Bibliothek",
1656
1679
/// ]);
1657
1680
/// ```
1658
- pub fn get_many_key_value_mut < Q , const N : usize > (
1681
+ pub fn get_disjoint_key_value_mut < Q , const N : usize > (
1659
1682
& mut self ,
1660
1683
ks : [ & Q ; N ] ,
1661
1684
) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
1662
1685
where
1663
1686
Q : Hash + Equivalent < K > + ?Sized ,
1664
1687
{
1665
- self . get_many_mut_inner ( ks)
1688
+ self . get_disjoint_mut_inner ( ks)
1666
1689
. map ( |res| res. map ( |( k, v) | ( & * k, v) ) )
1667
1690
}
1668
1691
1692
+ /// Attempts to get mutable references to `N` values in the map at once, with immutable
1693
+ /// references to the corresponding keys.
1694
+ #[ deprecated( note = "use `get_disjoint_key_value_mut` instead" ) ]
1695
+ pub fn get_many_key_value_mut < Q , const N : usize > (
1696
+ & mut self ,
1697
+ ks : [ & Q ; N ] ,
1698
+ ) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
1699
+ where
1700
+ Q : Hash + Equivalent < K > + ?Sized ,
1701
+ {
1702
+ self . get_disjoint_key_value_mut ( ks)
1703
+ }
1704
+
1669
1705
/// Attempts to get mutable references to `N` values in the map at once, with immutable
1670
1706
/// references to the corresponding keys, without validating that the values are unique.
1671
1707
///
1672
1708
/// Returns an array of length `N` with the results of each query. `None` will be returned if
1673
1709
/// any of the keys are missing.
1674
1710
///
1675
- /// For a safe alternative see [`get_many_key_value_mut `](`HashMap::get_many_key_value_mut `).
1711
+ /// For a safe alternative see [`get_disjoint_key_value_mut `](`HashMap::get_disjoint_key_value_mut `).
1676
1712
///
1677
1713
/// # Safety
1678
1714
///
@@ -1692,7 +1728,7 @@ where
1692
1728
/// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
1693
1729
/// libraries.insert("Library of Congress".to_string(), 1800);
1694
1730
///
1695
- /// let got = libraries.get_many_key_value_mut ([
1731
+ /// let got = libraries.get_disjoint_key_value_mut ([
1696
1732
/// "Bodleian Library",
1697
1733
/// "Herzogin-Anna-Amalia-Bibliothek",
1698
1734
/// ]);
@@ -1704,7 +1740,7 @@ where
1704
1740
/// ],
1705
1741
/// );
1706
1742
/// // Missing keys result in None
1707
- /// let got = libraries.get_many_key_value_mut ([
1743
+ /// let got = libraries.get_disjoint_key_value_mut ([
1708
1744
/// "Bodleian Library",
1709
1745
/// "Gewandhaus",
1710
1746
/// ]);
@@ -1716,27 +1752,43 @@ where
1716
1752
/// ],
1717
1753
/// );
1718
1754
/// ```
1719
- pub unsafe fn get_many_key_value_unchecked_mut < Q , const N : usize > (
1755
+ pub unsafe fn get_disjoint_key_value_unchecked_mut < Q , const N : usize > (
1720
1756
& mut self ,
1721
1757
ks : [ & Q ; N ] ,
1722
1758
) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
1723
1759
where
1724
1760
Q : Hash + Equivalent < K > + ?Sized ,
1725
1761
{
1726
- self . get_many_unchecked_mut_inner ( ks)
1762
+ self . get_disjoint_unchecked_mut_inner ( ks)
1727
1763
. map ( |res| res. map ( |( k, v) | ( & * k, v) ) )
1728
1764
}
1729
1765
1730
- fn get_many_mut_inner < Q , const N : usize > ( & mut self , ks : [ & Q ; N ] ) -> [ Option < & ' _ mut ( K , V ) > ; N ]
1766
+ /// Attempts to get mutable references to `N` values in the map at once, with immutable
1767
+ /// references to the corresponding keys, without validating that the values are unique.
1768
+ #[ deprecated( note = "use `get_disjoint_key_value_unchecked_mut` instead" ) ]
1769
+ pub unsafe fn get_many_key_value_unchecked_mut < Q , const N : usize > (
1770
+ & mut self ,
1771
+ ks : [ & Q ; N ] ,
1772
+ ) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
1773
+ where
1774
+ Q : Hash + Equivalent < K > + ?Sized ,
1775
+ {
1776
+ self . get_disjoint_key_value_unchecked_mut ( ks)
1777
+ }
1778
+
1779
+ fn get_disjoint_mut_inner < Q , const N : usize > (
1780
+ & mut self ,
1781
+ ks : [ & Q ; N ] ,
1782
+ ) -> [ Option < & ' _ mut ( K , V ) > ; N ]
1731
1783
where
1732
1784
Q : Hash + Equivalent < K > + ?Sized ,
1733
1785
{
1734
1786
let hashes = self . build_hashes_inner ( ks) ;
1735
1787
self . table
1736
- . get_many_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
1788
+ . get_disjoint_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
1737
1789
}
1738
1790
1739
- unsafe fn get_many_unchecked_mut_inner < Q , const N : usize > (
1791
+ unsafe fn get_disjoint_unchecked_mut_inner < Q , const N : usize > (
1740
1792
& mut self ,
1741
1793
ks : [ & Q ; N ] ,
1742
1794
) -> [ Option < & ' _ mut ( K , V ) > ; N ]
@@ -1745,7 +1797,7 @@ where
1745
1797
{
1746
1798
let hashes = self . build_hashes_inner ( ks) ;
1747
1799
self . table
1748
- . get_many_unchecked_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
1800
+ . get_disjoint_unchecked_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
1749
1801
}
1750
1802
1751
1803
fn build_hashes_inner < Q , const N : usize > ( & self , ks : [ & Q ; N ] ) -> [ u64 ; N ]
@@ -6056,20 +6108,20 @@ mod test_map {
6056
6108
}
6057
6109
6058
6110
#[ test]
6059
- fn test_get_many_mut ( ) {
6111
+ fn test_get_disjoint_mut ( ) {
6060
6112
let mut map = HashMap :: new ( ) ;
6061
6113
map. insert ( "foo" . to_owned ( ) , 0 ) ;
6062
6114
map. insert ( "bar" . to_owned ( ) , 10 ) ;
6063
6115
map. insert ( "baz" . to_owned ( ) , 20 ) ;
6064
6116
map. insert ( "qux" . to_owned ( ) , 30 ) ;
6065
6117
6066
- let xs = map. get_many_mut ( [ "foo" , "qux" ] ) ;
6118
+ let xs = map. get_disjoint_mut ( [ "foo" , "qux" ] ) ;
6067
6119
assert_eq ! ( xs, [ Some ( & mut 0 ) , Some ( & mut 30 ) ] ) ;
6068
6120
6069
- let xs = map. get_many_mut ( [ "foo" , "dud" ] ) ;
6121
+ let xs = map. get_disjoint_mut ( [ "foo" , "dud" ] ) ;
6070
6122
assert_eq ! ( xs, [ Some ( & mut 0 ) , None ] ) ;
6071
6123
6072
- let ys = map. get_many_key_value_mut ( [ "bar" , "baz" ] ) ;
6124
+ let ys = map. get_disjoint_key_value_mut ( [ "bar" , "baz" ] ) ;
6073
6125
assert_eq ! (
6074
6126
ys,
6075
6127
[
@@ -6078,17 +6130,17 @@ mod test_map {
6078
6130
] ,
6079
6131
) ;
6080
6132
6081
- let ys = map. get_many_key_value_mut ( [ "bar" , "dip" ] ) ;
6133
+ let ys = map. get_disjoint_key_value_mut ( [ "bar" , "dip" ] ) ;
6082
6134
assert_eq ! ( ys, [ Some ( ( & "bar" . to_string( ) , & mut 10 ) ) , None ] ) ;
6083
6135
}
6084
6136
6085
6137
#[ test]
6086
6138
#[ should_panic = "duplicate keys found" ]
6087
- fn test_get_many_mut_duplicate ( ) {
6139
+ fn test_get_disjoint_mut_duplicate ( ) {
6088
6140
let mut map = HashMap :: new ( ) ;
6089
6141
map. insert ( "foo" . to_owned ( ) , 0 ) ;
6090
6142
6091
- let _xs = map. get_many_mut ( [ "foo" , "foo" ] ) ;
6143
+ let _xs = map. get_disjoint_mut ( [ "foo" , "foo" ] ) ;
6092
6144
}
6093
6145
6094
6146
#[ test]
0 commit comments