Add examples to document the return type of select_nth_unstable, select_nth_unstable_by, and select_nth_unstable_by_key.
This commit is contained in:
@@ -3016,8 +3016,13 @@ impl<T> [T] {
|
|||||||
/// ```
|
/// ```
|
||||||
/// let mut v = [-5i32, 4, 2, -3, 1];
|
/// let mut v = [-5i32, 4, 2, -3, 1];
|
||||||
///
|
///
|
||||||
/// // Find the median
|
/// // Find the items less than or equal to the median, the median, and greater than or equal to
|
||||||
/// v.select_nth_unstable(2);
|
/// // the median.
|
||||||
|
/// let (lesser, median, greater) = v.select_nth_unstable(2);
|
||||||
|
///
|
||||||
|
/// assert!(lesser == [-3, -5] || lesser == [-5, -3]);
|
||||||
|
/// assert_eq!(median, &mut 1);
|
||||||
|
/// assert!(greater == [4, 2] || greater == [2, 4]);
|
||||||
///
|
///
|
||||||
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
||||||
/// // about the specified index.
|
/// // about the specified index.
|
||||||
@@ -3067,8 +3072,13 @@ impl<T> [T] {
|
|||||||
/// ```
|
/// ```
|
||||||
/// let mut v = [-5i32, 4, 2, -3, 1];
|
/// let mut v = [-5i32, 4, 2, -3, 1];
|
||||||
///
|
///
|
||||||
/// // Find the median as if the slice were sorted in descending order.
|
/// // Find the items less than or equal to the median, the median, and greater than or equal to
|
||||||
/// v.select_nth_unstable_by(2, |a, b| b.cmp(a));
|
/// // 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));
|
||||||
|
///
|
||||||
|
/// assert!(lesser == [4, 2] || lesser == [2, 4]);
|
||||||
|
/// assert_eq!(median, &mut 1);
|
||||||
|
/// assert!(greater == [-3, -5] || greater == [-5, -3]);
|
||||||
///
|
///
|
||||||
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
||||||
/// // about the specified index.
|
/// // about the specified index.
|
||||||
@@ -3122,8 +3132,13 @@ impl<T> [T] {
|
|||||||
/// ```
|
/// ```
|
||||||
/// let mut v = [-5i32, 4, 1, -3, 2];
|
/// let mut v = [-5i32, 4, 1, -3, 2];
|
||||||
///
|
///
|
||||||
/// // Return the median as if the array were sorted according to absolute value.
|
/// // Find the items less than or equal to the median, the median, and greater than or equal to
|
||||||
/// v.select_nth_unstable_by_key(2, |a| a.abs());
|
/// // the median as if the slice were sorted according to absolute value.
|
||||||
|
/// let (lesser, median, greater) = v.select_nth_unstable_by_key(2, |a| a.abs());
|
||||||
|
///
|
||||||
|
/// assert!(lesser == [1, 2] || lesser == [2, 1]);
|
||||||
|
/// assert_eq!(median, &mut -3);
|
||||||
|
/// assert!(greater == [4, -5] || greater == [-5, 4]);
|
||||||
///
|
///
|
||||||
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
/// // We are only guaranteed the slice will be one of the following, based on the way we sort
|
||||||
/// // about the specified index.
|
/// // about the specified index.
|
||||||
|
|||||||
Reference in New Issue
Block a user