From 5afe4a9e09b09b2a74cf5cbce5b69ca40b3873a9 Mon Sep 17 00:00:00 2001 From: Andy Kurnia Date: Sat, 23 Mar 2024 21:38:32 +0800 Subject: [PATCH] improve example on inserting to a sorted vector to avoid shifting equal elements --- library/alloc/src/collections/vec_deque/mod.rs | 2 +- library/core/src/slice/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 41adc2e79dc..41935a69420 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2464,7 +2464,7 @@ 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); + /// let idx = deque.partition_point(|&x| x <= num); /// // The above is equivalent to `let idx = deque.binary_search(&num).unwrap_or_else(|x| x);` /// deque.insert(idx, num); /// assert_eq!(deque, &[0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 4a574bf0347..b1ae07b05f7 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2728,7 +2728,7 @@ pub fn strip_suffix + ?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); + /// let idx = s.partition_point(|&x| x <= num); /// // The above is equivalent to `let idx = s.binary_search(&num).unwrap_or_else(|x| x);` /// s.insert(idx, num); /// assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); @@ -4179,7 +4179,7 @@ pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool /// ``` /// 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); + /// let idx = s.partition_point(|&x| x <= num); /// s.insert(idx, num); /// assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); /// ```