aivika-0.7: A multi-paradigm simulation library

Stabilityexperimental
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Safe HaskellSafe-Inferred

Simulation.Aivika.Queue

Description

Tested with: GHC 7.6.3

This module defines a queue that can use the specified strategies. So, having only the FCFS, LCFS, SIRO and StaticPriorities strategies, you can build 4 x 3 x 4 = 48 different types of the queue, each of them will have its own behavior (below StaticPriorities can be used for input and output only).

Synopsis

Documentation

data Queue si qi sm qm so qo a Source

Represents the queue using the specified strategies for input si, internal storing (in memory) sm and output so, where a denotes the type of items stored in the queue. Types qi, qm and qo are determined automatically and you should not care about them - they are dependent types.

queueNull :: Queue si qi sm qm so qo a -> Event BoolSource

Test whether the queue is empty.

queueFull :: Queue si qi sm qm so qo a -> Event BoolSource

Test whether the queue is full.

queueMaxCount :: Queue si qi sm qm so qo a -> IntSource

The maximum available number of items.

queueCount :: Queue si qi sm qm so qo a -> Event IntSource

Return the queue size.

queueLostCount :: Queue si qi sm qm so qo a -> Event IntSource

Return the number of lost items.

enqueued :: Queue si qi sm qm so qo a -> Signal aSource

Return a signal that notifies when any item is enqueued.

dequeued :: Queue si qi sm qm so qo a -> Signal aSource

Return a signal that notifies when any item is dequeued.

enqueuedButLost :: Queue si qi sm qm so qo a -> Signal aSource

Return a signal which notifies that the item was lost when attempting to add it to the full queue with help of enqueueOrLost or enqueueOrLost_.

newQueueSource

Arguments

:: (QueueStrategy si qi, QueueStrategy sm qm, QueueStrategy so qo) 
=> si

the strategy applied to the input (enqueuing) process

-> sm

the strategy applied when storing items in the queue

-> so

the strategy applied to the output (dequeuing) process

-> Int

the maximum available number of items

-> Simulation (Queue si qi sm qm so qo a) 

Create a new queue with the specified strategies and maximum available number of items.

dequeueSource

Arguments

:: (DequeueStrategy si qi, DequeueStrategy sm qm, EnqueueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> Process a

the dequeued value

Dequeue suspending the process if the queue is empty.

dequeueWithPrioritySource

Arguments

:: (DequeueStrategy si qi, DequeueStrategy sm qm, PriorityQueueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> Double

the priority

-> Process a

the dequeued value

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

dequeueWithDynamicPrioritySource

Arguments

:: (DequeueStrategy si qi, DequeueStrategy sm qm, DynamicPriorityQueueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> Event Double

the dynamic priority

-> Process a

the dequeued value

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

tryDequeueSource

Arguments

:: (DequeueStrategy si qi, DequeueStrategy sm qm) 
=> Queue si qi sm qm so qo a

the queue

-> Event (Maybe a)

the dequeued value of Nothing

Try to dequeue from the queue immediately.

enqueueSource

Arguments

:: (EnqueueStrategy si qi, EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> a

the item to enqueue

-> Process () 

Enqueue the item suspending the process if the queue is full.

enqueueWithPrioritySource

Arguments

:: (PriorityQueueStrategy si qi, EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> Double

the priority

-> a

the item to enqueue

-> Process () 

Enqueue with the priority the item suspending the process if the queue is full.

enqueueWithDynamicPrioritySource

Arguments

:: (DynamicPriorityQueueStrategy si qi, EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> Event Double

the dynamic priority

-> a

the item to enqueue

-> Process () 

Enqueue with the dynamic priority the item suspending the process if the queue is full.

tryEnqueueSource

Arguments

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> a

the item which we try to enqueue

-> Event Bool 

Try to enqueue the item. Return False in the monad if the queue is full.

enqueueOrLostSource

Arguments

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> a

the item which we try to enqueue

-> Event Bool 

Try to enqueue the item. If the queue is full then the item will be lost and False will be returned.

enqueueOrLost_Source

Arguments

:: (EnqueueStrategy sm qm, DequeueStrategy so qo) 
=> Queue si qi sm qm so qo a

the queue

-> a

the item which we try to enqueue

-> Event () 

Try to enqueue the item. If the queue is full then the item will be lost.