Description
From the docs of VecDeque:
"""
A double-ended queue implemented with a growable ring buffer.
The “default” usage of this type as a queue is to use push_back to add to the queue, and pop_front to remove from the queue. extend and append push onto the back in this manner, and iterating over VecDeque goes front to back.
"""
From this, we can assume the default way to use VecDeque when visualised is:
front [ a, b, c, d, e ] back
# push_back(f)
front [ a, b, c, d, e, f ] back
VecDeque has a number of operations to reduce the size of the content in the VecDeque such as truncate or split_off, but these assume you want to truncate or split from the back.
front [ a, b, c, d, e, f ] back
# truncate(4)
front [ a, b, c, d ] back
front [ a, b, c, d, e, f ] back
# split_off(4)
front [ a, b, c, d ] back -> front [ e, f ] back
However, what is missing is equivalents for operating on the front of the VecDeque
front [ a, b, c, d, e, f ] back
# truncate_front(4)
front [ c, d, e, f ] back
This created confusion for me wanting to use VecDeque as an ordered ringbuffer since VecDeque will iterate front to back, and recommends you push_back, but trying to maintain a fixed capacity requires you to either manually pop_front to len, OR you need to actually store your VecDeque in reverse, and rely on iter().rev() allowing you to use truncate.
Since VecDeque intends to be "double ended" it would be useful and convenient to have a number of the methods given front variants. My non-exhaustive list is:
- truncate
- split_off