@@ -3071,19 +3071,18 @@ impl<T> [T] {
3071
3071
sort:: unstable:: sort ( self , & mut |a, b| f ( a) . lt ( & f ( b) ) ) ;
3072
3072
}
3073
3073
3074
- /// Reorders the slice such that the element at `index` after the reordering is at its final
3075
- /// sorted position .
3074
+ /// Reorders the slice such that the element at `index` is at a sort-order position. All
3075
+ /// elements before `index` will then be `<=` this value, and all elements after will be `>=` .
3076
3076
///
3077
- /// This reordering has the additional property that any value at position `i < index` will be
3078
- /// less than or equal to any value at a position `j > index`. Additionally, this reordering is
3079
- /// unstable (i.e. any number of equal elements may end up at position `index`), in-place (i.e .
3080
- /// does not allocate), and runs in *O*(*n*) time. This function is also known as "kth element"
3081
- /// in other libraries.
3077
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3078
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3079
+ /// function is also known as "kth element" in other libraries .
3080
+ ///
3081
+ /// Returns a triple partitioning the reordered slice:
3082
3082
///
3083
- /// It returns a triplet of the following from the reordered slice: the subslice prior to
3084
- /// `index`, the element at `index`, and the subslice after `index`; accordingly, the values in
3085
- /// those two subslices will respectively all be less-than-or-equal-to and
3086
- /// greater-than-or-equal-to the value of the element at `index`.
3083
+ /// * The unsorted subslice before `index` (elements all pass `x <= self[index]`)
3084
+ /// * The element at `index`
3085
+ /// * The unsorted subslice after `index` (elements all pass `x >= self[index]`)
3087
3086
///
3088
3087
/// # Current implementation
3089
3088
///
@@ -3096,7 +3095,7 @@ impl<T> [T] {
3096
3095
///
3097
3096
/// # Panics
3098
3097
///
3099
- /// Panics when `index >= len()`, meaning it always panics on empty slices.
3098
+ /// Panics when `index >= len()`, and so always panics on empty slices.
3100
3099
///
3101
3100
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order].
3102
3101
///
@@ -3105,8 +3104,7 @@ impl<T> [T] {
3105
3104
/// ```
3106
3105
/// let mut v = [-5i32, 4, 2, -3, 1];
3107
3106
///
3108
- /// // Find the items less than or equal to the median, the median, and greater than or equal to
3109
- /// // the median.
3107
+ /// // Find the items `<=` the median, the median, and `>=` the median.
3110
3108
/// let (lesser, median, greater) = v.select_nth_unstable(2);
3111
3109
///
3112
3110
/// assert!(lesser == [-3, -5] || lesser == [-5, -3]);
@@ -3132,19 +3130,19 @@ impl<T> [T] {
3132
3130
sort:: select:: partition_at_index ( self , index, T :: lt)
3133
3131
}
3134
3132
3135
- /// Reorders the slice with a comparator function such that the element at `index` after the
3136
- /// reordering is at its final sorted position.
3133
+ /// Reorders the slice with a comparator function such that the element at `index` is at a
3134
+ /// sort-order position. All elements before `index` will then be `<=` this value, and all
3135
+ /// elements after will be `>=` according to the comparator function.
3137
3136
///
3138
- /// This reordering has the additional property that any value at position `i < index` will be
3139
- /// less than or equal to any value at a position `j > index` using the comparator function.
3140
- /// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
3141
- /// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3137
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3138
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3142
3139
/// function is also known as "kth element" in other libraries.
3143
3140
///
3144
- /// It returns a triplet of the following from the slice reordered according to the provided
3145
- /// comparator function: the subslice prior to `index`, the element at `index`, and the subslice
3146
- /// after `index`; accordingly, the values in those two subslices will respectively all be
3147
- /// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`.
3141
+ /// Returns a triple partitioning the reordered slice:
3142
+ ///
3143
+ /// * The unsorted subslice before `index` (elements all pass `compare(x, self[index]).is_le()`)
3144
+ /// * The element at `index`
3145
+ /// * The unsorted subslice after `index` (elements all pass `compare(x, self[index]).is_ge()`)
3148
3146
///
3149
3147
/// # Current implementation
3150
3148
///
@@ -3157,7 +3155,7 @@ impl<T> [T] {
3157
3155
///
3158
3156
/// # Panics
3159
3157
///
3160
- /// Panics when `index >= len()`, meaning it always panics on empty slices.
3158
+ /// Panics when `index >= len()`, and so always panics on empty slices.
3161
3159
///
3162
3160
/// May panic if `compare` does not implement a [total order].
3163
3161
///
@@ -3166,13 +3164,13 @@ impl<T> [T] {
3166
3164
/// ```
3167
3165
/// let mut v = [-5i32, 4, 2, -3, 1];
3168
3166
///
3169
- /// // Find the items less than or equal to the median, the median, and greater than or equal to
3170
- /// // the median as if the slice were sorted in descending order .
3171
- /// let (lesser , median, greater ) = v.select_nth_unstable_by(2, |a, b| b.cmp(a));
3167
+ /// // Find the items `>=` the median, the median, and `<=` the median, by using a reversed
3168
+ /// // comparator .
3169
+ /// let (before , median, after ) = v.select_nth_unstable_by(2, |a, b| b.cmp(a));
3172
3170
///
3173
- /// assert!(lesser == [4, 2] || lesser == [2, 4]);
3171
+ /// assert!(before == [4, 2] || before == [2, 4]);
3174
3172
/// assert_eq!(median, &mut 1);
3175
- /// assert!(greater == [-3, -5] || greater == [-5, -3]);
3173
+ /// assert!(after == [-3, -5] || after == [-5, -3]);
3176
3174
///
3177
3175
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
3178
3176
/// // about the specified index.
@@ -3197,19 +3195,19 @@ impl<T> [T] {
3197
3195
sort:: select:: partition_at_index ( self , index, |a : & T , b : & T | compare ( a, b) == Less )
3198
3196
}
3199
3197
3200
- /// Reorders the slice with a key extraction function such that the element at `index` after the
3201
- /// reordering is at its final sorted position.
3198
+ /// Reorders the slice with a key extraction function such that the element at `index` is at a
3199
+ /// sort-order position. All elements before `index` will have keys `<=` the key at `index`, and
3200
+ /// all elements after will have keys `>=`.
3202
3201
///
3203
- /// This reordering has the additional property that any value at position `i < index` will be
3204
- /// less than or equal to any value at a position `j > index` using the key extraction function.
3205
- /// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
3206
- /// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3202
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3203
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3207
3204
/// function is also known as "kth element" in other libraries.
3208
3205
///
3209
- /// It returns a triplet of the following from the slice reordered according to the provided key
3210
- /// extraction function: the subslice prior to `index`, the element at `index`, and the subslice
3211
- /// after `index`; accordingly, the values in those two subslices will respectively all be
3212
- /// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`.
3206
+ /// Returns a triple partitioning the reordered slice:
3207
+ ///
3208
+ /// * The unsorted subslice before `index` (elements all pass `f(x) <= f(self[index])`)
3209
+ /// * The element at `index`
3210
+ /// * The unsorted subslice after `index` (elements all pass `f(x) >= f(self[index])`)
3213
3211
///
3214
3212
/// # Current implementation
3215
3213
///
@@ -3231,8 +3229,8 @@ impl<T> [T] {
3231
3229
/// ```
3232
3230
/// let mut v = [-5i32, 4, 1, -3, 2];
3233
3231
///
3234
- /// // Find the items less than or equal to the median, the median , and greater than or equal to
3235
- /// // the median as if the slice were sorted according to absolute value.
3232
+ /// // Find the items <= the median absolute value, the median absolute value , and >= the median
3233
+ /// // absolute value.
3236
3234
/// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs());
3237
3235
///
3238
3236
/// assert!(lesser == [1, 2] || lesser == [2, 1]);
0 commit comments