- Rust Standard Library Cookbook
- Jan Nils Ferner Daniel Durante
- 216字
- 2021-08-27 19:45:12
There's more...
Internally, the VecDeque is implemented as a ring buffer, also known as a circular buffer. It's called like this because it behaves like a circle: the end touches the beginning.
It works by allocating a continuous block of memory, like the Vec; however, where the Vec always leaves its extra capacity at the end of the block, the VecDeque has nothing against leaving spots inside the block empty. It follows that when you remove the first element, the VecDeque doesn't move all elements to the left, but simply leaves the first spot empty. If you then push an element into the beginning via push_front, it will take the spot freed earlier while leaving the elements after it untouched.
The circular catch in the story is that if you have some capacity in the front of the block but none in the back while using push_back, the VecDeque will simply use that space to allocate the extra element, leading to the following situation:

This is great, because you will not have to worry about this at all while using it, as its iterating methods hide the implementation by always showing you the correct order!
Like the vector, VecDeque will resize itself and move all its elements into a new block when its capacity runs out.
- 大話傳送網(wǎng)
- App Inventor移動(dòng)應(yīng)用開(kāi)發(fā)標(biāo)準(zhǔn)教程
- 西門(mén)子工業(yè)網(wǎng)絡(luò)通信技術(shù)詳解
- 電子單元電路應(yīng)用與實(shí)測(cè)技能演練
- 電子技能與實(shí)訓(xùn)項(xiàng)目教程
- 電子工程師自學(xué)速成:設(shè)計(jì)篇(第2版)
- 寬帶光接入技術(shù)
- 數(shù)字新基建的大動(dòng)脈:光纜技術(shù)革新與管線施工
- 數(shù)據(jù)通信原理與技術(shù)
- 5G網(wǎng)絡(luò)技術(shù)與規(guī)劃設(shè)計(jì)基礎(chǔ)
- 基站主設(shè)備及配套設(shè)備維護(hù)
- 電力工程與通信技術(shù)
- 電子裝配工藝實(shí)訓(xùn):項(xiàng)目教程
- 空間信號(hào)協(xié)同處理理論與技術(shù)
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要