底层实现原理:
A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still.
通过 双链表实现; 两头都可以方便的访问,新增,删除; 但是 对于中间段 的操作仍然很慢;
各种操作 复杂度如下:
在 头尾 进行 新增(append),删除(pop) 时 比较高效,复杂度为1;
对比 python list(底层使用顺序表实现), list 只在 尾部append,pop时比较高效O(1),在头部 效率为O(N);
具体用法如下链接:
collections中 deque的使用_阿常呓语的专栏-CSDN博客
具体使用的地方:
python的asyncio包的base_events模块的BaseEventLoop类的_ready属性
相关链接: