Skip to content

Commit 6991938

Browse files
committed
Auto merge of #38961 - steveklabnik:fix-sort-wording, r=alexcrichton
Fix wording around sort guarantees Fixes #38524 /cc @rust-lang/libs @stjepang
2 parents df8debf + e02f923 commit 6991938

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/libcollections/slice.rs

+36-11
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,17 @@ impl<T> [T] {
10641064

10651065
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
10661066
///
1067-
/// This sort is stable and `O(n log n)` worst-case, but allocates
1068-
/// temporary storage half the size of `self`.
1067+
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1068+
///
1069+
/// # Current implementation
1070+
///
1071+
/// The current algorithm is an adaptive, iterative merge sort inspired by
1072+
/// [timsort](https://en.wikipedia.org/wiki/Timsort).
1073+
/// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1074+
/// two or more sorted sequences concatenated one after another.
1075+
///
1076+
/// Also, it allocates temporary storage half the size of `self`, but for short slices a
1077+
/// non-allocating insertion sort is used instead.
10691078
///
10701079
/// # Examples
10711080
///
@@ -1083,11 +1092,19 @@ impl<T> [T] {
10831092
self.sort_by(|a, b| a.cmp(b))
10841093
}
10851094

1086-
/// Sorts the slice, in place, using `f` to extract a key by which to
1087-
/// order the sort by.
1095+
/// Sorts the slice using `f` to extract a key to compare elements by.
1096+
///
1097+
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1098+
///
1099+
/// # Current implementation
10881100
///
1089-
/// This sort is stable and `O(n log n)` worst-case, but allocates
1090-
/// temporary storage half the size of `self`.
1101+
/// The current algorithm is an adaptive, iterative merge sort inspired by
1102+
/// [timsort](https://en.wikipedia.org/wiki/Timsort).
1103+
/// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1104+
/// two or more sorted sequences concatenated one after another.
1105+
///
1106+
/// Also, it allocates temporary storage half the size of `self`, but for short slices a
1107+
/// non-allocating insertion sort is used instead.
10911108
///
10921109
/// # Examples
10931110
///
@@ -1105,11 +1122,19 @@ impl<T> [T] {
11051122
self.sort_by(|a, b| f(a).cmp(&f(b)))
11061123
}
11071124

1108-
/// Sorts the slice, in place, using `compare` to compare
1109-
/// elements.
1125+
/// Sorts the slice using `compare` to compare elements.
1126+
///
1127+
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1128+
///
1129+
/// # Current implementation
1130+
///
1131+
/// The current algorithm is an adaptive, iterative merge sort inspired by
1132+
/// [timsort](https://en.wikipedia.org/wiki/Timsort).
1133+
/// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1134+
/// two or more sorted sequences concatenated one after another.
11101135
///
1111-
/// This sort is stable and `O(n log n)` worst-case, but allocates
1112-
/// temporary storage half the size of `self`.
1136+
/// Also, it allocates temporary storage half the size of `self`, but for short slices a
1137+
/// non-allocating insertion sort is used instead.
11131138
///
11141139
/// # Examples
11151140
///
@@ -1535,7 +1560,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
15351560

15361561
// FIXME #12092: These numbers are platform-specific and need more extensive testing/tuning.
15371562
//
1538-
// If `v` has length up to `insertion_len`, simply switch to insertion sort because it is going
1563+
// If `v` has length up to `max_insertion`, simply switch to insertion sort because it is going
15391564
// to perform better than merge sort. For bigger types `T`, the threshold is smaller.
15401565
//
15411566
// Short runs are extended using insertion sort to span at least `min_run` elements, in order

0 commit comments

Comments
 (0)