rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.63k stars 12.49k forks source link

VecDeque should support splice / extend_front #69939

Open Boscop opened 4 years ago

Boscop commented 4 years ago

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).

cynecx commented 3 years ago

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.

tomkarw commented 2 years ago

@rustbot claim

Boscop commented 2 years ago

@tomkarw Thanks for working on this. Btw, what's the current status? :)

tomkarw commented 2 years ago

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.

drwilco commented 1 year ago

And what about a .prepend() to mirror .append()?

qvignaud commented 3 months ago

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.

jnb commented 3 weeks ago

+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.