- eList : List α
The enqueue list, which stores elements that have just been pushed (with the most recently enqueued elements at the head).
- dList : List α
The dequeue list, which buffers elements ready to be dequeued (with the head being the next item to be yielded by
dequeue?).
A functional queue data structure, using two back-to-back lists.
If we think of the queue as having elements pushed on the front and
popped from the back, then the queue itself is effectively eList ++ dList.reverse.
Instances For
Equations
- Std.Queue.instEmptyCollectionQueue = { emptyCollection := Std.Queue.empty }
O(1). Is the queue empty?
Equations
- Std.Queue.isEmpty q = (List.isEmpty q.dList && List.isEmpty q.eList)
Instances For
O(1). Push an element on the front of the queue.
Equations
- Std.Queue.enqueue v q = { eList := v :: q.eList, dList := q.dList }
Instances For
O(|vs|). Push a list of elements vs on the front of the queue.
Equations
- Std.Queue.enqueueAll vs q = { eList := vs ++ q.eList, dList := q.dList }
Instances For
Equations
- Std.Queue.toArray q = List.toArray q.dList ++ Array.reverse (List.toArray q.eList)