Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and test the difference between stable and unstable sorts #653

Merged
merged 2 commits into from Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/lib.rs
Expand Up @@ -2512,6 +2512,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_unstable`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is unstable (i.e., may reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand Down Expand Up @@ -2541,6 +2543,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_unstable_by`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is unstable (i.e., may reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand Down Expand Up @@ -2574,6 +2578,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_unstable_by_key`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is unstable (i.e., may reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand Down Expand Up @@ -2608,6 +2614,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is stable (i.e., does not reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand Down Expand Up @@ -2637,6 +2645,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_by`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is stable (i.e., does not reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand All @@ -2645,7 +2655,7 @@ pub trait Itertools : Iterator {
/// use itertools::Itertools;
///
/// // sort people in descending order by age
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
///
/// let oldest_people_first = people
/// .into_iter()
Expand All @@ -2670,6 +2680,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_by_key`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is stable (i.e., does not reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand All @@ -2678,7 +2690,7 @@ pub trait Itertools : Iterator {
/// use itertools::Itertools;
///
/// // sort people in descending order by age
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
///
/// let oldest_people_first = people
/// .into_iter()
Expand All @@ -2705,6 +2717,8 @@ pub trait Itertools : Iterator {
/// **Note:** This consumes the entire iterator, uses the
/// [`slice::sort_by_cached_key`] method and returns the result as a new
/// iterator that owns its elements.
///
/// This sort is stable (i.e., does not reorder equal elements).
///
/// The sorted iterator, if directly collected to a `Vec`, is converted
/// without any extra copying or allocation cost.
Expand All @@ -2713,7 +2727,7 @@ pub trait Itertools : Iterator {
/// use itertools::Itertools;
///
/// // sort people in descending order by age
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 27)];
/// let people = vec![("Jane", 20), ("John", 18), ("Jill", 30), ("Jack", 30)];
///
/// let oldest_people_first = people
/// .into_iter()
Expand Down