public final class Merge
Merges an array of strictly increasing Integer input streams into one strictly increasing output stream.
Warning: this process assumes that its input channel array has at least two elements.
Input Channels | ||
---|---|---|
in[] | java.lang.Number |
Assume: in.length >= 2. All 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. |
import org.jcsp.lang.*; import org.jcsp.util.ints.*; public final class MergeExample { public static void main (String[] argv) { final One2OneChannel[] a = Channel.createOne2One (4); final One2OneChannel[] b = Channel.createOne2One (3, new InfiniteBuffer ()); final One2OneChannel c = Channel.createOne2One (); final One2OneChannel d = Channel.createOne2One (); 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 Merge (Channel.getInputArray (b), c.out ()), new Prefix (1, c.in (), d.out ()), new Delta (d.in (), Channel.getOutputArray (a)), new Printer (a[3].in (), "--> ", "\n") } ).run (); } }
public void run () { final int n = in.length; // deduce: n >= 2 switch (n) { case 2: new Merge2 (in[0], in[1], out).run (); break; case 3: final One2OneChannelImpl c = new One2OneChannelImpl (); new Parallel ( new CSProcess[] { new Merge2 (in[0], in[1], c), new Merge2 (c, in[2], out) } ).run (); break; default: // deduce: n >= 4 final int n2 = n/2; ChannelInput[] bottom = new ChannelInput[n2]; ChannelInput[] top = new ChannelInput[n - n2]; for (int i = 0; i < n2; i++) { bottom[i] = in[i]; } for (int i = n2; i < n; i++) { top[i - n2] = in[i]; } final One2OneChannelImpl[] d = One2OneChannelImpl.create (2); new Parallel ( new CSProcess[] { new Merge (bottom, d[0]), new Merge (top, d[1]), new Merge2 (d[0], d[1], out) } ).run (); break; } }
Constructor and description |
---|
Merge
(ChannelInput[] in, ChannelOutput out) Construct a new Merge2 process with the input channels inand the output channel out. |
Construct a new Merge2 process with the input channels inand the output channel out. The ordering of the input channels makes no difference to the behaviour of this process.
in
- the input channelsout
- the output channelJCSP for Java 1.8 generated 14-10-2016 by Jon Kerridge, Edinburgh Napier University - j dot kerridge at napier dot ac dot uk