@@ -1486,13 +1486,13 @@ where
14861486 /// libraries.insert("Library of Congress".to_string(), 1800);
14871487 ///
14881488 /// // 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 ([
14901490 /// "Athenæum",
14911491 /// "Bodleian Library",
14921492 /// ]) else { panic!() };
14931493 ///
14941494 /// // Assert values of Athenæum and Library of Congress
1495- /// let got = libraries.get_many_mut ([
1495+ /// let got = libraries.get_disjoint_mut ([
14961496 /// "Athenæum",
14971497 /// "Library of Congress",
14981498 /// ]);
@@ -1505,7 +1505,7 @@ where
15051505 /// );
15061506 ///
15071507 /// // Missing keys result in None
1508- /// let got = libraries.get_many_mut ([
1508+ /// let got = libraries.get_disjoint_mut ([
15091509 /// "Athenæum",
15101510 /// "New York Public Library",
15111511 /// ]);
@@ -1525,16 +1525,26 @@ where
15251525 /// libraries.insert("Athenæum".to_string(), 1807);
15261526 ///
15271527 /// // Duplicate keys panic!
1528- /// let got = libraries.get_many_mut ([
1528+ /// let got = libraries.get_disjoint_mut ([
15291529 /// "Athenæum",
15301530 /// "Athenæum",
15311531 /// ]);
15321532 /// ```
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" ) ]
15331543 pub fn get_many_mut < Q , const N : usize > ( & mut self , ks : [ & Q ; N ] ) -> [ Option < & ' _ mut V > ; N ]
15341544 where
15351545 Q : Hash + Equivalent < K > + ?Sized ,
15361546 {
1537- self . get_many_mut_inner ( ks) . map ( |res| res . map ( | ( _ , v ) | v ) )
1547+ self . get_disjoint_mut ( ks)
15381548 }
15391549
15401550 /// Attempts to get mutable references to `N` values in the map at once, without validating that
@@ -1543,7 +1553,7 @@ where
15431553 /// Returns an array of length `N` with the results of each query. `None` will be used if
15441554 /// the key is missing.
15451555 ///
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 `).
15471557 ///
15481558 /// # Safety
15491559 ///
@@ -1564,13 +1574,13 @@ where
15641574 /// libraries.insert("Library of Congress".to_string(), 1800);
15651575 ///
15661576 /// // 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 ([
15681578 /// "Athenæum",
15691579 /// "Bodleian Library",
15701580 /// ]) }) else { panic!() };
15711581 ///
15721582 /// // SAFETY: The keys do not overlap.
1573- /// let got = unsafe { libraries.get_many_unchecked_mut ([
1583+ /// let got = unsafe { libraries.get_disjoint_unchecked_mut ([
15741584 /// "Athenæum",
15751585 /// "Library of Congress",
15761586 /// ]) };
@@ -1583,24 +1593,37 @@ where
15831593 /// );
15841594 ///
15851595 /// // SAFETY: The keys do not overlap.
1586- /// let got = unsafe { libraries.get_many_unchecked_mut ([
1596+ /// let got = unsafe { libraries.get_disjoint_unchecked_mut ([
15871597 /// "Athenæum",
15881598 /// "New York Public Library",
15891599 /// ]) };
15901600 /// // Missing keys result in None
15911601 /// assert_eq!(got, [Some(&mut 1807), None]);
15921602 /// ```
1593- pub unsafe fn get_many_unchecked_mut < Q , const N : usize > (
1603+ pub unsafe fn get_disjoint_unchecked_mut < Q , const N : usize > (
15941604 & mut self ,
15951605 ks : [ & Q ; N ] ,
15961606 ) -> [ Option < & ' _ mut V > ; N ]
15971607 where
15981608 Q : Hash + Equivalent < K > + ?Sized ,
15991609 {
1600- self . get_many_unchecked_mut_inner ( ks)
1610+ self . get_disjoint_unchecked_mut_inner ( ks)
16011611 . map ( |res| res. map ( |( _, v) | v) )
16021612 }
16031613
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+
16041627 /// Attempts to get mutable references to `N` values in the map at once, with immutable
16051628 /// references to the corresponding keys.
16061629 ///
@@ -1622,7 +1645,7 @@ where
16221645 /// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
16231646 /// libraries.insert("Library of Congress".to_string(), 1800);
16241647 ///
1625- /// let got = libraries.get_many_key_value_mut ([
1648+ /// let got = libraries.get_disjoint_key_value_mut ([
16261649 /// "Bodleian Library",
16271650 /// "Herzogin-Anna-Amalia-Bibliothek",
16281651 /// ]);
@@ -1634,7 +1657,7 @@ where
16341657 /// ],
16351658 /// );
16361659 /// // Missing keys result in None
1637- /// let got = libraries.get_many_key_value_mut ([
1660+ /// let got = libraries.get_disjoint_key_value_mut ([
16381661 /// "Bodleian Library",
16391662 /// "Gewandhaus",
16401663 /// ]);
@@ -1649,30 +1672,43 @@ where
16491672 /// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
16501673 ///
16511674 /// // Duplicate keys result in panic!
1652- /// let got = libraries.get_many_key_value_mut ([
1675+ /// let got = libraries.get_disjoint_key_value_mut ([
16531676 /// "Bodleian Library",
16541677 /// "Herzogin-Anna-Amalia-Bibliothek",
16551678 /// "Herzogin-Anna-Amalia-Bibliothek",
16561679 /// ]);
16571680 /// ```
1658- pub fn get_many_key_value_mut < Q , const N : usize > (
1681+ pub fn get_disjoint_key_value_mut < Q , const N : usize > (
16591682 & mut self ,
16601683 ks : [ & Q ; N ] ,
16611684 ) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
16621685 where
16631686 Q : Hash + Equivalent < K > + ?Sized ,
16641687 {
1665- self . get_many_mut_inner ( ks)
1688+ self . get_disjoint_mut_inner ( ks)
16661689 . map ( |res| res. map ( |( k, v) | ( & * k, v) ) )
16671690 }
16681691
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+
16691705 /// Attempts to get mutable references to `N` values in the map at once, with immutable
16701706 /// references to the corresponding keys, without validating that the values are unique.
16711707 ///
16721708 /// Returns an array of length `N` with the results of each query. `None` will be returned if
16731709 /// any of the keys are missing.
16741710 ///
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 `).
16761712 ///
16771713 /// # Safety
16781714 ///
@@ -1692,7 +1728,7 @@ where
16921728 /// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
16931729 /// libraries.insert("Library of Congress".to_string(), 1800);
16941730 ///
1695- /// let got = libraries.get_many_key_value_mut ([
1731+ /// let got = libraries.get_disjoint_key_value_mut ([
16961732 /// "Bodleian Library",
16971733 /// "Herzogin-Anna-Amalia-Bibliothek",
16981734 /// ]);
@@ -1704,7 +1740,7 @@ where
17041740 /// ],
17051741 /// );
17061742 /// // Missing keys result in None
1707- /// let got = libraries.get_many_key_value_mut ([
1743+ /// let got = libraries.get_disjoint_key_value_mut ([
17081744 /// "Bodleian Library",
17091745 /// "Gewandhaus",
17101746 /// ]);
@@ -1716,27 +1752,43 @@ where
17161752 /// ],
17171753 /// );
17181754 /// ```
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 > (
17201756 & mut self ,
17211757 ks : [ & Q ; N ] ,
17221758 ) -> [ Option < ( & ' _ K , & ' _ mut V ) > ; N ]
17231759 where
17241760 Q : Hash + Equivalent < K > + ?Sized ,
17251761 {
1726- self . get_many_unchecked_mut_inner ( ks)
1762+ self . get_disjoint_unchecked_mut_inner ( ks)
17271763 . map ( |res| res. map ( |( k, v) | ( & * k, v) ) )
17281764 }
17291765
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 ]
17311783 where
17321784 Q : Hash + Equivalent < K > + ?Sized ,
17331785 {
17341786 let hashes = self . build_hashes_inner ( ks) ;
17351787 self . table
1736- . get_many_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
1788+ . get_disjoint_mut ( hashes, |i, ( k, _) | ks[ i] . equivalent ( k) )
17371789 }
17381790
1739- unsafe fn get_many_unchecked_mut_inner < Q , const N : usize > (
1791+ unsafe fn get_disjoint_unchecked_mut_inner < Q , const N : usize > (
17401792 & mut self ,
17411793 ks : [ & Q ; N ] ,
17421794 ) -> [ Option < & ' _ mut ( K , V ) > ; N ]
@@ -1745,7 +1797,7 @@ where
17451797 {
17461798 let hashes = self . build_hashes_inner ( ks) ;
17471799 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) )
17491801 }
17501802
17511803 fn build_hashes_inner < Q , const N : usize > ( & self , ks : [ & Q ; N ] ) -> [ u64 ; N ]
@@ -6056,20 +6108,20 @@ mod test_map {
60566108 }
60576109
60586110 #[ test]
6059- fn test_get_many_mut ( ) {
6111+ fn test_get_disjoint_mut ( ) {
60606112 let mut map = HashMap :: new ( ) ;
60616113 map. insert ( "foo" . to_owned ( ) , 0 ) ;
60626114 map. insert ( "bar" . to_owned ( ) , 10 ) ;
60636115 map. insert ( "baz" . to_owned ( ) , 20 ) ;
60646116 map. insert ( "qux" . to_owned ( ) , 30 ) ;
60656117
6066- let xs = map. get_many_mut ( [ "foo" , "qux" ] ) ;
6118+ let xs = map. get_disjoint_mut ( [ "foo" , "qux" ] ) ;
60676119 assert_eq ! ( xs, [ Some ( & mut 0 ) , Some ( & mut 30 ) ] ) ;
60686120
6069- let xs = map. get_many_mut ( [ "foo" , "dud" ] ) ;
6121+ let xs = map. get_disjoint_mut ( [ "foo" , "dud" ] ) ;
60706122 assert_eq ! ( xs, [ Some ( & mut 0 ) , None ] ) ;
60716123
6072- let ys = map. get_many_key_value_mut ( [ "bar" , "baz" ] ) ;
6124+ let ys = map. get_disjoint_key_value_mut ( [ "bar" , "baz" ] ) ;
60736125 assert_eq ! (
60746126 ys,
60756127 [
@@ -6078,17 +6130,17 @@ mod test_map {
60786130 ] ,
60796131 ) ;
60806132
6081- let ys = map. get_many_key_value_mut ( [ "bar" , "dip" ] ) ;
6133+ let ys = map. get_disjoint_key_value_mut ( [ "bar" , "dip" ] ) ;
60826134 assert_eq ! ( ys, [ Some ( ( & "bar" . to_string( ) , & mut 10 ) ) , None ] ) ;
60836135 }
60846136
60856137 #[ test]
60866138 #[ should_panic = "duplicate keys found" ]
6087- fn test_get_many_mut_duplicate ( ) {
6139+ fn test_get_disjoint_mut_duplicate ( ) {
60886140 let mut map = HashMap :: new ( ) ;
60896141 map. insert ( "foo" . to_owned ( ) , 0 ) ;
60906142
6091- let _xs = map. get_many_mut ( [ "foo" , "foo" ] ) ;
6143+ let _xs = map. get_disjoint_mut ( [ "foo" , "foo" ] ) ;
60926144 }
60936145
60946146 #[ test]
0 commit comments