The underlying principle of C++ deque

First, the purpose

Implement double-ended array

2. Bottom-level implementation

Continuous linear space with two-way openings

3. Schematic diagram

therefore

4. Class structure

  • class deque : protected Deque base

  • _Deque_base._Deque_impl

M_map 			指针数组
_M_map_size 	_M_map的容量
_M_start		记录 map 数组中首个连续空间的信息
_M_finish		记录 map 数组中最后一个连续空间的信息
  • _Deque_ iterator
_M_cur			指向当前正在遍历的元素
_M_first		指向当前连续空间的首地址
_M_last			指向当前连续空间的末尾地址
_M_node			用于指向 map 数组中存储的指向连续空间的指针
  • _deque buf size The number of elements that can be accommodated in the continuous space
  • _M_initialize _map
创建 map,并配置缓冲区
_M_start 和_M_finish 指向中间的位置,方便公平地往上或者向下扩展空间

五、push_back

  • Is the current continuous space enough?
  • Is there enough map space?

6. pop_back

  • Delete the last node. If there is no data in the current continuous space, release the continuous space.

I recommend a Lingsheng Academy project class. I personally think the teacher taught it well. I would like to share it with you:
Lingsheng Platinum Learning Card (including infrastructure/high-performance storage/golang cloud native/audio and video/Linux kernel)
https://xxetb.xet .tech/s/VsFMs

Guess you like

Origin blog.csdn.net/qq_40135848/article/details/132579402