Copyright | Copyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Tested with: GHC 8.0.1
This module defines an infinite optimised queue, which has no counters nor signals.
Synopsis
- type FCFSQueue m a = Queue m FCFS FCFS a
- type LCFSQueue m a = Queue m LCFS FCFS a
- type SIROQueue m a = Queue m SIRO FCFS a
- type PriorityQueue m a = Queue m StaticPriorities FCFS a
- data Queue m sm so a
- newFCFSQueue :: MonadDES m => Simulation m (FCFSQueue m a)
- newLCFSQueue :: MonadDES m => Simulation m (LCFSQueue m a)
- newSIROQueue :: (MonadDES m, QueueStrategy m SIRO) => Simulation m (SIROQueue m a)
- newPriorityQueue :: (MonadDES m, QueueStrategy m StaticPriorities) => Simulation m (PriorityQueue m a)
- newQueue :: (MonadDES m, QueueStrategy m sm, QueueStrategy m so) => sm -> so -> Simulation m (Queue m sm so a)
- enqueueStoringStrategy :: Queue m sm so a -> sm
- dequeueStrategy :: Queue m sm so a -> so
- queueNull :: MonadDES m => Queue m sm so a -> Event m Bool
- queueCount :: MonadDES m => Queue m sm so a -> Event m Int
- dequeue :: (MonadDES m, DequeueStrategy m sm, EnqueueStrategy m so) => Queue m sm so a -> Process m a
- dequeueWithOutputPriority :: (MonadDES m, DequeueStrategy m sm, PriorityQueueStrategy m so po) => Queue m sm so a -> po -> Process m a
- tryDequeue :: (MonadDES m, DequeueStrategy m sm) => Queue m sm so a -> Event m (Maybe a)
- enqueue :: (MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> a -> Event m ()
- enqueueWithStoringPriority :: (MonadDES m, PriorityQueueStrategy m sm pm, DequeueStrategy m so) => Queue m sm so a -> pm -> a -> Event m ()
- queueDelete :: (MonadDES m, Eq a, DeletingQueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> a -> Event m Bool
- queueDelete_ :: (MonadDES m, Eq a, DeletingQueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> a -> Event m ()
- queueDeleteBy :: (MonadDES m, DeletingQueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> (a -> Bool) -> Event m (Maybe a)
- queueDeleteBy_ :: (MonadDES m, DeletingQueueStrategy m sm, DequeueStrategy m so) => Queue m sm so a -> (a -> Bool) -> Event m ()
- queueContains :: (MonadDES m, Eq a, DeletingQueueStrategy m sm) => Queue m sm so a -> a -> Event m Bool
- queueContainsBy :: (MonadDES m, DeletingQueueStrategy m sm) => Queue m sm so a -> (a -> Bool) -> Event m (Maybe a)
- clearQueue :: (MonadDES m, DequeueStrategy m sm) => Queue m sm so a -> Event m ()
Queue Types
type FCFSQueue m a = Queue m FCFS FCFS a Source #
A type synonym for the ordinary FIFO queue also known as the FCFS (First Come - First Serviced) queue.
type LCFSQueue m a = Queue m LCFS FCFS a Source #
A type synonym for the ordinary LIFO queue also known as the LCFS (Last Come - First Serviced) queue.
type SIROQueue m a = Queue m SIRO FCFS a Source #
A type synonym for the SIRO (Serviced in Random Order) queue.
type PriorityQueue m a = Queue m StaticPriorities FCFS a Source #
A type synonym for the queue with static priorities applied when storing the elements in the queue.
Represents an infinite queue using the specified strategies for
internal storing (in memory), sm
, and dequeueing (output), so
, where a
denotes
the type of items stored in the queue. Type m
denotes the underlying monad within
which the simulation executes.
Creating Queue
newFCFSQueue :: MonadDES m => Simulation m (FCFSQueue m a) Source #
Create a new infinite FCFS queue.
newLCFSQueue :: MonadDES m => Simulation m (LCFSQueue m a) Source #
Create a new infinite LCFS queue.
newSIROQueue :: (MonadDES m, QueueStrategy m SIRO) => Simulation m (SIROQueue m a) Source #
Create a new infinite SIRO queue.
newPriorityQueue :: (MonadDES m, QueueStrategy m StaticPriorities) => Simulation m (PriorityQueue m a) Source #
Create a new infinite priority queue.
:: (MonadDES m, QueueStrategy m sm, QueueStrategy m so) | |
=> sm | the strategy applied when storing items in the queue |
-> so | the strategy applied to the dequeueing (output) processes when the queue is empty |
-> Simulation m (Queue m sm so a) |
Create a new infinite queue with the specified strategies.
Queue Properties and Activities
enqueueStoringStrategy :: Queue m sm so a -> sm Source #
The strategy applied when storing (in memory) items in the queue.
dequeueStrategy :: Queue m sm so a -> so Source #
The strategy applied to the dequeueing (output) processes.
queueNull :: MonadDES m => Queue m sm so a -> Event m Bool Source #
Test whether the queue is empty.
See also queueNullChanged
and queueNullChanged_
.
queueCount :: MonadDES m => Queue m sm so a -> Event m Int Source #
Return the current queue size.
See also queueCountStats
, queueCountChanged
and queueCountChanged_
.
Dequeuing and Enqueuing
:: (MonadDES m, DequeueStrategy m sm, EnqueueStrategy m so) | |
=> Queue m sm so a | the queue |
-> Process m a | the dequeued value |
Dequeue suspending the process if the queue is empty.
dequeueWithOutputPriority Source #
:: (MonadDES m, DequeueStrategy m sm, PriorityQueueStrategy m so po) | |
=> Queue m sm so a | the queue |
-> po | the priority for output |
-> Process m a | the dequeued value |
Dequeue with the output priority suspending the process if the queue is empty.
:: (MonadDES m, DequeueStrategy m sm) | |
=> Queue m sm so a | the queue |
-> Event m (Maybe a) | the dequeued value of |
Try to dequeue immediately.
:: (MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> a | the item to enqueue |
-> Event m () |
Enqueue the item.
enqueueWithStoringPriority Source #
:: (MonadDES m, PriorityQueueStrategy m sm pm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> pm | the priority for storing |
-> a | the item to enqueue |
-> Event m () |
Enqueue with the storing priority the item.
:: (MonadDES m, Eq a, DeletingQueueStrategy m sm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> a | the item to remove from the queue |
-> Event m Bool | whether the item was found and removed |
Remove the item from the queue and return a flag indicating whether the item was found and actually removed.
:: (MonadDES m, Eq a, DeletingQueueStrategy m sm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> a | the item to remove from the queue |
-> Event m () |
Remove the specified item from the queue.
:: (MonadDES m, DeletingQueueStrategy m sm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> (a -> Bool) | the predicate |
-> Event m (Maybe a) |
Remove an item satisfying the specified predicate and return the item if found.
:: (MonadDES m, DeletingQueueStrategy m sm, DequeueStrategy m so) | |
=> Queue m sm so a | the queue |
-> (a -> Bool) | the predicate |
-> Event m () |
Remove an item satisfying the specified predicate.
:: (MonadDES m, Eq a, DeletingQueueStrategy m sm) | |
=> Queue m sm so a | the queue |
-> a | the item to search the queue for |
-> Event m Bool | whether the item was found |
Detect whether the item is contained in the queue.
:: (MonadDES m, DeletingQueueStrategy m sm) | |
=> Queue m sm so a | the queue |
-> (a -> Bool) | the predicate |
-> Event m (Maybe a) | the item if it was found |
Detect whether an item satisfying the specified predicate is contained in the queue.
:: (MonadDES m, DequeueStrategy m sm) | |
=> Queue m sm so a | the queue |
-> Event m () |
Clear the queue immediately.