Deque
documents
They also lack a
capacity
property -- the size of the
storage buffer at any given point is an unstable implementation detail that
should not affect application logic.
I find this somewhat unconvincing because Deque
s are often used for buffering and in many cases we want to prevent holding onto a (temporarily) ballooned Deque
. For example in SwiftNIO we have code which does:
self.buffers.removeAll(keepingCapacity: self.buffers.capacity < 16) // don't grow too much
and the idea is that we want to hold onto self.buffers
(a deque) but only if its underlying storage buffer is 16 elements or less at the moment. This occurred to me when I was reimplementing CircularBuffer
on top of Deque
.