@@ -3071,19 +3071,21 @@ 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 be `<=` to this value, and all elements after will be `>=` to
3076
+ /// it.
3076
3077
///
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.
3078
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3079
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3080
+ /// function is also known as "kth element" in other libraries.
3081
+ ///
3082
+ /// Returns a triple that partitions the reordered slice:
3083
+ ///
3084
+ /// * The unsorted subslice before `index`, whose elements all satisfy `x <= self[index]`.
3082
3085
///
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`.
3086
+ /// * The element at `index`.
3087
+ ///
3088
+ /// * The unsorted subslice after `index`, whose elements all satisfy `x >= self[index]`.
3087
3089
///
3088
3090
/// # Current implementation
3089
3091
///
@@ -3096,7 +3098,7 @@ impl<T> [T] {
3096
3098
///
3097
3099
/// # Panics
3098
3100
///
3099
- /// Panics when `index >= len()`, meaning it always panics on empty slices.
3101
+ /// Panics when `index >= len()`, and so always panics on empty slices.
3100
3102
///
3101
3103
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order].
3102
3104
///
@@ -3105,8 +3107,7 @@ impl<T> [T] {
3105
3107
/// ```
3106
3108
/// let mut v = [-5i32, 4, 2, -3, 1];
3107
3109
///
3108
- /// // Find the items less than or equal to the median, the median, and greater than or equal to
3109
- /// // the median.
3110
+ /// // Find the items `<=` to the median, the median itself, and the items `>=` to it.
3110
3111
/// let (lesser, median, greater) = v.select_nth_unstable(2);
3111
3112
///
3112
3113
/// assert!(lesser == [-3, -5] || lesser == [-5, -3]);
@@ -3132,19 +3133,23 @@ impl<T> [T] {
3132
3133
sort:: select:: partition_at_index ( self , index, T :: lt)
3133
3134
}
3134
3135
3135
- /// Reorders the slice with a comparator function such that the element at `index` after the
3136
- /// reordering is at its final sorted position.
3136
+ /// Reorders the slice with a comparator function such that the element at `index` is at a
3137
+ /// sort-order position. All elements before `index` will be `<=` to this value, and all
3138
+ /// elements after will be `>=` to it, according to the comparator function.
3137
3139
///
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
3140
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3141
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3142
3142
/// function is also known as "kth element" in other libraries.
3143
3143
///
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`.
3144
+ /// Returns a triple partitioning the reordered slice:
3145
+ ///
3146
+ /// * The unsorted subslice before `index`, whose elements all satisfy
3147
+ /// `compare(x, self[index]).is_le()`.
3148
+ ///
3149
+ /// * The element at `index`.
3150
+ ///
3151
+ /// * The unsorted subslice after `index`, whose elements all satisfy
3152
+ /// `compare(x, self[index]).is_ge()`.
3148
3153
///
3149
3154
/// # Current implementation
3150
3155
///
@@ -3157,7 +3162,7 @@ impl<T> [T] {
3157
3162
///
3158
3163
/// # Panics
3159
3164
///
3160
- /// Panics when `index >= len()`, meaning it always panics on empty slices.
3165
+ /// Panics when `index >= len()`, and so always panics on empty slices.
3161
3166
///
3162
3167
/// May panic if `compare` does not implement a [total order].
3163
3168
///
@@ -3166,13 +3171,13 @@ impl<T> [T] {
3166
3171
/// ```
3167
3172
/// let mut v = [-5i32, 4, 2, -3, 1];
3168
3173
///
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));
3174
+ /// // Find the items `>=` to the median, the median itself , and the items `<=` to it, by using
3175
+ /// // a reversed comparator .
3176
+ /// let (before , median, after ) = v.select_nth_unstable_by(2, |a, b| b.cmp(a));
3172
3177
///
3173
- /// assert!(lesser == [4, 2] || lesser == [2, 4]);
3178
+ /// assert!(before == [4, 2] || before == [2, 4]);
3174
3179
/// assert_eq!(median, &mut 1);
3175
- /// assert!(greater == [-3, -5] || greater == [-5, -3]);
3180
+ /// assert!(after == [-3, -5] || after == [-5, -3]);
3176
3181
///
3177
3182
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
3178
3183
/// // about the specified index.
@@ -3197,19 +3202,21 @@ impl<T> [T] {
3197
3202
sort:: select:: partition_at_index ( self , index, |a : & T , b : & T | compare ( a, b) == Less )
3198
3203
}
3199
3204
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.
3205
+ /// Reorders the slice with a key extraction function such that the element at `index` is at a
3206
+ /// sort-order position. All elements before `index` will have keys `<=` to the key at `index`,
3207
+ /// and all elements after will have keys `>=` to it.
3202
3208
///
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
3209
+ /// This reordering is unstable (i.e. any element that compares equal to the nth element may end
3210
+ /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This
3207
3211
/// function is also known as "kth element" in other libraries.
3208
3212
///
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`.
3213
+ /// Returns a triple partitioning the reordered slice:
3214
+ ///
3215
+ /// * The unsorted subslice before `index`, whose elements all satisfy `f(x) <= f(self[index])`.
3216
+ ///
3217
+ /// * The element at `index`.
3218
+ ///
3219
+ /// * The unsorted subslice after `index`, whose elements all satisfy `f(x) >= f(self[index])`.
3213
3220
///
3214
3221
/// # Current implementation
3215
3222
///
@@ -3231,8 +3238,8 @@ impl<T> [T] {
3231
3238
/// ```
3232
3239
/// let mut v = [-5i32, 4, 1, -3, 2];
3233
3240
///
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 .
3241
+ /// // Find the items `<=` to the absolute median, the absolute median itself , and the items
3242
+ /// // `>=` to it .
3236
3243
/// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs());
3237
3244
///
3238
3245
/// assert!(lesser == [1, 2] || lesser == [2, 1]);
0 commit comments