TL DR:
- A “shift” is performed when the buffer is full and if the head is not at the end. If you click every time you click, there is no need to move data.
- Values are not contiguous because they wrap the buffer.
VecDeque 2 : . / VecDeque, , /.
:
, , push_back pop_front.
T H
Before [o o o o . . . . ]
T H
After [. o o o o . . . ]
. .
H T
Before [. . . . o o o o ]
H T
After [o . . . . o o o ]
:
, , :
.
T H
Before [o o o o o o o . ]
T H
After [o o o o o o o . . . . . . . . . ]
, , .
H T
Before [o o . o o o o o ]
T H
After [. . . o o o o o o o . . . . . . ]
After the buffer grows, the tail moves to the end of the buffer.
H T
Before [o o o o o . o o ]
H T
After [o o o o o . . . . . . . . . o o ]
source
share