Package org.jcsp.plugNplay
Class Merge2
java.lang.Object
org.jcsp.plugNplay.Merge2
- All Implemented Interfaces:
CSProcess
Merges two strictly increasing Integer input streams into one
strictly increasing output stream.
Process Diagram
in0 ________ -->--| | out in1 | Merge2 |-->-- -->--|________|
Description
Merge2 is a process whose output stream is the ordered merging of the Integers on its input streams. It assumes that each input stream is strictly increasing (i.e. with no repeats) sequence of Integers. It generates a strictly increasing output stream containing all -- and only -- the Integers from its input streams (eliminating any duplicates).Channel Protocols
Input Channels | ||
---|---|---|
in0, in1 | java.lang.Number | Both channels can accept data from any subclass of Number. It is possible to send Floats down one channel and Integers down the other. However all values will be converted to ints. |
Output Channels | ||
out | java.lang.Integer | The output will always be of type Integer. |
Example
The following example shows how to use Merge2 in a small program. The program also uses some of the other plugNplay processes. The program prints, in ascending order (up to Integer.MAX_VALUE), all integers whose prime factors consist only of 2, 3 and 5. Curious readers may like to reason why the infinitely buffered channels are needed.import org.jcsp.lang.*; import org.jcsp.util.*; import org.jcsp.plugNplay.*; public class Merge2Example { public static void main (String[] argv) { final One2OneChannel[] a = Channel.one2oneArray (4); final One2OneChannel[] b = Channel.one2oneArray (3, new InfiniteBuffer ()); final One2OneChannel c = Channel.one2one (); final One2OneChannel d = Channel.one2one (); final One2OneChannel e = Channel.one2one (); new Parallel ( new CSProcess[] { new Mult (2, a[0].in (), b[0].out ()), new Mult (3, a[1].in (), b[1].out ()), new Mult (5, a[2].in (), b[2].out ()), new Merge2 (b[0].in (), b[1].in (), c.out ()), new Merge2 (c.in (), b[2].in (), d.out ()), new Prefix (1, d.in (), e.out ()), new Delta (e.in (), Channel.getOutputArray (a)), new Printer (a[3].in (), "--> ", "\n") } ).run (); } }
- Author:
- P.H. Welch
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMerge2
(ChannelInput in0, ChannelInput in1, ChannelOutput out) Construct a new Merge2 process with the input channels in0 and in1 and the output channel out. -
Method Summary
-
Constructor Details
-
Merge2
Construct a new Merge2 process with the input channels in0 and in1 and the output channel out. The ordering of the input channels makes no difference to the behaviour of this process.- Parameters:
in0
- an input channelin1
- an input channelout
- the output channel
-
-
Method Details