aivika-4.3.5: A multi-method simulation library

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

Simulation.Aivika.Queue.Infinite.Base

Contents

Description

Tested with: GHC 7.10.1

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

Synopsis

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.

data Queue sm so a Source

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.

Creating Queue

newFCFSQueue :: Simulation (FCFSQueue a) Source

Create a new infinite FCFS queue.

newLCFSQueue :: Simulation (LCFSQueue a) Source

Create a new infinite LCFS queue.

newSIROQueue :: Simulation (SIROQueue a) Source

Create a new infinite SIRO queue.

newPriorityQueue :: Simulation (PriorityQueue a) Source

Create a new infinite priority queue.

newQueue Source

Arguments

:: (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

-> Simulation (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_.

Dequeuing and Enqueuing

dequeue Source

Arguments

:: (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

Arguments

:: (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.

tryDequeue Source

Arguments

:: DequeueStrategy sm 
=> Queue sm so a

the queue

-> Event (Maybe a)

the dequeued value of Nothing

Try to dequeue immediately.

enqueue Source

Arguments

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

the queue

-> a

the item to enqueue

-> Event () 

Enqueue the item.

enqueueWithStoringPriority Source

Arguments

:: (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.

queueDelete Source

Arguments

:: (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.

queueDelete_ Source

Arguments

:: (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.

queueDeleteBy Source

Arguments

:: (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.

queueDeleteBy_ Source

Arguments

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

the queue

-> (a -> Bool)

the predicate

-> Event () 

Remove an item satisfying the specified predicate.

queueContains Source

Arguments

:: (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.

queueContainsBy Source

Arguments

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

clearQueue Source

Arguments

:: DequeueStrategy sm 
=> Queue sm so a

the queue

-> Event () 

Clear the queue immediately.