Skip to content

Commit 0b18d26

Browse files
Merge #653
653: Document and test the difference between stable and unstable sorts r=jswrenn a=wainwrightmark Closes #652 Co-authored-by: Mark Wainwright <[email protected]>
2 parents c17ef69 + b1f5faa commit 0b18d26

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,8 @@ pub trait Itertools : Iterator {
25492549
/// **Note:** This consumes the entire iterator, uses the
25502550
/// [`slice::sort_unstable`] method and returns the result as a new
25512551
/// iterator that owns its elements.
2552+
///
2553+
/// This sort is unstable (i.e., may reorder equal elements).
25522554
///
25532555
/// The sorted iterator, if directly collected to a `Vec`, is converted
25542556
/// without any extra copying or allocation cost.
@@ -2578,6 +2580,8 @@ pub trait Itertools : Iterator {
25782580
/// **Note:** This consumes the entire iterator, uses the
25792581
/// [`slice::sort_unstable_by`] method and returns the result as a new
25802582
/// iterator that owns its elements.
2583+
///
2584+
/// This sort is unstable (i.e., may reorder equal elements).
25812585
///
25822586
/// The sorted iterator, if directly collected to a `Vec`, is converted
25832587
/// without any extra copying or allocation cost.
@@ -2611,6 +2615,8 @@ pub trait Itertools : Iterator {
26112615
/// **Note:** This consumes the entire iterator, uses the
26122616
/// [`slice::sort_unstable_by_key`] method and returns the result as a new
26132617
/// iterator that owns its elements.
2618+
///
2619+
/// This sort is unstable (i.e., may reorder equal elements).
26142620
///
26152621
/// The sorted iterator, if directly collected to a `Vec`, is converted
26162622
/// without any extra copying or allocation cost.
@@ -2645,6 +2651,8 @@ pub trait Itertools : Iterator {
26452651
/// **Note:** This consumes the entire iterator, uses the
26462652
/// [`slice::sort`] method and returns the result as a new
26472653
/// iterator that owns its elements.
2654+
///
2655+
/// This sort is stable (i.e., does not reorder equal elements).
26482656
///
26492657
/// The sorted iterator, if directly collected to a `Vec`, is converted
26502658
/// without any extra copying or allocation cost.
@@ -2674,6 +2682,8 @@ pub trait Itertools : Iterator {
26742682
/// **Note:** This consumes the entire iterator, uses the
26752683
/// [`slice::sort_by`] method and returns the result as a new
26762684
/// iterator that owns its elements.
2685+
///
2686+
/// This sort is stable (i.e., does not reorder equal elements).
26772687
///
26782688
/// The sorted iterator, if directly collected to a `Vec`, is converted
26792689
/// without any extra copying or allocation cost.
@@ -2682,7 +2692,7 @@ pub trait Itertools : Iterator {
26822692
/// use itertools::Itertools;
26832693
///
26842694
/// // sort people in descending order by age
2685-
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
2695+
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
26862696
///
26872697
/// let oldest_people_first = people
26882698
/// .into_iter()
@@ -2707,6 +2717,8 @@ pub trait Itertools : Iterator {
27072717
/// **Note:** This consumes the entire iterator, uses the
27082718
/// [`slice::sort_by_key`] method and returns the result as a new
27092719
/// iterator that owns its elements.
2720+
///
2721+
/// This sort is stable (i.e., does not reorder equal elements).
27102722
///
27112723
/// The sorted iterator, if directly collected to a `Vec`, is converted
27122724
/// without any extra copying or allocation cost.
@@ -2715,7 +2727,7 @@ pub trait Itertools : Iterator {
27152727
/// use itertools::Itertools;
27162728
///
27172729
/// // sort people in descending order by age
2718-
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
2730+
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
27192731
///
27202732
/// let oldest_people_first = people
27212733
/// .into_iter()
@@ -2742,6 +2754,8 @@ pub trait Itertools : Iterator {
27422754
/// **Note:** This consumes the entire iterator, uses the
27432755
/// [`slice::sort_by_cached_key`] method and returns the result as a new
27442756
/// iterator that owns its elements.
2757+
///
2758+
/// This sort is stable (i.e., does not reorder equal elements).
27452759
///
27462760
/// The sorted iterator, if directly collected to a `Vec`, is converted
27472761
/// without any extra copying or allocation cost.
@@ -2750,7 +2764,7 @@ pub trait Itertools : Iterator {
27502764
/// use itertools::Itertools;
27512765
///
27522766
/// // sort people in descending order by age
2753-
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
2767+
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
27542768
///
27552769
/// let oldest_people_first = people
27562770
/// .into_iter()

0 commit comments

Comments
 (0)