public final class Merge extends java.lang.Object implements CSProcess
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.*; import org.jcsp.plugNplay.*; public class MergeExample { public static void main (String[] argv) { final One2OneChannel[] a = Channel.one2oneArray (5); final One2OneChannel[] b = Channel.one2oneArray (4, new InfiniteBuffer ()); final One2OneChannel c = Channel.one2one (); final One2OneChannel d = 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 Mult (7, a[3].in (), b[3].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[4].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 One2OneChannel c = Channel.one2one(); new Parallel ( new CSProcess[] { new Merge2 (in[0], in[1], c.out ()), new Merge2 (c.in (), 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 One2OneChannel[] d = Channel.one2oneArray(2); new Parallel ( new CSProcess[] { new Merge (bottom, d[0].out ()), new Merge (top, d[1].out ()), new Merge2 (d[0].in (), d[1].in (), out) } ).run (); break; } }
Merge2
Constructor and Description |
---|
Merge(ChannelInput[] in,
ChannelOutput out)
Construct a new Merge2 process with the input channels
inand the output channel out.
|
Modifier and Type | Method and Description |
---|---|
void |
run()
The main body of this process.
|
public Merge(ChannelInput[] in, ChannelOutput out)
in
- the input channels (there must be at least 2)out
- the output channelCopyright © 1996–2018. All rights reserved.