Skip to content

docs: Specify that common sort functions sort in an ascending direction #140526

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use crate::boxed::Box;
use crate::vec::Vec;

impl<T> [T] {
/// Sorts the slice, preserving initial order of equal elements.
/// Sorts the slice in ascending order, preserving initial order of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
/// worst-case.
Expand Down Expand Up @@ -137,7 +137,8 @@ impl<T> [T] {
stable_sort(self, T::lt);
}

/// Sorts the slice with a comparison function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a comparison function, preserving initial order of
/// equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
/// worst-case.
Expand Down Expand Up @@ -197,7 +198,8 @@ impl<T> [T] {
stable_sort(self, |a, b| compare(a, b) == Less);
}

/// Sorts the slice with a key extraction function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a key extraction function, preserving initial order
/// of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* \* log(*n*))
/// worst-case, where the key function is *O*(*m*).
Expand Down Expand Up @@ -252,7 +254,8 @@ impl<T> [T] {
stable_sort(self, |a, b| f(a).lt(&f(b)));
}

/// Sorts the slice with a key extraction function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a key extraction function, preserving initial order
/// of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* + *n* \*
/// log(*n*)) worst-case, where the key function is *O*(*m*).
Expand Down
10 changes: 5 additions & 5 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2986,7 +2986,7 @@ impl<T> [T] {
self.binary_search_by(|k| f(k).cmp(b))
}

/// Sorts the slice **without** preserving the initial order of equal elements.
/// Sorts the slice in ascending order **without** preserving the initial order of equal elements.
///
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
Expand Down Expand Up @@ -3047,8 +3047,8 @@ impl<T> [T] {
sort::unstable::sort(self, &mut T::lt);
}

/// Sorts the slice with a comparison function, **without** preserving the initial order of
/// equal elements.
/// Sorts the slice in ascending order with a comparison function, **without** preserving the
/// initial order of equal elements.
///
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
Expand Down Expand Up @@ -3102,8 +3102,8 @@ impl<T> [T] {
sort::unstable::sort(self, &mut |a, b| compare(a, b) == Ordering::Less);
}

/// Sorts the slice with a key extraction function, **without** preserving the initial order of
/// equal elements.
/// Sorts the slice in ascending order with a key extraction function, **without** preserving
/// the initial order of equal elements.
///
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
Expand Down
Loading