From 217e10a70c3d6681408f9eca656567e0194d918b Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Tue, 31 Dec 2024 09:46:37 -0700 Subject: [PATCH 01/13] Improve `select_nth_unstable` documentation clarity * Instead uses `before` and `after` variable names in the example where `greater` and `lesser` are flipped. * Uses `<=` and `>=` instead of "less than or equal to" and "greater than or equal to" to make the docs more concise. * General attempt to remove unnecessary words and be more precise. For example it seems slightly wrong to say "its final sorted position", since this implies there is only one sorted position for this element. --- library/core/src/slice/mod.rs | 82 +++++++++++++++++------------------ 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index df9720698d32f..abe5a5acf3bb8 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3069,19 +3069,18 @@ impl [T] { sort::unstable::sort(self, &mut |a, b| f(a).lt(&f(b))); } - /// Reorders the slice such that the element at `index` after the reordering is at its final - /// sorted position. + /// Reorders the slice such that the element at `index` is at a sort-order position. All + /// elements before `index` will then be `<=` this value, and all elements after will be `>=`. /// - /// This reordering has the additional property that any value at position `i < index` will be - /// less than or equal to any value at a position `j > index`. Additionally, this reordering is - /// unstable (i.e. any number of equal elements may end up at position `index`), in-place (i.e. - /// does not allocate), and runs in *O*(*n*) time. This function is also known as "kth element" - /// in other libraries. + /// This reordering is unstable (i.e. any element that compares equal to the nth element may end + /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This + /// function is also known as "kth element" in other libraries. + /// + /// Returns a triple partitioning the reordered slice: /// - /// It returns a triplet of the following from the reordered slice: the subslice prior to - /// `index`, the element at `index`, and the subslice after `index`; accordingly, the values in - /// those two subslices will respectively all be less-than-or-equal-to and - /// greater-than-or-equal-to the value of the element at `index`. + /// * The unsorted subslice before `index` (elements all pass `x <= self[index]`) + /// * The element at `index` + /// * The unsorted subslice after `index` (elements all pass `x >= self[index]`) /// /// # Current implementation /// @@ -3094,7 +3093,7 @@ impl [T] { /// /// # Panics /// - /// Panics when `index >= len()`, meaning it always panics on empty slices. + /// Panics when `index >= len()`, and so always panics on empty slices. /// /// May panic if the implementation of [`Ord`] for `T` does not implement a [total order]. /// @@ -3103,8 +3102,7 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 2, -3, 1]; /// - /// // Find the items less than or equal to the median, the median, and greater than or equal to - /// // the median. + /// // Find the items `<=` the median, the median, and `>=` the median. /// let (lesser, median, greater) = v.select_nth_unstable(2); /// /// assert!(lesser == [-3, -5] || lesser == [-5, -3]); @@ -3130,19 +3128,19 @@ impl [T] { sort::select::partition_at_index(self, index, T::lt) } - /// Reorders the slice with a comparator function such that the element at `index` after the - /// reordering is at its final sorted position. + /// Reorders the slice with a comparator function such that the element at `index` is at a + /// sort-order position. All elements before `index` will then be `<=` this value, and all + /// elements after will be `>=` according to the comparator function. /// - /// This reordering has the additional property that any value at position `i < index` will be - /// less than or equal to any value at a position `j > index` using the comparator function. - /// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at - /// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This + /// This reordering is unstable (i.e. any element that compares equal to the nth element may end + /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This /// function is also known as "kth element" in other libraries. /// - /// It returns a triplet of the following from the slice reordered according to the provided - /// comparator function: the subslice prior to `index`, the element at `index`, and the subslice - /// after `index`; accordingly, the values in those two subslices will respectively all be - /// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`. + /// Returns a triple partitioning the reordered slice: + /// + /// * The unsorted subslice before `index` (elements all pass `compare(x, self[index]).is_le()`) + /// * The element at `index` + /// * The unsorted subslice after `index` (elements all pass `compare(x, self[index]).is_ge()`) /// /// # Current implementation /// @@ -3155,7 +3153,7 @@ impl [T] { /// /// # Panics /// - /// Panics when `index >= len()`, meaning it always panics on empty slices. + /// Panics when `index >= len()`, and so always panics on empty slices. /// /// May panic if `compare` does not implement a [total order]. /// @@ -3164,13 +3162,13 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 2, -3, 1]; /// - /// // Find the items less than or equal to the median, the median, and greater than or equal to - /// // the median as if the slice were sorted in descending order. - /// let (lesser, median, greater) = v.select_nth_unstable_by(2, |a, b| b.cmp(a)); + /// // Find the items `>=` the median, the median, and `<=` the median, by using a reversed + /// // comparator. + /// let (before, median, after) = v.select_nth_unstable_by(2, |a, b| b.cmp(a)); /// - /// assert!(lesser == [4, 2] || lesser == [2, 4]); + /// assert!(before == [4, 2] || before == [2, 4]); /// assert_eq!(median, &mut 1); - /// assert!(greater == [-3, -5] || greater == [-5, -3]); + /// assert!(after == [-3, -5] || after == [-5, -3]); /// /// // We are only guaranteed the slice will be one of the following, based on the way we sort /// // about the specified index. @@ -3195,19 +3193,19 @@ impl [T] { sort::select::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less) } - /// Reorders the slice with a key extraction function such that the element at `index` after the - /// reordering is at its final sorted position. + /// Reorders the slice with a key extraction function such that the element at `index` is at a + /// sort-order position. All elements before `index` will have keys `<=` the key at `index`, and + /// all elements after will have keys `>=`. /// - /// This reordering has the additional property that any value at position `i < index` will be - /// less than or equal to any value at a position `j > index` using the key extraction function. - /// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at - /// position `index`), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This + /// This reordering is unstable (i.e. any element that compares equal to the nth element may end + /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This /// function is also known as "kth element" in other libraries. /// - /// It returns a triplet of the following from the slice reordered according to the provided key - /// extraction function: the subslice prior to `index`, the element at `index`, and the subslice - /// after `index`; accordingly, the values in those two subslices will respectively all be - /// less-than-or-equal-to and greater-than-or-equal-to the value of the element at `index`. + /// Returns a triple partitioning the reordered slice: + /// + /// * The unsorted subslice before `index` (elements all pass `f(x) <= f(self[index])`) + /// * The element at `index` + /// * The unsorted subslice after `index` (elements all pass `f(x) >= f(self[index])`) /// /// # Current implementation /// @@ -3229,8 +3227,8 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 1, -3, 2]; /// - /// // Find the items less than or equal to the median, the median, and greater than or equal to - /// // the median as if the slice were sorted according to absolute value. + /// // Find the items <= the median absolute value, the median absolute value, and >= the median + /// // absolute value. /// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs()); /// /// assert!(lesser == [1, 2] || lesser == [2, 1]); From 0257cfb974c2a78d96b8a3d192a61d0bdec00f39 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 14:52:16 -0700 Subject: [PATCH 02/13] `then be` -> `be` based on feedback from @ibraheemdev --- library/core/src/slice/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index abe5a5acf3bb8..03c21507aec93 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3070,7 +3070,7 @@ impl [T] { } /// Reorders the slice such that the element at `index` is at a sort-order position. All - /// elements before `index` will then be `<=` this value, and all elements after will be `>=`. + /// elements before `index` will be `<=` this value, and all elements after will be `>=`. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This @@ -3129,8 +3129,8 @@ impl [T] { } /// Reorders the slice with a comparator function such that the element at `index` is at a - /// sort-order position. All elements before `index` will then be `<=` this value, and all - /// elements after will be `>=` according to the comparator function. + /// sort-order position. All elements before `index` will be `<=` this value, and all elements + /// after will be `>=` according to the comparator function. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This From ecf68f3cd0078d3d2407d826c8338528e456c693 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:32:47 -0700 Subject: [PATCH 03/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 03c21507aec93..ecf64e9fc038d 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3129,8 +3129,8 @@ impl [T] { } /// Reorders the slice with a comparator function such that the element at `index` is at a - /// sort-order position. All elements before `index` will be `<=` this value, and all elements - /// after will be `>=` according to the comparator function. + /// sort-order position. All elements before `index` will be `<=` to this value, and all elements + /// after will be `>=` to it, according to the comparator function. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This From d39d0ecd57a835e6065bece447c37d0921ded43b Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:33:02 -0700 Subject: [PATCH 04/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index ecf64e9fc038d..1b68b8ee7d700 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3102,7 +3102,7 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 2, -3, 1]; /// - /// // Find the items `<=` the median, the median, and `>=` the median. + /// // Find the items `<=` to the median, the median itself, and the items `>=` to it. /// let (lesser, median, greater) = v.select_nth_unstable(2); /// /// assert!(lesser == [-3, -5] || lesser == [-5, -3]); From 305bd856b22fbbad7e30028d4b230d8704c00776 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:33:23 -0700 Subject: [PATCH 05/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 1b68b8ee7d700..9b82a17cd5c31 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3078,9 +3078,9 @@ impl [T] { /// /// Returns a triple partitioning the reordered slice: /// - /// * The unsorted subslice before `index` (elements all pass `x <= self[index]`) - /// * The element at `index` - /// * The unsorted subslice after `index` (elements all pass `x >= self[index]`) + /// * The unsorted subslice before `index`, whose elements all satisfy `x <= self[index]`. + /// * The element at `index`. + /// * The unsorted subslice after `index`, whose elements all satisfy `x >= self[index]`. /// /// # Current implementation /// From a506f9d21038d067825de6947a1067b3d212948d Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:33:33 -0700 Subject: [PATCH 06/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 9b82a17cd5c31..2f2bc5c559ebf 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3076,7 +3076,7 @@ impl [T] { /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This /// function is also known as "kth element" in other libraries. /// - /// Returns a triple partitioning the reordered slice: + /// Returns a triple that partitions the reordered slice: /// /// * The unsorted subslice before `index`, whose elements all satisfy `x <= self[index]`. /// * The element at `index`. From 2eef440c220a7e58d7a4fb37f8dd212d30c39a36 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:33:42 -0700 Subject: [PATCH 07/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 2f2bc5c559ebf..25a8058e89c43 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3070,7 +3070,7 @@ impl [T] { } /// Reorders the slice such that the element at `index` is at a sort-order position. All - /// elements before `index` will be `<=` this value, and all elements after will be `>=`. + /// elements before `index` will be `<=` to this value, and all elements after will be `>=` to it. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This From a3c65805adda4bbd6ab9973507119e1d36c53948 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:34:21 -0700 Subject: [PATCH 08/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 25a8058e89c43..56f4b8203a873 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3203,9 +3203,9 @@ impl [T] { /// /// Returns a triple partitioning the reordered slice: /// - /// * The unsorted subslice before `index` (elements all pass `f(x) <= f(self[index])`) - /// * The element at `index` - /// * The unsorted subslice after `index` (elements all pass `f(x) >= f(self[index])`) + /// * The unsorted subslice before `index`, whose elements all satisfy `f(x) <= f(self[index])`. + /// * The element at `index`. + /// * The unsorted subslice after `index`, whose elements all satisfy `f(x) >= f(self[index])`. /// /// # Current implementation /// From de7f1b670b31d44f36c445a90af596772c9ea51d Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:34:29 -0700 Subject: [PATCH 09/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 56f4b8203a873..3eaca01d7c46b 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3194,8 +3194,8 @@ impl [T] { } /// Reorders the slice with a key extraction function such that the element at `index` is at a - /// sort-order position. All elements before `index` will have keys `<=` the key at `index`, and - /// all elements after will have keys `>=`. + /// sort-order position. All elements before `index` will have keys `<=` to the key at `index`, and + /// all elements after will have keys `>=` to it. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This From c0aa7b5cf081fdbde2c79c0a5f2de87b81b4db50 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:35:12 -0700 Subject: [PATCH 10/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 3eaca01d7c46b..34fd78001e804 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3162,8 +3162,8 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 2, -3, 1]; /// - /// // Find the items `>=` the median, the median, and `<=` the median, by using a reversed - /// // comparator. + /// // Find the items `>=` to the median, the median itself, and the items `<=` to it, by using + /// // a reversed comparator. /// let (before, median, after) = v.select_nth_unstable_by(2, |a, b| b.cmp(a)); /// /// assert!(before == [4, 2] || before == [2, 4]); From 6ac44fa5faf20b6c1b43b6b3cefc13b5ab4b2de0 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:35:22 -0700 Subject: [PATCH 11/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 34fd78001e804..2e697f8850553 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3138,9 +3138,9 @@ impl [T] { /// /// Returns a triple partitioning the reordered slice: /// - /// * The unsorted subslice before `index` (elements all pass `compare(x, self[index]).is_le()`) - /// * The element at `index` - /// * The unsorted subslice after `index` (elements all pass `compare(x, self[index]).is_ge()`) + /// * The unsorted subslice before `index`, whose elements all satisfy `compare(x, self[index]).is_le()`. + /// * The element at `index`. + /// * The unsorted subslice after `index`, whose elements all satisfy `compare(x, self[index]).is_ge()`. /// /// # Current implementation /// From fd89cf9b8f0cc893711eea6069429e94dbd68dcc Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:35:41 -0700 Subject: [PATCH 12/13] Update library/core/src/slice/mod.rs Co-authored-by: Ibraheem Ahmed --- library/core/src/slice/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 2e697f8850553..2527036556dd1 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3227,8 +3227,7 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 1, -3, 2]; /// - /// // Find the items <= the median absolute value, the median absolute value, and >= the median - /// // absolute value. + /// // Find the items `<=` to the absolute median, the absolute median itself, and the items `>=` to it. /// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs()); /// /// assert!(lesser == [1, 2] || lesser == [2, 1]); From 3a6eea0c6aee335cce2112f6098915d458744582 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 18 Jan 2025 18:40:16 -0700 Subject: [PATCH 13/13] Rewrap following accepting review suggestions from @ibraheemdev --- library/core/src/slice/mod.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 2527036556dd1..f26a6a2d7e275 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3070,7 +3070,8 @@ impl [T] { } /// Reorders the slice such that the element at `index` is at a sort-order position. All - /// elements before `index` will be `<=` to this value, and all elements after will be `>=` to it. + /// elements before `index` will be `<=` to this value, and all elements after will be `>=` to + /// it. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This @@ -3079,7 +3080,9 @@ impl [T] { /// Returns a triple that partitions the reordered slice: /// /// * The unsorted subslice before `index`, whose elements all satisfy `x <= self[index]`. + /// /// * The element at `index`. + /// /// * The unsorted subslice after `index`, whose elements all satisfy `x >= self[index]`. /// /// # Current implementation @@ -3129,8 +3132,8 @@ impl [T] { } /// Reorders the slice with a comparator function such that the element at `index` is at a - /// sort-order position. All elements before `index` will be `<=` to this value, and all elements - /// after will be `>=` to it, according to the comparator function. + /// sort-order position. All elements before `index` will be `<=` to this value, and all + /// elements after will be `>=` to it, according to the comparator function. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This @@ -3138,9 +3141,13 @@ impl [T] { /// /// Returns a triple partitioning the reordered slice: /// - /// * The unsorted subslice before `index`, whose elements all satisfy `compare(x, self[index]).is_le()`. + /// * The unsorted subslice before `index`, whose elements all satisfy + /// `compare(x, self[index]).is_le()`. + /// /// * The element at `index`. - /// * The unsorted subslice after `index`, whose elements all satisfy `compare(x, self[index]).is_ge()`. + /// + /// * The unsorted subslice after `index`, whose elements all satisfy + /// `compare(x, self[index]).is_ge()`. /// /// # Current implementation /// @@ -3194,8 +3201,8 @@ impl [T] { } /// Reorders the slice with a key extraction function such that the element at `index` is at a - /// sort-order position. All elements before `index` will have keys `<=` to the key at `index`, and - /// all elements after will have keys `>=` to it. + /// sort-order position. All elements before `index` will have keys `<=` to the key at `index`, + /// and all elements after will have keys `>=` to it. /// /// This reordering is unstable (i.e. any element that compares equal to the nth element may end /// up at that position), in-place (i.e. does not allocate), and runs in *O*(*n*) time. This @@ -3204,7 +3211,9 @@ impl [T] { /// Returns a triple partitioning the reordered slice: /// /// * The unsorted subslice before `index`, whose elements all satisfy `f(x) <= f(self[index])`. + /// /// * The element at `index`. + /// /// * The unsorted subslice after `index`, whose elements all satisfy `f(x) >= f(self[index])`. /// /// # Current implementation @@ -3227,7 +3236,8 @@ impl [T] { /// ``` /// let mut v = [-5i32, 4, 1, -3, 2]; /// - /// // Find the items `<=` to the absolute median, the absolute median itself, and the items `>=` to it. + /// // Find the items `<=` to the absolute median, the absolute median itself, and the items + /// // `>=` to it. /// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs()); /// /// assert!(lesser == [1, 2] || lesser == [2, 1]);