
英:/'dek/ 美:/'dɛk/
n. 雙端隊列;雙隊列
n. (Deque)人名;(西)德克
When a task forks a new thread, it pushes it onto the head of its own deque.
當一個任務劃分一個新線程時,它将自己推到deque的頭部。
In the event the thread's task queue is empty, it then tries to steal another task off the tail of another thread's deque.
當線程的任務隊列為空,它将嘗試從另一個線程的deque的尾部竊取另一個任務。
My classes were all about finding the best algorithm or discovering new data structures that behave like old ones (anyone remember implementing a deque?).
我上的課隻是教會了我們怎樣尋找最好的算法,或是和舊的數據結構行為相似的新數據結構(還有人記得雙向隊列麼?)
Work stealing can be implemented with standard queues, but using a deque has two principle advantages over a standard queue: reduced contention and reduced stealing.
可以使用标準隊列實現工作竊取,但是與标準隊列相比,deque具有兩方面的優勢:減少争用和竊取。
The queue used in each case is actually a deque (a double-ended queue, pronounced deck), which allows threads to steal work from the back end of another queue, balancing work entering the pool.
所有情況下使用的隊列其實是一種雙隊列(deque)(兩端都能輸入數據的數據行列,發音為“deck”),它允許線程從另一個隊列的後端竊取工作,從而平衡進入線程池的工作。
Deque(雙端隊列) 是一種線性數據結構,全稱為“Double-Ended Queue”。它允許在隊列的前端(Front)和尾端(Rear)高效地進行插入(push
)和删除(pop
)操作,同時支持動态調整容量。與普通隊列(僅允許一端插入、另一端删除)相比,雙端隊列在功能上更為靈活。
雙端操作
用戶可在隊列頭部或尾部添加/移除元素,時間複雜度通常為$O(1)$(如Python的collections.deque
。
公式示例(動态擴容機制):
$$
C{text{new}} = max(1, alpha cdot C{text{old}})
$$
其中,$alpha$為擴容因子(不同語言實現可能不同)。
隨機訪問與内存結構
部分實現(如C++ STL的std::deque
)通過分塊數組(block-based array)實現近似隨機訪問,時間複雜度為$O(1)$,但實際性能可能弱于向量(vector
)。
線程安全與適用場景
多數編程語言中,雙端隊列非線程安全,需手動同步。典型應用包括:
collections.deque
std::deque
“Deque”是計算機科學中的一個術語,是“double-ended queue”(雙端隊列)的縮寫,發音為/dɛk/(類似英文單詞“deck”)。它是一種允許在隊列的前端和尾端高效進行插入、删除操作的線性數據結構,結合了棧(Stack)和普通隊列(Queue)的特性。
addFirst()
、addLast()
、removeFirst()
、removeLast()
。特性 | 普通隊列 | 雙端隊列(Deque) |
---|---|---|
插入位置 | 僅尾部 | 頭部或尾部 |
删除位置 | 僅頭部 | 頭部或尾部 |
典型應用 | 任務調度、BFS算法 | 撤銷操作、滑動窗口算法 |
例如在Python中,可通過collections.deque
直接使用雙端隊列,支持appendleft()
、popleft()
等方法;在Java中,Deque
接口由ArrayDeque
或LinkedList
實現。
deque
還支持隨機訪問,但時間複雜度為$O(1)$或$O(n)$,具體取決于實現。at easeremaintrojanbring forwardhierarchycastecripdeformingFuninginhibitoryIsaacslifesaverstandssybaritismunbuttonedWAeconomic structuregentleman in brownlower abdomenmorphine sulfateprescription drugRolls Royceadrenotropicbionicsgabbrophyrehydrotreatinginterbreedisochorekeymakermelodica