Data.PriorityQueue
- class Monad m => Enqueue q m a | q -> a where
- enqueue :: q -> a -> m ()
- enqueueBatch :: q -> [a] -> m ()
- class Monad m => Dequeue q m a | q -> a where
- dequeue :: q -> m (Maybe a)
- dequeueBatch :: q -> m [a]
- class Monad m => DequeueWhere q m a | q -> a where
- dequeueWhere :: q -> (a -> Bool) -> m (Maybe a)
- class Monad m => PeekQueue q m a | q -> a where
- peekQueue :: q -> m [a]
- peekQueueTaking :: Int -> q -> m [a]
- class Monad m => QueueSize q m where
- data PQ a
- emptyPQ :: Ord p => (a -> p) -> PQ a
- mkPriorityQueue :: ModifyRef sr m (PQ a) => sr -> PriorityQueue m a
- mkDefaultPriorityQueue :: Ref m (PQ a) -> PriorityQueue m a
- data PriorityQueue m a
- newPriorityQueue :: (Monad m, HasRef m1, NewRef (Ref m1 (PQ a)) m (PQ a), Ord p) => (a -> p) -> m (PriorityQueue m1 a)
- newPriorityQueueBy :: (Monad m, HasRef m1, NewRef (Ref m1 (PQ a)) m (PQ a)) => (a -> a -> Ordering) -> m (PriorityQueue m1 a)
Documentation
class Monad m => Enqueue q m a | q -> a where
Methods
enqueue :: q -> a -> m ()
Put an item into a queue. May block while trying to do so.
No constraint is placed on the behavior of the queue except that
every item put in really ought to come out sometime before
dequeue
returns a Nothing
.
enqueueBatch :: q -> [a] -> m ()
Instances
Monad m => Enqueue (PriorityQueue m a) m a |
class Monad m => Dequeue q m a | q -> a where
Methods
Pull an item out of a queue. Should not block. No ordering
constraints are implied other than that any item that went into
the queue really ought to come out before dequeue
returns
Nothing
.
dequeueBatch :: q -> m [a]
Instances
Monad m => Dequeue (PriorityQueue m a) m a |
class Monad m => DequeueWhere q m a | q -> a where
Methods
dequeueWhere :: q -> (a -> Bool) -> m (Maybe a)
Pull an item matching the given predicate out of a queue.
Instances
Monad m => DequeueWhere (PriorityQueue m a) m a |
class Monad m => PeekQueue q m a | q -> a where
Methods
peekQueue :: q -> m [a]
return the whole contents of the queue (if possible) without altering the queue's contents. Obviously in cases where this can't be done lazily this can be a very expensive operation.
peekQueueTaking :: Int -> q -> m [a]
peek a specified number of items off the queue. The default implementation is hideously wasteful in cases where peekQueue is not able to get the contents lazily.
Instances
Monad m => PeekQueue (PriorityQueue m a) m a |
class Monad m => QueueSize q m where
Instances
Monad m => QueueSize (PriorityQueue m a) m |
mkPriorityQueue :: ModifyRef sr m (PQ a) => sr -> PriorityQueue m aSource
Build a priority queue from a modifiable reference containing
a PQ
mkDefaultPriorityQueue :: Ref m (PQ a) -> PriorityQueue m aSource
Build a priority queue using an instance of the default modifiable reference for the requested monad and value type
data PriorityQueue m a Source
A priority queue usable in the monad m
with values of type a
Instances
Monad m => QueueSize (PriorityQueue m a) m | |
Monad m => Enqueue (PriorityQueue m a) m a | |
Monad m => Dequeue (PriorityQueue m a) m a | |
Monad m => DequeueWhere (PriorityQueue m a) m a | |
Monad m => PeekQueue (PriorityQueue m a) m a |
newPriorityQueue :: (Monad m, HasRef m1, NewRef (Ref m1 (PQ a)) m (PQ a), Ord p) => (a -> p) -> m (PriorityQueue m1 a)Source
Construct a new priority queue using the specified indexing function
newPriorityQueueBy :: (Monad m, HasRef m1, NewRef (Ref m1 (PQ a)) m (PQ a)) => (a -> a -> Ordering) -> m (PriorityQueue m1 a)Source
Construct a new priority queue using a comparator function. It is the user's responsibility to ensure that this function provides a sensible order.