clarify equivalency of binary_search and partition_point
This commit is contained in:
parent
5afe4a9e09
commit
643029693b
@ -2465,7 +2465,9 @@ unsafe fn rotate_right_inner(&mut self, k: usize) {
|
||||
/// let mut deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
|
||||
/// let num = 42;
|
||||
/// let idx = deque.partition_point(|&x| x <= num);
|
||||
/// // The above is equivalent to `let idx = deque.binary_search(&num).unwrap_or_else(|x| x);`
|
||||
/// // If `num` is unique, `s.partition_point(|&x| x < num)` (with `<`) is equivalent to
|
||||
/// // `s.binary_search(&num).unwrap_or_else(|x| x)`, but using `<=` may allow `insert`
|
||||
/// // to shift less elements.
|
||||
/// deque.insert(idx, num);
|
||||
/// assert_eq!(deque, &[0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
|
||||
/// ```
|
||||
|
@ -2729,7 +2729,9 @@ pub fn strip_suffix<P: SlicePattern<Item = T> + ?Sized>(&self, suffix: &P) -> Op
|
||||
/// let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
|
||||
/// let num = 42;
|
||||
/// let idx = s.partition_point(|&x| x <= num);
|
||||
/// // The above is equivalent to `let idx = s.binary_search(&num).unwrap_or_else(|x| x);`
|
||||
/// // If `num` is unique, `s.partition_point(|&x| x < num)` (with `<`) is equivalent to
|
||||
/// // `s.binary_search(&num).unwrap_or_else(|x| x)`, but using `<=` will allow `insert`
|
||||
/// // to shift less elements.
|
||||
/// s.insert(idx, num);
|
||||
/// assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
|
||||
/// ```
|
||||
|
Loading…
Reference in New Issue
Block a user