Repository navigation
Tracking issue for VecDeque::rotate_{left|right} (feature vecdeque_rotate) #56686
Copy link
Copy link
Closed
Closed
Copy link
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Currently if you want to rotate a VecDeque n elements to the left or right, you'd have to write something like this:
use std::collections::VecDeque;
fn main() {
let mut v = (0..10).collect::<VecDeque<_>>();
println!("{:?}", v); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// rotate left by 2,
for _ in 0..2 {
if let Some(popped_front) = v.pop_front() {
v.push_back(popped_front);
}
}
println!("{:?}", v); // [2, 3, 4, 5, 6, 7, 8, 9, 0, 1]
// rotate right by 4
for _ in 0..4 {
if let Some(popped_back) = v.pop_back() {
v.push_front(popped_back);
}
}
println!("{:?}", v); //[8, 9, 0, 1, 2, 3, 4, 5, 6, 7]
}I wonder if it would be possible to add 2 functions:
- rotate_left(mid: usize)
- rotate_right(mid: usize)
You then only have to write:
use std::collections::VecDeque;
fn main() {
let mut v = (0..10).collect::<VecDeque<_>>();
println!("{:?}", v); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// rotate left by 2,
v.rotate_left(2)
println!("{:?}", v); // [2, 3, 4, 5, 6, 7, 8, 9, 0, 1]
// rotate right by 4
v.rotate_right(4);
println!("{:?}", v); //[8, 9, 0, 1, 2, 3, 4, 5, 6, 7]
}This would be equal to slice's rotate_left and rotate_right.
It could probably be implemented on a lower level than with pop's and pushes for a little more efficiency.
Reacted by Jeff VanDyke
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
scottmcm commentedon Dec 15, 2018
Ooh, I like this --
VecDequeis a circular buffer internally, so it should be doable withjust a singleat most twoptr::copy. EDIT: PR #56842[-]VecDeque rotation[/-][+]Tracking issue for VecDeque::rotate_{left|right} (feature vecdeque_rotate)[/+]scottmcm commentedon Dec 20, 2018
PR is r+'d, so I turned this into a tracking issue.
Rollup merge of rust-lang#56842 - scottmcm:vecdeque-rotate, r=alexcri…
Rollup merge of rust-lang#56842 - scottmcm:vecdeque-rotate, r=alexcri…
Rollup merge of rust-lang#56842 - scottmcm:vecdeque-rotate, r=alexcri…
Auto merge of #56842 - scottmcm:vecdeque-rotate, r=alexcrichton
DutchGhost commentedon Apr 17, 2019
I've since the feature replaced any code that used the pop - push technique with the rotate methods. This was fairly easy to do.
It's been a few months now, are there any issue's preventing this from landing stable?
1 remaining item
rfcbot commentedon May 1, 2019
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
rfcbot commentedon May 8, 2019
🔔 This is now entering its final comment period, as per the review above. 🔔
WiSaGaN commentedon May 14, 2019
Is "left" or "right" the word we want to use here? Previously we have deprecated
trim_left(trim_right) ofStringin favor oftrim_startandtrim_endso that we do not assume the string is laid out from left to right. Here we seem to assumeleftis tofrontwhilerightis toback? Are we able to use some words that express thefrontandbackwithout assuming a left-to-right layout?DutchGhost commentedon May 14, 2019
As discussed here, we have to use those names to stay consistent with the slice rotate_{left |right} methods #56842 (comment)
WiSaGaN commentedon May 14, 2019
@DutchGhost , sorry I missed that. That makes sense.
rfcbot commentedon May 18, 2019
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
The RFC will be merged soon.
Rollup merge of rust-lang#60678 - DutchGhost:master, r=scottmcm