Deque
Deque: functional double-ended queue with O(1) size tracking.
Representation: Deque(size, front, back) front is in natural order (head = front of deque) back is in reverse order (head = back of deque)
Complexity: push_front / push_back O(1) worst case pop_front / pop_back O(1) amortised (O(n) worst case on rebalance) peek_front / peek_back O(1) amortised size O(1) concat O(|d2|) amortised to_list / from_list O(n)
Types
Functions
True when f returns true for all elements (vacuously true for empty).
Append all elements of d2 after d1. O(|d2|) amortised.
Left fold over elements from front to back. O(n).
Right fold over elements from back to front. O(n).
Build a deque from a list. First element becomes the front. O(n).
Apply f to every element, returning a new deque in the same order. O(n).
Return Some(back element) without removing, or None if empty. O(1) amortised.
Return Some(front element) without removing, or None if empty. O(1) amortised.
Remove the back element. Returns (rest, Some(elem)) or (empty, None). O(1) amortised.
Remove the front element. Returns (Some(elem), rest) or (None, empty). O(1) amortised.
Add an element to the front of the deque. O(1).