-- |-- Module: Control.Wire.Prefab.Queue-- Copyright: (c) 2012 Ertugrul Soeylemez-- License: BSD3-- Maintainer: Ertugrul Soeylemez <es@ertes.de>---- Wires acting as queues.moduleControl.Wire.Prefab.Queue(-- * Queuesbag,fifo,lifo)whereimportqualifiedData.SetasSimportqualifiedData.SequenceasSeqimportControl.Wire.WireimportData.MonoidimportData.Set(Set)importData.Sequence(ViewL(..),(><),viewl)-- | Incoming values are placed in a set, which is discharged element by-- element. Lower values are served first. Duplicate values are served-- once.---- Note: Incorrect usage can lead to congestion.---- * Complexity: O(n) space wrt bag size.---- * Depends: current instant.---- * Inhibits: when the bag is empty.bag::(Monoide,Ordb)=>Wireem(Setb)bbag=bag'S.emptywherebag's'=mkPure$\_xs->caseS.minView(S.unions'xs)ofNothing->(Leftmempty,bag'S.empty)Just(x,s)->(Rightx,bag's)-- | First in, first out. The input list is placed on the right end of-- a queue at every instant, giving earlier elements a higher priority.-- The queue is discharged item by item from the left.---- Note: Incorrect usage can lead to congestion.---- * Complexity: O(n) space wrt queue size.---- * Depends: current instant.---- * Inhibits: when the queue is currently empty.fifo::(Monoide)=>Wireem[b]bfifo=fifo'Seq.emptywherefifo'queue'=mkPure$\_xs->caseviewl(queue'><Seq.fromListxs)ofEmptyL->(Leftmempty,fifo'Seq.empty)x:<queue->(Rightx,fifo'queue)-- | Last in, first out. The input list is placed on a stack at every-- instant, giving earlier elements a higher priority. The stack is-- discharged item by item from the top.---- Note: Incorrect usage can lead to congestion.---- * Complexity: O(n) space wrt stack size.---- * Depends: current instant.---- * Inhibits: when the stack is currently empty.lifo::(Monoide)=>Wireem[b]blifo=lifo'Seq.emptywherelifo'queue'=mkPure$\_xs->caseviewl(Seq.fromListxs><queue')ofEmptyL->(Leftmempty,lifo'Seq.empty)x:<queue->(Rightx,lifo'queue)