Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A queue data structure with \(\mathcal{O}(1)\) (worst-case) 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 Queue a where
- empty :: Queue a
- singleton :: a -> Queue a
- fromList :: [a] -> Queue a
- enqueue :: a -> Queue a -> Queue a
- dequeue :: Queue a -> Maybe (a, Queue a)
- enqueueFront :: a -> Queue a -> Queue a
- isEmpty :: Queue a -> Bool
- map :: (a -> b) -> Queue a -> Queue b
- traverse :: Applicative f => (a -> f b) -> Queue a -> f (Queue b)
- toList :: Queue a -> [a]
Queue
A queue data structure with \(\mathcal{O}(1)\) (worst-case) operations.
pattern Empty :: Queue a | An empty queue. |
pattern Full :: a -> Queue a -> Queue a | The front of a queue, and the rest of it. |
Instances
Foldable Queue Source # | |
Defined in Queue fold :: Monoid m => Queue m -> m # foldMap :: Monoid m => (a -> m) -> Queue a -> m # foldMap' :: Monoid m => (a -> m) -> Queue a -> m # foldr :: (a -> b -> b) -> b -> Queue a -> b # foldr' :: (a -> b -> b) -> b -> Queue a -> b # foldl :: (b -> a -> b) -> b -> Queue a -> b # foldl' :: (b -> a -> b) -> b -> Queue a -> b # foldr1 :: (a -> a -> a) -> Queue a -> a # foldl1 :: (a -> a -> a) -> Queue a -> a # elem :: Eq a => a -> Queue a -> Bool # maximum :: Ord a => Queue a -> a # minimum :: Ord a => Queue a -> a # | |
Traversable Queue Source # | |
Functor Queue Source # | |
Monoid (Queue a) Source # | |
Semigroup (Queue a) Source # | \(\mathcal{O}(n)\), where \(n\) is the size of the second argument. |
Show a => Show (Queue a) Source # | |
Eq a => Eq (Queue a) Source # | |
Initialization
fromList :: [a] -> Queue 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 -> Queue a -> Queue a Source #
\(\mathcal{O}(1)\). Enqueue an element at the back of a queue, to be dequeued last.
dequeue :: Queue a -> Maybe (a, Queue a) Source #
\(\mathcal{O}(1)\) front, \(\mathcal{O}(1)\) rest. Dequeue an element from the front of a queue.
Extended interface
enqueueFront :: a -> Queue a -> Queue a Source #
\(\mathcal{O}(1)\). Enqueue an element at the front of a queue, to be dequeued next.
Queries
Transformations
map :: (a -> b) -> Queue a -> Queue b Source #
\(\mathcal{O}(n)\). Apply a function to every element in a queue.
traverse :: Applicative f => (a -> f b) -> Queue a -> f (Queue b) Source #
\(\mathcal{O}(n)\). Apply a function to every element in a queue.