Data.Queue.Class
Description
Abstracts the implementation details of a single-insertion, single-extraction queuelike structure.
- data e :-> f = e :-> f
- class IQueue q where
- type QueueKey q
- insert :: QueueKey q -> q -> q
- insertAll :: [QueueKey q] -> q -> q
- extract :: q -> Maybe (QueueKey q, q)
- top :: q -> Maybe (QueueKey q)
- delete :: q -> Maybe q
- empty :: q
- singleton :: QueueKey q -> q
- fromList :: [QueueKey q] -> q
- size :: q -> Int
- null :: q -> Bool
- toList :: q -> [QueueKey q]
- toList_ :: q -> [QueueKey q]
- merge :: q -> q -> q
- mergeAll :: [q] -> q
Documentation
Type that only orders on the key, ignoring the value completely; frequently useful in priority queues, so made available here.
Constructors
| e :-> f |
A generic type class encapsulating a generic queuelike structure, that supports single-insertion and single-extraction; this abstraction includes priority queues, stacks, and FIFO queues. There are many minimal implementations, so each method lists the prerequisites for its default implementation. Most implementations will implement empty, (singleton and merge) or insert, (peek and delete) or extract, and size. (The absolute minimal implementation is empty, insert, extract, and size.)
Methods
insert :: QueueKey q -> q -> qSource
insertAll :: [QueueKey q] -> q -> qSource
Inserts several elements into the queue. The default implementation uses insert. (In some cases, it may be advantageous to override this implementation with xs `.)
insertAll` q = q `merge` fromList xs
extract :: q -> Maybe (QueueKey q, q)Source
Attempts to extract an element from the queue; if the queue is empty, returns Nothing. The default implementation uses peek and delete.
top :: q -> Maybe (QueueKey q)Source
Gets the element that will next be extracted from the queue, if there is an element available. The default implementation uses extract.
Deletes an element from the queue, if the queue is nonempty. The default implementation uses extract.
Constructs an empty queue. The default implementation uses fromList.
singleton :: QueueKey q -> qSource
fromList :: [QueueKey q] -> qSource
Constructs a queue with all of the elements in the list. The default implementation uses insertAll and empty.
Gets the size of the queue. The default implementation uses toList_.
Checks if the queue is empty. The default implementation uses peek.
toList :: q -> [QueueKey q]Source
Extracts every element from the queue. The default implementation uses extract.
toList_ :: q -> [QueueKey q]Source
Extracts every element from the queue, with no guarantees upon order. The default implementation uses toList.