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 optimised finite queue, which has no counters nor signals.
Synopsis
- type FCFSQueue a = Queue FCFS FCFS FCFS a
- type LCFSQueue a = Queue FCFS LCFS FCFS a
- type SIROQueue a = Queue FCFS SIRO FCFS a
- type PriorityQueue a = Queue FCFS StaticPriorities FCFS a
- data Queue si sm so a
- newFCFSQueue :: Int -> Simulation (FCFSQueue a)
- newLCFSQueue :: Int -> Simulation (LCFSQueue a)
- newSIROQueue :: Int -> Simulation (SIROQueue a)
- newPriorityQueue :: Int -> Simulation (PriorityQueue a)
- newQueue :: (QueueStrategy si, QueueStrategy sm, QueueStrategy so) => si -> sm -> so -> Int -> Simulation (Queue si sm so a)
- enqueueStrategy :: Queue si sm so a -> si
- enqueueStoringStrategy :: Queue si sm so a -> sm
- dequeueStrategy :: Queue si sm so a -> so
- queueNull :: Queue si sm so a -> Event Bool
- queueFull :: Queue si sm so a -> Event Bool
- queueMaxCount :: Queue si sm so a -> Int
- queueCount :: Queue si sm so a -> Event Int
- dequeue :: (DequeueStrategy si, DequeueStrategy sm, EnqueueStrategy so) => Queue si sm so a -> Process a
- dequeueWithOutputPriority :: (DequeueStrategy si, DequeueStrategy sm, PriorityQueueStrategy so po) => Queue si sm so a -> po -> Process a
- tryDequeue :: (DequeueStrategy si, DequeueStrategy sm) => Queue si sm so a -> Event (Maybe a)
- enqueue :: (EnqueueStrategy si, EnqueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> a -> Process ()
- enqueueWithInputPriority :: (PriorityQueueStrategy si pi, EnqueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> pi -> a -> Process ()
- enqueueWithStoringPriority :: (EnqueueStrategy si, PriorityQueueStrategy sm pm, DequeueStrategy so) => Queue si sm so a -> pm -> a -> Process ()
- enqueueWithInputStoringPriorities :: (PriorityQueueStrategy si pi, PriorityQueueStrategy sm pm, DequeueStrategy so) => Queue si sm so a -> pi -> pm -> a -> Process ()
- tryEnqueue :: (EnqueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> a -> Event Bool
- tryEnqueueWithStoringPriority :: (PriorityQueueStrategy sm pm, DequeueStrategy so) => Queue si sm so a -> pm -> a -> Event Bool
- queueDelete :: (Eq a, DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> a -> Event Bool
- queueDelete_ :: (Eq a, DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> a -> Event ()
- queueDeleteBy :: (DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> (a -> Bool) -> Event (Maybe a)
- queueDeleteBy_ :: (DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) => Queue si sm so a -> (a -> Bool) -> Event ()
- queueContains :: (Eq a, DeletingQueueStrategy sm) => Queue si sm so a -> a -> Event Bool
- queueContainsBy :: DeletingQueueStrategy sm => Queue si sm so a -> (a -> Bool) -> Event (Maybe a)
- clearQueue :: (DequeueStrategy si, DequeueStrategy sm) => Queue si sm so a -> Event ()
Queue Types
type FCFSQueue a = Queue 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 a = Queue 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 a = Queue FCFS SIRO FCFS a Source #
A type synonym for the SIRO (Serviced in Random Order) queue.
type PriorityQueue a = Queue FCFS StaticPriorities FCFS a Source #
A type synonym for the queue with static priorities applied when storing the elements in the queue.
data Queue 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.
Creating Queue
newFCFSQueue :: Int -> Simulation (FCFSQueue a) Source #
Create a new FCFS queue with the specified capacity.
newLCFSQueue :: Int -> Simulation (LCFSQueue a) Source #
Create a new LCFS queue with the specified capacity.
newSIROQueue :: Int -> Simulation (SIROQueue a) Source #
Create a new SIRO queue with the specified capacity.
newPriorityQueue :: Int -> Simulation (PriorityQueue a) Source #
Create a new priority queue with the specified capacity.
:: (QueueStrategy si, QueueStrategy sm, QueueStrategy 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 (Queue si sm so a) |
Create a new queue with the specified strategies and capacity.
Queue Properties and Activities
enqueueStrategy :: Queue si sm so a -> si Source #
The strategy applied to the enqueueing (input) processes when the queue is full.
enqueueStoringStrategy :: Queue si sm so a -> sm Source #
The strategy applied when storing (in memory) items in the queue.
dequeueStrategy :: Queue si sm so a -> so Source #
The strategy applied to the dequeueing (output) processes when the queue is empty.
queueNull :: Queue si sm so a -> Event Bool Source #
Test whether the queue is empty.
See also queueNullChanged
and queueNullChanged_
.
queueFull :: Queue si sm so a -> Event Bool Source #
Test whether the queue is full.
See also queueFullChanged
and queueFullChanged_
.
queueMaxCount :: Queue si sm so a -> Int Source #
The queue capacity.
queueCount :: Queue si sm so a -> Event Int Source #
Return the current queue size.
See also queueCountStats
, queueCountChanged
and queueCountChanged_
.
Dequeuing and Enqueuing
:: (DequeueStrategy si, DequeueStrategy sm, EnqueueStrategy so) | |
=> Queue si sm so a | the queue |
-> Process a | the dequeued value |
Dequeue suspending the process if the queue is empty.
dequeueWithOutputPriority Source #
:: (DequeueStrategy si, DequeueStrategy sm, PriorityQueueStrategy so po) | |
=> Queue si 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 si, DequeueStrategy sm) | |
=> Queue si sm so a | the queue |
-> Event (Maybe a) | the dequeued value of |
Try to dequeue immediately.
:: (EnqueueStrategy si, EnqueueStrategy sm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> a | the item to enqueue |
-> Process () |
Enqueue the item suspending the process if the queue is full.
enqueueWithInputPriority Source #
:: (PriorityQueueStrategy si pi, EnqueueStrategy sm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> pi | the priority for input |
-> a | the item to enqueue |
-> Process () |
Enqueue with the input priority the item suspending the process if the queue is full.
enqueueWithStoringPriority Source #
:: (EnqueueStrategy si, PriorityQueueStrategy sm pm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> pm | the priority for storing |
-> a | the item to enqueue |
-> Process () |
Enqueue with the storing priority the item suspending the process if the queue is full.
enqueueWithInputStoringPriorities Source #
:: (PriorityQueueStrategy si pi, PriorityQueueStrategy sm pm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> pi | the priority for input |
-> pm | the priority for storing |
-> a | the item to enqueue |
-> Process () |
Enqueue with the input and storing priorities the item suspending the process if the queue is full.
:: (EnqueueStrategy sm, DequeueStrategy so) | |
=> Queue si sm so 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.
tryEnqueueWithStoringPriority Source #
:: (PriorityQueueStrategy sm pm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> pm | the priority for storing |
-> a | the item which we try to enqueue |
-> Event Bool |
Try to enqueue with the storing priority the item. Return False
in
the monad if the queue is full.
:: (Eq a, DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) | |
=> Queue si 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, DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> a | the item to remove from the queue |
-> Event () |
Remove the specified item from the queue.
:: (DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) | |
=> Queue si 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.
:: (DequeueStrategy si, DeletingQueueStrategy sm, DequeueStrategy so) | |
=> Queue si sm so a | the queue |
-> (a -> Bool) | the predicate |
-> Event () |
Remove an item satisfying the specified predicate.
:: (Eq a, DeletingQueueStrategy sm) | |
=> Queue si 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 si 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 si, DequeueStrategy sm) | |
=> Queue si sm so a | the queue |
-> Event () |
Clear the queue immediately.