@@ -669,18 +669,18 @@ where
669669
670670 /// Sort the map’s key-value pairs by the default ordering of the keys.
671671 ///
672- /// See `sort_by` for details.
672+ /// See [ `sort_by`](Self::sort_by) for details.
673673 pub fn sort_keys ( & mut self )
674674 where
675675 K : Ord ,
676676 {
677- self . with_entries ( |entries| {
678- entries. sort_by ( |a, b| Ord :: cmp ( & a. key , & b. key ) ) ;
677+ self . with_entries ( move |entries| {
678+ entries. sort_by ( move |a, b| K :: cmp ( & a. key , & b. key ) ) ;
679679 } ) ;
680680 }
681681
682682 /// Sort the map’s key-value pairs in place using the comparison
683- /// function `compare `.
683+ /// function `cmp `.
684684 ///
685685 /// The comparison function receives two key and value pairs to compare (you
686686 /// can sort by keys or values or their combination as needed).
@@ -696,7 +696,7 @@ where
696696 } ) ;
697697 }
698698
699- /// Sort the key-value pairs of the map and return a by value iterator of
699+ /// Sort the key-value pairs of the map and return a by- value iterator of
700700 /// the key-value pairs with the result.
701701 ///
702702 /// The sort is stable.
@@ -711,6 +711,52 @@ where
711711 }
712712 }
713713
714+ /// Sort the map's key-value pairs by the default ordering of the keys, but
715+ /// may not preserve the order of equal elements.
716+ ///
717+ /// See [`sort_unstable_by`](Self::sort_unstable_by) for details.
718+ pub fn sort_unstable_keys ( & mut self )
719+ where
720+ K : Ord ,
721+ {
722+ self . with_entries ( move |entries| {
723+ entries. sort_unstable_by ( move |a, b| K :: cmp ( & a. key , & b. key ) ) ;
724+ } ) ;
725+ }
726+
727+ /// Sort the map's key-value pairs in place using the comparison function `cmp`, but
728+ /// may not preserve the order of equal elements.
729+ ///
730+ /// The comparison function receives two key and value pairs to compare (you
731+ /// can sort by keys or values or their combination as needed).
732+ ///
733+ /// Computes in **O(n log n + c)** time where *n* is
734+ /// the length of the map and *c* is the capacity. The sort is unstable.
735+ pub fn sort_unstable_by < F > ( & mut self , mut cmp : F )
736+ where
737+ F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
738+ {
739+ self . with_entries ( move |entries| {
740+ entries. sort_unstable_by ( move |a, b| cmp ( & a. key , & a. value , & b. key , & b. value ) ) ;
741+ } ) ;
742+ }
743+
744+ /// Sort the key-value pairs of the map and return a by-value iterator of
745+ /// the key-value pairs with the result.
746+ ///
747+ /// The sort is unstable.
748+ #[ inline]
749+ pub fn sorted_unstable_by < F > ( self , mut cmp : F ) -> IntoIter < K , V >
750+ where
751+ F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
752+ {
753+ let mut entries = self . into_entries ( ) ;
754+ entries. sort_unstable_by ( move |a, b| cmp ( & a. key , & a. value , & b. key , & b. value ) ) ;
755+ IntoIter {
756+ iter : entries. into_iter ( ) ,
757+ }
758+ }
759+
714760 /// Reverses the order of the map’s key-value pairs in place.
715761 ///
716762 /// Computes in **O(n)** time and **O(1)** space.
0 commit comments