Skip to content

Commit ca3bed0

Browse files
committed
Improve and fix documentation for sort_by_cached_key
1 parent b430cba commit ca3bed0

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/liballoc/slice.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1353,21 +1353,25 @@ impl<T> [T] {
13531353
///
13541354
/// # Current implementation
13551355
///
1356-
/// The current algorithm is an adaptive, iterative merge sort inspired by
1357-
/// [timsort](https://en.wikipedia.org/wiki/Timsort).
1358-
/// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1359-
/// two or more sorted sequences concatenated one after another.
1356+
/// The current algorithm is based on [pattern-defeating quicksort][pdqsort] by Orson Peters,
1357+
/// which combines the fast average case of randomized quicksort with the fast worst case of
1358+
/// heapsort, while achieving linear time on slices with certain patterns. It uses some
1359+
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
1360+
/// deterministic behavior.
13601361
///
1361-
/// The algorithm allocates temporary storage in a `Vec<(K, usize)>` the length of the slice.
1362+
/// In the worst case, the algorithm allocates temporary storage in a `Vec<(K, usize)>` the
1363+
/// length of the slice.
13621364
///
13631365
/// # Examples
13641366
///
13651367
/// ```
1366-
/// let mut v = [-5i32, 4, 1, -3, 2];
1368+
/// let mut v = [-5i32, 4, 32, -3, 2];
13671369
///
1368-
/// v.sort_by_cached_key(|k| k.abs());
1369-
/// assert!(v == [1, 2, -3, 4, -5]);
1370+
/// v.sort_by_cached_key(|k| k.to_string());
1371+
/// assert!(v == [-3, -5, 2, 32, 4]);
13701372
/// ```
1373+
///
1374+
/// [pdqsort]: https://github.com/orlp/pdqsort
13711375
#[unstable(feature = "slice_sort_by_cached_key", issue = "34447")]
13721376
#[inline]
13731377
pub fn sort_by_cached_key<K, F>(&mut self, f: F)

0 commit comments

Comments
 (0)