Copyright | Copyright (c) 2009-2015, David Sorokin <david.sorokin@gmail.com> |
---|---|

License | BSD3 |

Maintainer | David Sorokin <david.sorokin@gmail.com> |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

Tested with: GHC 7.10.1

This module defines an infinite queue that can use the specified strategies.

- type FCFSQueue a = Queue FCFS FCFS a
- type LCFSQueue a = Queue LCFS FCFS a
- type SIROQueue a = Queue SIRO FCFS a
- type PriorityQueue a = Queue StaticPriorities FCFS a
- data Queue sm so a
- newFCFSQueue :: Event (FCFSQueue a)
- newLCFSQueue :: Event (LCFSQueue a)
- newSIROQueue :: Event (SIROQueue a)
- newPriorityQueue :: Event (PriorityQueue a)
- newQueue :: (QueueStrategy sm, QueueStrategy so) => sm -> so -> Event (Queue sm so a)
- enqueueStoringStrategy :: Queue sm so a -> sm
- dequeueStrategy :: Queue sm so a -> so
- queueNull :: Queue sm so a -> Event Bool
- queueCount :: Queue sm so a -> Event Int
- queueCountStats :: Queue sm so a -> Event (TimingStats Int)
- enqueueStoreCount :: Queue sm so a -> Event Int
- dequeueCount :: Queue sm so a -> Event Int
- dequeueExtractCount :: Queue sm so a -> Event Int
- enqueueStoreRate :: Queue sm so a -> Event Double
- dequeueRate :: Queue sm so a -> Event Double
- dequeueExtractRate :: Queue sm so a -> Event Double
- queueWaitTime :: Queue sm so a -> Event (SamplingStats Double)
- dequeueWaitTime :: Queue sm so a -> Event (SamplingStats Double)
- queueRate :: Queue sm so a -> Event Double
- dequeue :: (DequeueStrategy sm, EnqueueStrategy so) => Queue sm so a -> Process a
- dequeueWithOutputPriority :: (DequeueStrategy sm, PriorityQueueStrategy so po) => Queue sm so a -> po -> Process a
- tryDequeue :: DequeueStrategy sm => Queue sm so a -> Event (Maybe a)
- enqueue :: (EnqueueStrategy sm, DequeueStrategy so) => Queue sm so a -> a -> Event ()
- enqueueWithStoringPriority :: (PriorityQueueStrategy sm pm, DequeueStrategy so) => Queue sm so a -> pm -> a -> Event ()
- queueDelete :: (Eq a, DeletingQueueStrategy sm, DequeueStrategy so) => Queue sm so a -> a -> Event Bool
- queueDelete_ :: (Eq a, DeletingQueueStrategy sm, DequeueStrategy so) => Queue sm so a -> a -> Event ()
- queueDeleteBy :: (DeletingQueueStrategy sm, DequeueStrategy so) => Queue sm so a -> (a -> Bool) -> Event (Maybe a)
- queueDeleteBy_ :: (DeletingQueueStrategy sm, DequeueStrategy so) => Queue sm so a -> (a -> Bool) -> Event ()
- queueContains :: (Eq a, DeletingQueueStrategy sm) => Queue sm so a -> a -> Event Bool
- queueContainsBy :: DeletingQueueStrategy sm => Queue sm so a -> (a -> Bool) -> Event (Maybe a)
- clearQueue :: DequeueStrategy sm => Queue sm so a -> Event ()
- queueSummary :: (Show sm, Show so) => Queue sm so a -> Int -> Event ShowS
- queueNullChanged :: Queue sm so a -> Signal Bool
- queueNullChanged_ :: Queue sm so a -> Signal ()
- queueCountChanged :: Queue sm so a -> Signal Int
- queueCountChanged_ :: Queue sm so a -> Signal ()
- enqueueStoreCountChanged :: Queue sm so a -> Signal Int
- enqueueStoreCountChanged_ :: Queue sm so a -> Signal ()
- dequeueCountChanged :: Queue sm so a -> Signal Int
- dequeueCountChanged_ :: Queue sm so a -> Signal ()
- dequeueExtractCountChanged :: Queue sm so a -> Signal Int
- dequeueExtractCountChanged_ :: Queue sm so a -> Signal ()
- queueWaitTimeChanged :: Queue sm so a -> Signal (SamplingStats Double)
- queueWaitTimeChanged_ :: Queue sm so a -> Signal ()
- dequeueWaitTimeChanged :: Queue sm so a -> Signal (SamplingStats Double)
- dequeueWaitTimeChanged_ :: Queue sm so a -> Signal ()
- queueRateChanged :: Queue sm so a -> Signal Double
- queueRateChanged_ :: Queue sm so a -> Signal ()
- enqueueStored :: Queue sm so a -> Signal a
- dequeueRequested :: Queue sm so a -> Signal ()
- dequeueExtracted :: Queue sm so a -> Signal a
- queueChanged_ :: Queue sm so a -> Signal ()

