C ++ standard library analysis summary (five) - <design principles Deque>

This section summarizes the design and characteristics of a method and an internal standard library Deque features associated iterator

1, Deque basic structure

  • Deque (deque) also known as continuous space, in fact it uses stitching together segmented (segmented continuous), between each segment are managed with Vector, each element of the Vector is a pointer, each pointer points to a sub- segments, each segment buffer is a buffer, when the first element placement, when the need to expand the buffer is full, then a buffer reallocation inside Vector string;
  • Deque iterator has four pointers, which represents the node at the control center position (i.e. position in the Vector), first node represents the meaning of the first buffer, the buffer last tail node represents referred to, first and last is the model boundaries, they will not change, cur indicates which elements of the iterator is currently pointing;
  • Implemented piecewise continuous, forward iterator when the latter reverse, is determined to be the current buffer is not reached the end or head, must have the ability to skip to the next buffer buffer, if we must rely on node pointer reaches the boundary back to the control center (Vector) and then jump to the next buffer

2, Deque iterator

Deque iterator is sizeof 16, comprising a Deque two iterators, a pointer to a size_type, so sizeof Deque of 16 + 16 + 4 + 4 = 40 bytes

2.1 Deque inserting operation deque <T> :: insert ()

  Since Deque can be expanded at both ends, the mobile element is introduced insert elements will issue, then bring the overhead structure of the copy, so that when inserted from the first insertion position to judge which side the first short moving distance of the shorter sides, maximize reduce overhead.

2.2 Deque how to implement so-called continuous space

  Deque claiming that continuous space, in fact, it is piecewise continuous, then the continuous space is to provide analog functions continuous space, such as increment, decrement, jumps and other movements, this is the iterator credit.

 

  

3、queue

 

Guess you like

Origin www.cnblogs.com/laiyingpeng/p/11193946.html