Skip to content

Commit a42b04c

Browse files
authored
Rollup merge of #113662 - pedroclobo:vec-deque-rotate, r=thomcc
Rename VecDeque's `rotate_left` and `rotate_right` parameters This pull request introduces a modification to the `VecDeque` collection, specifically the `rotate_left` and `rotate_right` functions, by renaming the parameter associated with these functions. The rationale behind this change is to provide clearer and more consistent naming for the parameter that specifies the number of places to rotate the double-ended queue. By using `n` as the parameter name in both functions, it becomes easier to understand and remember the purpose of the parameter.
2 parents f6dbf7d + 30a029e commit a42b04c

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,21 +2283,21 @@ impl<T, A: Allocator> VecDeque<T, A> {
22832283
unsafe { slice::from_raw_parts_mut(ptr.add(self.head), self.len) }
22842284
}
22852285

2286-
/// Rotates the double-ended queue `mid` places to the left.
2286+
/// Rotates the double-ended queue `n` places to the left.
22872287
///
22882288
/// Equivalently,
2289-
/// - Rotates item `mid` into the first position.
2290-
/// - Pops the first `mid` items and pushes them to the end.
2291-
/// - Rotates `len() - mid` places to the right.
2289+
/// - Rotates item `n` into the first position.
2290+
/// - Pops the first `n` items and pushes them to the end.
2291+
/// - Rotates `len() - n` places to the right.
22922292
///
22932293
/// # Panics
22942294
///
2295-
/// If `mid` is greater than `len()`. Note that `mid == len()`
2295+
/// If `n` is greater than `len()`. Note that `n == len()`
22962296
/// does _not_ panic and is a no-op rotation.
22972297
///
22982298
/// # Complexity
22992299
///
2300-
/// Takes `*O*(min(mid, len() - mid))` time and no extra space.
2300+
/// Takes `*O*(min(n, len() - n))` time and no extra space.
23012301
///
23022302
/// # Examples
23032303
///
@@ -2316,31 +2316,31 @@ impl<T, A: Allocator> VecDeque<T, A> {
23162316
/// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
23172317
/// ```
23182318
#[stable(feature = "vecdeque_rotate", since = "1.36.0")]
2319-
pub fn rotate_left(&mut self, mid: usize) {
2320-
assert!(mid <= self.len());
2321-
let k = self.len - mid;
2322-
if mid <= k {
2323-
unsafe { self.rotate_left_inner(mid) }
2319+
pub fn rotate_left(&mut self, n: usize) {
2320+
assert!(n <= self.len());
2321+
let k = self.len - n;
2322+
if n <= k {
2323+
unsafe { self.rotate_left_inner(n) }
23242324
} else {
23252325
unsafe { self.rotate_right_inner(k) }
23262326
}
23272327
}
23282328

2329-
/// Rotates the double-ended queue `k` places to the right.
2329+
/// Rotates the double-ended queue `n` places to the right.
23302330
///
23312331
/// Equivalently,
2332-
/// - Rotates the first item into position `k`.
2333-
/// - Pops the last `k` items and pushes them to the front.
2334-
/// - Rotates `len() - k` places to the left.
2332+
/// - Rotates the first item into position `n`.
2333+
/// - Pops the last `n` items and pushes them to the front.
2334+
/// - Rotates `len() - n` places to the left.
23352335
///
23362336
/// # Panics
23372337
///
2338-
/// If `k` is greater than `len()`. Note that `k == len()`
2338+
/// If `n` is greater than `len()`. Note that `n == len()`
23392339
/// does _not_ panic and is a no-op rotation.
23402340
///
23412341
/// # Complexity
23422342
///
2343-
/// Takes `*O*(min(k, len() - k))` time and no extra space.
2343+
/// Takes `*O*(min(n, len() - n))` time and no extra space.
23442344
///
23452345
/// # Examples
23462346
///
@@ -2359,13 +2359,13 @@ impl<T, A: Allocator> VecDeque<T, A> {
23592359
/// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
23602360
/// ```
23612361
#[stable(feature = "vecdeque_rotate", since = "1.36.0")]
2362-
pub fn rotate_right(&mut self, k: usize) {
2363-
assert!(k <= self.len());
2364-
let mid = self.len - k;
2365-
if k <= mid {
2366-
unsafe { self.rotate_right_inner(k) }
2362+
pub fn rotate_right(&mut self, n: usize) {
2363+
assert!(n <= self.len());
2364+
let k = self.len - n;
2365+
if n <= k {
2366+
unsafe { self.rotate_right_inner(n) }
23672367
} else {
2368-
unsafe { self.rotate_left_inner(mid) }
2368+
unsafe { self.rotate_left_inner(k) }
23692369
}
23702370
}
23712371

library/alloc/src/collections/vec_deque/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ fn test_rotate_left_right() {
351351
}
352352

353353
#[test]
354-
#[should_panic = "assertion failed: mid <= self.len()"]
354+
#[should_panic = "assertion failed: n <= self.len()"]
355355
fn test_rotate_left_panic() {
356356
let mut tester: VecDeque<_> = (1..=10).collect();
357357
tester.rotate_left(tester.len() + 1);
358358
}
359359

360360
#[test]
361-
#[should_panic = "assertion failed: k <= self.len()"]
361+
#[should_panic = "assertion failed: n <= self.len()"]
362362
fn test_rotate_right_panic() {
363363
let mut tester: VecDeque<_> = (1..=10).collect();
364364
tester.rotate_right(tester.len() + 1);

0 commit comments

Comments
 (0)