# Queue Types

type FCFSQueue a = Queue FCFS FCFS a Source

A type synonym for the ordinary FIFO queue also known as the FCFS (First Come - First Serviced) queue.

type LCFSQueue a = Queue LCFS FCFS a Source

A type synonym for the ordinary LIFO queue also known as the LCFS (Last Come - First Serviced) queue.

type SIROQueue a = Queue SIRO FCFS a Source

A type synonym for the SIRO (Serviced in Random Order) queue.

type PriorityQueue a = Queue 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.

(Show sm, Show so, ResultItemable (ResultValue sm), ResultItemable (ResultValue so)) => ResultProvider (Queue sm so a) Source |

# Creating Queue

newFCFSQueue :: Event (FCFSQueue a) Source

Create a new infinite FCFS queue.

newLCFSQueue :: Event (LCFSQueue a) Source

Create a new infinite LCFS queue.

newSIROQueue :: Event (SIROQueue a) Source

Create a new infinite SIRO queue.

newPriorityQueue :: Event (PriorityQueue a) Source

Create a new infinite priority queue.

:: (QueueStrategy sm, QueueStrategy 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 |

-> Event (Queue sm so a) |

Create a new infinite queue with the specified strategies.

# Queue Properties and Activities

enqueueStoringStrategy :: Queue sm so a -> sm Source

The strategy applied when storing (in memory) items in the queue.

dequeueStrategy :: Queue sm so a -> so Source

The strategy applied to the dequeueing (output) processes.

queueNull :: Queue sm so a -> Event Bool Source

Test whether the queue is empty.

See also `queueNullChanged`

and `queueNullChanged_`

.

queueCount :: Queue sm so a -> Event Int Source

Return the current queue size.

See also `queueCountStats`

, `queueCountChanged`

and `queueCountChanged_`

.

queueCountStats :: Queue sm so a -> Event (TimingStats Int) Source

Return the queue size statistics.

enqueueStoreCount :: Queue sm so a -> Event Int Source

Return the total number of input items that were stored.

See also `enqueueStoreCountChanged`

and `enqueueStoreCountChanged_`

.

dequeueCount :: Queue sm so a -> Event Int Source

Return the total number of requests for dequeueing the items, not taking into account the failed attempts to dequeue immediately without suspension.

See also `dequeueCountChanged`

and `dequeueCountChanged_`

.

dequeueExtractCount :: Queue sm so a -> Event Int Source

Return the total number of output items that were actually dequeued.

See also `dequeueExtractCountChanged`

and `dequeueExtractCountChanged_`

.

enqueueStoreRate :: Queue sm so a -> Event Double Source

Return the rate of the items that were stored: how many items per time.

dequeueRate :: Queue sm so a -> Event Double Source

Return the rate of the requests for dequeueing the items: how many requests per time. It does not include the failed attempts to dequeue immediately without suspension.

dequeueExtractRate :: Queue sm so a -> Event Double Source

Return the rate of the output items that were dequeued: how many items per time.

queueWaitTime :: Queue sm so a -> Event (SamplingStats Double) Source

Return the wait time from the time at which the item was stored in the queue to the time at which it was dequeued.

See also `queueWaitTimeChanged`

and `queueWaitTimeChanged_`

.

dequeueWaitTime :: Queue sm so a -> Event (SamplingStats Double) Source

Return the dequeue wait time from the time at which the item was requested for dequeueing to the time at which it was actually dequeued.

See also `dequeueWaitTimeChanged`

and `dequeueWaitTimeChanged_`

.

queueRate :: Queue sm so a -> Event Double Source

Return a long-term average queue rate calculated as the average queue size divided by the average wait time.

See also `queueRateChanged`

and `queueRateChanged_`

.

# Dequeuing and Enqueuing

:: (DequeueStrategy sm, EnqueueStrategy so) | |

=> Queue sm so a | the queue |

-> Process a | the dequeued value |

Dequeue suspending the process if the queue is empty.

dequeueWithOutputPriority Source

:: (DequeueStrategy sm, PriorityQueueStrategy so po) | |

=> Queue sm so a | the queue |

-> po | the priority for output |

-> Process a | the dequeued value |

Dequeue with the output priority suspending the process if the queue is empty.

:: DequeueStrategy sm | |

=> Queue sm so a | the queue |

-> Event (Maybe a) | the dequeued value of |

Try to dequeue immediately.

:: (EnqueueStrategy sm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> a | the item to enqueue |

-> Event () |

Enqueue the item.

enqueueWithStoringPriority Source

:: (PriorityQueueStrategy sm pm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> pm | the priority for storing |

-> a | the item to enqueue |

-> Event () |

Enqueue with the storing priority the item.

:: (Eq a, DeletingQueueStrategy sm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> a | the item to remove from the queue |

-> Event 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.

:: (Eq a, DeletingQueueStrategy sm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> a | the item to remove from the queue |

-> Event () |

Remove the specified item from the queue.

:: (DeletingQueueStrategy sm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> (a -> Bool) | the predicate |

-> Event (Maybe a) |

Remove an item satisfying the specified predicate and return the item if found.

:: (DeletingQueueStrategy sm, DequeueStrategy so) | |

=> Queue sm so a | the queue |

-> (a -> Bool) | the predicate |

-> Event () |

Remove an item satisfying the specified predicate.

:: (Eq a, DeletingQueueStrategy sm) | |

=> Queue sm so a | the queue |

-> a | the item to search the queue for |

-> Event Bool | whether the item was found |

Detect whether the item is contained in the queue.

:: DeletingQueueStrategy sm | |

=> Queue sm so a | the queue |

-> (a -> Bool) | the predicate |

-> Event (Maybe a) | the item if it was found |

Detect whether an item satisfying the specified predicate is contained in the queue.

:: DequeueStrategy sm | |

=> Queue sm so a | the queue |

-> Event () |

Clear the queue immediately.

# Summary

queueSummary :: (Show sm, Show so) => Queue sm so a -> Int -> Event ShowS Source

Return the summary for the queue with desciption of its properties and activities using the specified indent.

# Derived Signals for Properties

queueNullChanged :: Queue sm so a -> Signal Bool Source

Signal when the `queueNull`

property value has changed.

queueNullChanged_ :: Queue sm so a -> Signal () Source

Signal when the `queueNull`

property value has changed.

queueCountChanged :: Queue sm so a -> Signal Int Source

Signal when the `queueCount`

property value has changed.

queueCountChanged_ :: Queue sm so a -> Signal () Source

Signal when the `queueCount`

property value has changed.

enqueueStoreCountChanged :: Queue sm so a -> Signal Int Source

Signal when the `enqueueStoreCount`

property value has changed.

enqueueStoreCountChanged_ :: Queue sm so a -> Signal () Source

Signal when the `enqueueStoreCount`

property value has changed.

dequeueCountChanged :: Queue sm so a -> Signal Int Source

Signal when the `dequeueCount`

property value has changed.

dequeueCountChanged_ :: Queue sm so a -> Signal () Source

Signal when the `dequeueCount`

property value has changed.

dequeueExtractCountChanged :: Queue sm so a -> Signal Int Source

Signal when the `dequeueExtractCount`

property value has changed.

dequeueExtractCountChanged_ :: Queue sm so a -> Signal () Source

Signal when the `dequeueExtractCount`

property value has changed.

queueWaitTimeChanged :: Queue sm so a -> Signal (SamplingStats Double) Source

Signal when the `queueWaitTime`

property value has changed.

queueWaitTimeChanged_ :: Queue sm so a -> Signal () Source

Signal when the `queueWaitTime`

property value has changed.

dequeueWaitTimeChanged :: Queue sm so a -> Signal (SamplingStats Double) Source

Signal when the `dequeueWaitTime`

property value has changed.

dequeueWaitTimeChanged_ :: Queue sm so a -> Signal () Source

Signal when the `dequeueWaitTime`

property value has changed.

queueRateChanged :: Queue sm so a -> Signal Double Source

Signal when the `queueRate`

property value has changed.

queueRateChanged_ :: Queue sm so a -> Signal () Source

Signal when the `queueRate`

property value has changed.

# Basic Signals

enqueueStored :: Queue sm so a -> Signal a Source

Return a signal that notifies when the enqueued item is stored in the internal memory of the queue.

dequeueRequested :: Queue sm so a -> Signal () Source

Return a signal that notifies when the dequeuing operation was requested.

dequeueExtracted :: Queue sm so a -> Signal a Source

Return a signal that notifies when the item was extracted from the internal storage of the queue and prepared for immediate receiving by the dequeuing process.

# Overall Signal

queueChanged_ :: Queue sm so a -> Signal () Source

Signal whenever any property of the queue changes.

The property must have the corresponded signal. There are also characteristics similar to the properties but that have no signals. As a rule, such characteristics already depend on the simulation time and therefore they may change at any time point.