-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve select_nth_unstable
documentation clarity
#134976
Merged
bors
merged 13 commits into
rust-lang:master
from
mgsloan:improve-select-nth-unstable-docs
Jan 19, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
217e10a
Improve `select_nth_unstable` documentation clarity
mgsloan 0257cfb
`then be` -> `be` based on feedback from @ibraheemdev
mgsloan ecf68f3
Update library/core/src/slice/mod.rs
mgsloan d39d0ec
Update library/core/src/slice/mod.rs
mgsloan 305bd85
Update library/core/src/slice/mod.rs
mgsloan a506f9d
Update library/core/src/slice/mod.rs
mgsloan 2eef440
Update library/core/src/slice/mod.rs
mgsloan a3c6580
Update library/core/src/slice/mod.rs
mgsloan de7f1b6
Update library/core/src/slice/mod.rs
mgsloan c0aa7b5
Update library/core/src/slice/mod.rs
mgsloan 6ac44fa
Update library/core/src/slice/mod.rs
mgsloan fd89cf9
Update library/core/src/slice/mod.rs
mgsloan 3a6eea0
Rewrap following accepting review suggestions from @ibraheemdev
mgsloan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3069,19 +3069,21 @@ impl<T> [T] { | |||||
sort::unstable::sort(self, &mut |a, b| f(a).lt(&f(b))); | ||||||
} | ||||||
|
||||||
/// Reorders the slice such that the element at `index` after the reordering is at its final | ||||||
/// sorted position. | ||||||
/// Reorders the slice such that the element at `index` is at a sort-order position. All | ||||||
/// elements before `index` will be `<=` to this value, and all elements after will be `>=` to | ||||||
/// it. | ||||||
/// | ||||||
/// This reordering has the additional property that any value at position `i < index` will be | ||||||
/// less than or equal to any value at a position `j > index`. Additionally, this reordering is | ||||||
/// unstable (i.e. any number of equal elements may end up at position `index`), in-place (i.e. | ||||||
/// does not allocate), and runs in *O*(*n*) time. This function is also known as "kth element" | ||||||
/// in other libraries. | ||||||
/// This reordering is unstable (i.e. any element that compares equal to the nth element may end | ||||||
/// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This | ||||||
/// function is also known as "kth element" in other libraries. | ||||||
/// | ||||||
/// Returns a triple that partitions the reordered slice: | ||||||
/// | ||||||
/// * The unsorted subslice before `index`, whose elements all satisfy `x <= self[index]`. | ||||||
/// | ||||||
/// It returns a triplet of the following from the reordered slice: the subslice prior to | ||||||
/// `index`, the element at `index`, and the subslice after `index`; accordingly, the values in | ||||||
/// those two subslices will respectively all be less-than-or-equal-to and | ||||||
/// greater-than-or-equal-to the value of the element at `index`. | ||||||
/// * The element at `index`. | ||||||
/// | ||||||
/// * The unsorted subslice after `index`, whose elements all satisfy `x >= self[index]`. | ||||||
/// | ||||||
/// # Current implementation | ||||||
/// | ||||||
|
@@ -3094,7 +3096,7 @@ impl<T> [T] { | |||||
/// | ||||||
/// # Panics | ||||||
/// | ||||||
/// Panics when `index >= len()`, meaning it always panics on empty slices. | ||||||
/// Panics when `index >= len()`, and so always panics on empty slices. | ||||||
/// | ||||||
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order]. | ||||||
/// | ||||||
|
@@ -3103,8 +3105,7 @@ impl<T> [T] { | |||||
/// ``` | ||||||
/// let mut v = [-5i32, 4, 2, -3, 1]; | ||||||
/// | ||||||
/// // Find the items less than or equal to the median, the median, and greater than or equal to | ||||||
/// // the median. | ||||||
/// // Find the items `<=` to the median, the median itself, and the items `>=` to it. | ||||||
/// let (lesser, median, greater) = v.select_nth_unstable(2); | ||||||
/// | ||||||
/// assert!(lesser == [-3, -5] || lesser == [-5, -3]); | ||||||
|
@@ -3130,19 +3131,23 @@ impl<T> [T] { | |||||
sort::select::partition_at_index(self, index, T::lt) | ||||||
} | ||||||
|
||||||
/// Reorders the slice with a comparator function such that the element at `index` after the | ||||||
/// reordering is at its final sorted position. | ||||||
/// Reorders the slice with a comparator function such that the element at `index` is at a | ||||||
/// sort-order position. All elements before `index` will be `<=` to this value, and all | ||||||
/// elements after will be `>=` to it, according to the comparator function. | ||||||
/// | ||||||
/// This reordering has the additional property that any value at position `i < index` will be | ||||||
/// less than or equal to any value at a position `j > index` using the comparator function. | ||||||
/// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at | ||||||
/// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This | ||||||
/// This reordering is unstable (i.e. any element that compares equal to the nth element may end | ||||||
/// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This | ||||||
/// function is also known as "kth element" in other libraries. | ||||||
/// | ||||||
/// It returns a triplet of the following from the slice reordered according to the provided | ||||||
/// comparator function: the subslice prior to `index`, the element at `index`, and the subslice | ||||||
/// after `index`; accordingly, the values in those two subslices will respectively all be | ||||||
/// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`. | ||||||
/// Returns a triple partitioning the reordered slice: | ||||||
/// | ||||||
/// * The unsorted subslice before `index`, whose elements all satisfy | ||||||
/// `compare(x, self[index]).is_le()`. | ||||||
/// | ||||||
/// * The element at `index`. | ||||||
/// | ||||||
/// * The unsorted subslice after `index`, whose elements all satisfy | ||||||
/// `compare(x, self[index]).is_ge()`. | ||||||
/// | ||||||
/// # Current implementation | ||||||
/// | ||||||
|
@@ -3155,7 +3160,7 @@ impl<T> [T] { | |||||
/// | ||||||
/// # Panics | ||||||
/// | ||||||
/// Panics when `index >= len()`, meaning it always panics on empty slices. | ||||||
/// Panics when `index >= len()`, and so always panics on empty slices. | ||||||
/// | ||||||
/// May panic if `compare` does not implement a [total order]. | ||||||
/// | ||||||
|
@@ -3164,13 +3169,13 @@ impl<T> [T] { | |||||
/// ``` | ||||||
/// let mut v = [-5i32, 4, 2, -3, 1]; | ||||||
/// | ||||||
/// // Find the items less than or equal to the median, the median, and greater than or equal to | ||||||
/// // the median as if the slice were sorted in descending order. | ||||||
/// let (lesser, median, greater) = v.select_nth_unstable_by(2, |a, b| b.cmp(a)); | ||||||
/// // Find the items `>=` to the median, the median itself, and the items `<=` to it, by using | ||||||
/// // a reversed comparator. | ||||||
/// let (before, median, after) = v.select_nth_unstable_by(2, |a, b| b.cmp(a)); | ||||||
/// | ||||||
/// assert!(lesser == [4, 2] || lesser == [2, 4]); | ||||||
/// assert!(before == [4, 2] || before == [2, 4]); | ||||||
/// assert_eq!(median, &mut 1); | ||||||
/// assert!(greater == [-3, -5] || greater == [-5, -3]); | ||||||
/// assert!(after == [-3, -5] || after == [-5, -3]); | ||||||
/// | ||||||
/// // We are only guaranteed the slice will be one of the following, based on the way we sort | ||||||
/// // about the specified index. | ||||||
|
@@ -3195,19 +3200,21 @@ impl<T> [T] { | |||||
sort::select::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less) | ||||||
} | ||||||
|
||||||
/// Reorders the slice with a key extraction function such that the element at `index` after the | ||||||
/// reordering is at its final sorted position. | ||||||
/// Reorders the slice with a key extraction function such that the element at `index` is at a | ||||||
/// sort-order position. All elements before `index` will have keys `<=` to the key at `index`, | ||||||
/// and all elements after will have keys `>=` to it. | ||||||
/// | ||||||
/// This reordering has the additional property that any value at position `i < index` will be | ||||||
/// less than or equal to any value at a position `j > index` using the key extraction function. | ||||||
/// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at | ||||||
/// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This | ||||||
/// This reordering is unstable (i.e. any element that compares equal to the nth element may end | ||||||
/// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This | ||||||
/// function is also known as "kth element" in other libraries. | ||||||
/// | ||||||
/// It returns a triplet of the following from the slice reordered according to the provided key | ||||||
/// extraction function: the subslice prior to `index`, the element at `index`, and the subslice | ||||||
/// after `index`; accordingly, the values in those two subslices will respectively all be | ||||||
/// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`. | ||||||
/// Returns a triple partitioning the reordered slice: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// | ||||||
/// * The unsorted subslice before `index`, whose elements all satisfy `f(x) <= f(self[index])`. | ||||||
/// | ||||||
/// * The element at `index`. | ||||||
/// | ||||||
/// * The unsorted subslice after `index`, whose elements all satisfy `f(x) >= f(self[index])`. | ||||||
/// | ||||||
/// # Current implementation | ||||||
/// | ||||||
|
@@ -3229,8 +3236,8 @@ impl<T> [T] { | |||||
/// ``` | ||||||
/// let mut v = [-5i32, 4, 1, -3, 2]; | ||||||
/// | ||||||
/// // Find the items less than or equal to the median, the median, and greater than or equal to | ||||||
/// // the median as if the slice were sorted according to absolute value. | ||||||
/// // Find the items `<=` to the absolute median, the absolute median itself, and the items | ||||||
/// // `>=` to it. | ||||||
/// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs()); | ||||||
/// | ||||||
/// assert!(lesser == [1, 2] || lesser == [2, 1]); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.