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