You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VecDeque should support splice / extend_front #69939
VecDeque should support splice for convenience.
(SliceDeque supports it, but it doesn't build on wasm and seems kind of abandoned (several unmerged PRs with no updates).)
VecDeque should also support extend_front (like repeated push_front from an iterator. Compared to calling q.splice(..0, iter), the elements added with q.extend_front(iter) would be in reverse order).
Reacted by kangalio, Lucas Werkmeister, Bryan Ngo, cynecx, puuuuh, James0124, zopsicle, Juan Campa, Dixon Sean Low Yan Feng, Vélimir Chakhnovski and 8 more
I had to switch over to using a Vec because I couldn't efficiently insert multiple items into a VecDeque. Having a splice method would've been really useful. If I can find some time these days, I might be able to work on a PR.
Sorry for the late response, apparently I don't get GitHub notification via email.
TBH, I thought it will be easier. The unsafe code needed kinda scared me, and I got a job 4 days after claiming this.
I'll try to revisit it now, but will probably look for a mentor/guidance.
Reacted by James0124, Boscop, zopsicle, Dixon Sean Low Yan Feng, Vélimir Chakhnovski, Chris de Claverie, david072, mounir-khaled, Quentin VIGNAUD and interlaken
Hi, I just found out I'm encountering a case where prepend() and/or extend_front() methods on VecDeque could be really useful.
I'm doing the work by iterating over other vector and push_front repeatedly, but that feels not idiomatic and I guess not optimal at all.
If no one is available for this I might take a look at some point.
+1 for implementing this. Repeatedly calling push_front has a significant performance impact for my use-case, so I ended-up hacking something together on top of a Vec.
Reacted by James0124, Mads Ahlquist Jensen and Nathan Bustamante
For the simple case of trying to avoid repeated shifts on insert into the middle, the following should add only O(2n+m) to the complexity of extend(), where n is length pre-insert and m is length of iter.
use std::collections::VecDeque;traitVecDequeExt<T>{fninsert_iter<I>(&mutself,index:usize,iter:I)whereI:IntoIterator<Item = T>;}impl<T>VecDequeExt<T>forVecDeque<T>{fninsert_iter<I>(&mutself,index:usize,iter:I)whereI:IntoIterator<Item = T>{let n = self.len() - index;self.rotate_right(n);self.extend(iter);self.rotate_left(n);}}fnmain(){letmut deque = VecDeque::new();
deque.push_back(0);
deque.push_back(1);
deque.push_back(4);
deque.push_back(5);
deque.insert_iter(2,vec![2,3]);assert_eq!(deque.into_iter().collect::<Vec<_>>(), vec![0,1,2,3,4,5]);}
Activity
cynecx commentedon Dec 23, 2020
I had to switch over to using a
Vecbecause I couldn't efficiently insert multiple items into aVecDeque. Having a splice method would've been really useful. If I can find some time these days, I might be able to work on a PR.tomkarw commentedon Mar 28, 2022
@rustbot claim
Boscop commentedon May 11, 2022
@tomkarw Thanks for working on this. Btw, what's the current status? :)
tomkarw commentedon Jul 16, 2022
Sorry for the late response, apparently I don't get GitHub notification via email.
TBH, I thought it will be easier. The
unsafecode needed kinda scared me, and I got a job 4 days after claiming this.I'll try to revisit it now, but will probably look for a mentor/guidance.
drwilco commentedon Apr 25, 2023
And what about a
.prepend()to mirror.append()?qvignaud commentedon Jun 10, 2024
Hi, I just found out I'm encountering a case where
prepend()and/orextend_front()methods onVecDequecould be really useful.I'm doing the work by iterating over other vector and
push_frontrepeatedly, but that feels not idiomatic and I guess not optimal at all.If no one is available for this I might take a look at some point.
jnb commentedon Aug 13, 2024
+1 for implementing this. Repeatedly calling
push_fronthas a significant performance impact for my use-case, so I ended-up hacking something together on top of aVec.nhtyy commentedon Dec 12, 2024
I wonder what the blockers are here? I might give implementing
prependa shot this weekend.tomkarw commentedon Dec 13, 2024
No blockers, just lack of time. Feel free to pick it up, I'll be happy to see it implemented.
jlnstrk commentedon Mar 26, 2025
For the simple case of trying to avoid repeated shifts on insert into the middle, the following should add only
O(2n+m)to the complexity ofextend(), wherenis length pre-insert andmis length of iter.antonilol commentedon Sep 22, 2025
@rustbot claim
antonilol commentedon Oct 30, 2025
tracking issue: #146975, related PRs are linked there if people here want to check them out
Rollup merge of rust-lang#146861 - antonilol:vec_deque_extend_front, …
Rollup merge of rust-lang#146861 - antonilol:vec_deque_extend_front, …
Rollup merge of rust-lang#146861 - antonilol:vec_deque_extend_front, …
Rollup merge of rust-lang#146861 - antonilol:vec_deque_extend_front, …
Unrolled build for #146861
Rollup merge of rust-lang#146861 - antonilol:vec_deque_extend_front, …
Dylan-DPC commentedon Nov 7, 2026
Closing this in favour of the tracking issue #146975