CSP for Java
(JCSP) 1.1-rc4

Class Merge2Int

  extended by org.jcsp.plugNplay.ints.Merge2Int
All Implemented Interfaces:

public final class Merge2Int
extends Object
implements CSProcess

Merges two strictly increasing int input streams into one strictly increasing output stream.

Process Diagram

    in0  ___________
   -->--|           | out
    in1 | Merge2Int |-->--


Merge2Int 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 numbers from its input streams (eliminating any duplicates).

Channel Protocols

Input Channels
in0, in1 int All channels in this package carry integers.
Output Channels
out int All channels in this package carry integers.


The following example shows how to use Merge2Int 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.ints.*;
 import org.jcsp.plugNplay.ints.*;
 public class Merge2IntExample {
   public static void main (String[] argv) {
     final One2OneChannelInt[] a = Channel.one2oneIntArray (4);
     final One2OneChannelInt[] b = Channel.one2oneIntArray (3, new InfiniteBufferInt ());
     final One2OneChannelInt c = Channel.one2oneInt ();
     final One2OneChannelInt d = Channel.one2oneInt ();
     final One2OneChannelInt e = Channel.one2oneInt ();
     new Parallel (
       new CSProcess[] {
         new MultInt (2, a[0].in (), b[0].out ()),
         new MultInt (3, a[1].in (), b[1].out ()),
         new MultInt (5, a[2].in (), b[2].out ()),
         new Merge2Int (b[0].in (), b[1].in (), c.out ()),
         new Merge2Int (c.in (), b[2].in (), d.out ()),
         new PrefixInt (1, d.in (), e.out ()),
         new DeltaInt (e.in (), Channel.getOutputArray (a)),
         new PrinterInt (a[3].in (), "--> ", "\n")
     ).run ();

P.H. Welch
See Also:

Constructor Summary
Merge2Int(ChannelInputInt in0, ChannelInputInt in1, ChannelOutputInt out)
          Construct a new Merge2Int process with the input channels in0 and in1 and the output channel out.
Method Summary
 void run()
          The main body of this process.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public Merge2Int(ChannelInputInt in0,
                 ChannelInputInt in1,
                 ChannelOutputInt out)
Construct a new Merge2Int 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.

in0 - an input channel
in1 - an input channel
out - the output channel
Method Detail


public void run()
The main body of this process.

Specified by:
run in interface CSProcess

CSP for Java
(JCSP) 1.1-rc4

Submit a bug or feature to jcsp-team@kent.ac.uk
Version 1.1-rc4 of the JCSP API Specification (Copyright 1997-2008 P.D.Austin and P.H.Welch - All Rights Reserved)
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.