Skip to content

Commit

Permalink
Auto merge of #38961 - steveklabnik:fix-sort-wording, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix wording around sort guarantees

Fixes #38524

/cc @rust-lang/libs @stjepang
  • Loading branch information
bors committed Jan 26, 2017
2 parents df8debf + e02f923 commit 6991938
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,17 @@ impl<T> [T] {

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

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

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

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

0 comments on commit 6991938

Please sign in to comment.