aivika-transformers-5.8: Transformers for the Aivika simulation library

CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Simulation.Aivika.Trans.Queue.Base

Contents

Description

Tested with: GHC 8.0.1

This module defines an optimised finite queue, which has no counters nor signals.

Synopsis

Queue Types

type FCFSQueue m a = Queue m FCFS 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 FCFS 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 FCFS SIRO FCFS a Source #

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

type PriorityQueue m a = Queue m FCFS StaticPriorities FCFS a Source #

A type synonym for the queue with static priorities applied when storing the elements in the queue.

data Queue m si sm so a Source #

Represents a queue using the specified strategies for enqueueing (input), si, 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 => Int -> Simulation m (FCFSQueue m a) Source #

Create a new FCFS queue with the specified capacity.

newLCFSQueue :: MonadDES m => Int -> Simulation m (LCFSQueue m a) Source #

Create a new LCFS queue with the specified capacity.

newSIROQueue :: (MonadDES m, QueueStrategy m SIRO) => Int -> Simulation m (SIROQueue m a) Source #

Create a new SIRO queue with the specified capacity.

newPriorityQueue :: (MonadDES m, QueueStrategy m StaticPriorities) => Int -> Simulation m (PriorityQueue m a) Source #

Create a new priority queue with the specified capacity.

newQueue Source #

Arguments

:: (MonadDES m, QueueStrategy m si, QueueStrategy m sm, QueueStrategy m so) 
=> si

the strategy applied to the enqueueing (input) processes when the queue is full

-> sm

the strategy applied when storing items in the queue

-> so

the strategy applied to the dequeueing (output) processes when the queue is empty

-> Int

the queue capacity

-> Simulation m (Queue m si sm so a) 

Create a new queue with the specified strategies and capacity.

Queue Properties and Activities

enqueueStrategy :: Queue m si sm so a -> si Source #

The strategy applied to the enqueueing (input) processes when the queue is full.

enqueueStoringStrategy :: Queue m si sm so a -> sm Source #

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

dequeueStrategy :: Queue m si sm so a -> so Source #

The strategy applied to the dequeueing (output) processes when the queue is empty.

queueNull :: MonadDES m => Queue m si sm so a -> Event m Bool Source #

Test whether the queue is empty.

See also queueNullChanged and queueNullChanged_.

queueFull :: MonadDES m => Queue m si sm so a -> Event m Bool Source #

Test whether the queue is full.

See also queueFullChanged and queueFullChanged_.

queueMaxCount :: Queue m si sm so a -> Int Source #

The queue capacity.

queueCount :: MonadDES m => Queue m si sm so a -> Event m Int Source #

Return the current queue size.

See also queueCountStats, queueCountChanged and queueCountChanged_.

Dequeuing and Enqueuing

dequeue Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DequeueStrategy m sm, EnqueueStrategy m so) 
=> Queue m si sm so a

the queue

-> Process m a

the dequeued value

Dequeue suspending the process if the queue is empty.

dequeueWithOutputPriority Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DequeueStrategy m sm, PriorityQueueStrategy m so po) 
=> Queue m si 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.

tryDequeue Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) 
=> Queue m si sm so a

the queue

-> Event m (Maybe a)

the dequeued value of Nothing

Try to dequeue immediately.

enqueue Source #

Arguments

:: (MonadDES m, EnqueueStrategy m si, EnqueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> a

the item to enqueue

-> Process m () 

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

enqueueWithInputPriority Source #

Arguments

:: (MonadDES m, PriorityQueueStrategy m si pi, EnqueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> pi

the priority for input

-> a

the item to enqueue

-> Process m () 

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

enqueueWithStoringPriority Source #

Arguments

:: (MonadDES m, EnqueueStrategy m si, PriorityQueueStrategy m sm pm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> pm

the priority for storing

-> a

the item to enqueue

-> Process m () 

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

enqueueWithInputStoringPriorities Source #

Arguments

:: (MonadDES m, PriorityQueueStrategy m si pi, PriorityQueueStrategy m sm pm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> pi

the priority for input

-> pm

the priority for storing

-> a

the item to enqueue

-> Process m () 

Enqueue with the input and storing priorities the item suspending the process if the queue is full.

tryEnqueue Source #

Arguments

:: (MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> a

the item which we try to enqueue

-> Event m Bool 

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

tryEnqueueWithStoringPriority Source #

Arguments

:: (MonadDES m, PriorityQueueStrategy m sm pm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> pm

the priority for storing

-> a

the item which we try to enqueue

-> Event m Bool 

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

queueDelete Source #

Arguments

:: (MonadDES m, Eq a, DequeueStrategy m si, DeletingQueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si 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.

queueDelete_ Source #

Arguments

:: (MonadDES m, Eq a, DequeueStrategy m si, DeletingQueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> a

the item to remove from the queue

-> Event m () 

Remove the specified item from the queue.

queueDeleteBy Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DeletingQueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si 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.

queueDeleteBy_ Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DeletingQueueStrategy m sm, DequeueStrategy m so) 
=> Queue m si sm so a

the queue

-> (a -> Bool)

the predicate

-> Event m () 

Remove an item satisfying the specified predicate.

queueContains Source #

Arguments

:: (MonadDES m, Eq a, DeletingQueueStrategy m sm) 
=> Queue m si 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.

queueContainsBy Source #

Arguments

:: (MonadDES m, DeletingQueueStrategy m sm) 
=> Queue m si 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.

clearQueue Source #

Arguments

:: (MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) 
=> Queue m si sm so a

the queue

-> Event m () 

Clear the queue immediately.