Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A queue data structure with \(\mathcal{O}(1)^*\) (amortized under ephemeral usage only) operations, as described in
- Okasaki, Chris. "Simple and efficient purely functional queues and deques." Journal of functional programming 5.4 (1995): 583-592.
- Okasaki, Chris. Purely Functional Data Structures. Diss. Princeton University, 1996.
Synopsis
- data EphemeralQueue a where
- pattern Empty :: EphemeralQueue a
- pattern Full :: a -> EphemeralQueue a -> EphemeralQueue a
- empty :: EphemeralQueue a
- singleton :: a -> EphemeralQueue a
- fromList :: [a] -> EphemeralQueue a
- enqueue :: a -> EphemeralQueue a -> EphemeralQueue a
- dequeue :: EphemeralQueue a -> Maybe (a, EphemeralQueue a)
- enqueueFront :: a -> EphemeralQueue a -> EphemeralQueue a
- isEmpty :: EphemeralQueue a -> Bool
- map :: (a -> b) -> EphemeralQueue a -> EphemeralQueue b
- traverse :: Applicative f => (a -> f b) -> EphemeralQueue a -> f (EphemeralQueue b)
- toList :: EphemeralQueue a -> [a]
Ephemeral queue
data EphemeralQueue a where Source #
A queue data structure with \(\mathcal{O}(1)^*\) (amortized under ephemeral usage only) operations.
pattern Empty :: EphemeralQueue a | An empty queue. |
pattern Full :: a -> EphemeralQueue a -> EphemeralQueue a | The front of a queue, and the rest of it. |
Instances
Initialization
empty :: EphemeralQueue a Source #
An empty queue.
singleton :: a -> EphemeralQueue a Source #
A singleton queue.
fromList :: [a] -> EphemeralQueue a Source #
\(\mathcal{O}(1)\). Construct a queue from a list. The head of the list corresponds to the front of the queue.
Basic interface
enqueue :: a -> EphemeralQueue a -> EphemeralQueue a Source #
\(\mathcal{O}(1)\). Enqueue an element at the back of a queue, to be dequeued last.
dequeue :: EphemeralQueue a -> Maybe (a, EphemeralQueue a) Source #
\(\mathcal{O}(1)^*\) front, \(\mathcal{O}(1)^*\) rest. Dequeue an element from the front of a queue.
Extended interface
enqueueFront :: a -> EphemeralQueue a -> EphemeralQueue a Source #
\(\mathcal{O}(1)\). Enqueue an element at the front of a queue, to be dequeued next.
Queries
isEmpty :: EphemeralQueue a -> Bool Source #
\(\mathcal{O}(1)\). Is a queue empty?
Transformations
map :: (a -> b) -> EphemeralQueue a -> EphemeralQueue b Source #
\(\mathcal{O}(n)\). Apply a function to every element in a queue.
traverse :: Applicative f => (a -> f b) -> EphemeralQueue a -> f (EphemeralQueue b) Source #
\(\mathcal{O}(n)\). Apply a function to every element in a queue.
Conversions
toList :: EphemeralQueue a -> [a] Source #
\(\mathcal{O}(n)\). Construct a list from a queue. The head of the list corresponds to the front of the queue.