Skip to content

Commit

Permalink
improve example on inserting to a sorted vector to avoid shifting equ…
Browse files Browse the repository at this point in the history
…al elements
  • Loading branch information
andy-k committed Mar 23, 2024
1 parent c3b05c6 commit 5afe4a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// 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]);
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ impl<T> [T] {
/// ```
/// 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]);
Expand Down Expand Up @@ -4179,7 +4179,7 @@ impl<T> [T] {
/// ```
/// 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]);
/// ```
Expand Down

0 comments on commit 5afe4a9

Please sign in to comment.