CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay
Class Merge2

java.lang.Object
  |
  +--jcsp.plugNplay.Merge2
All Implemented Interfaces:
CSProcess

public final class Merge2
extends Object
implements 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 jcsp.lang.*;
 import jcsp.util.ints.*;
 
 public final class Merge2Example {
 
   public static void main (String[] argv) {
 
     final One2OneChannel[] a = One2OneChannel.create (4);
     final One2OneChannel[] b = One2OneChannel.create (3,
                                  new InfiniteBuffer ());
     final One2OneChannel c = new One2OneChannel ();
     final One2OneChannel d = new One2OneChannel ();
     final One2OneChannel e = new One2OneChannel ();
 
     new Parallel (
       new CSProcess[] {
         new Mult (2, a[0], b[0]),
         new Mult (3, a[1], b[1]),
         new Mult (5, a[2], b[2]),
         new Merge2 (b[0], b[1], c),
         new Merge2 (c, b[2], d),
         new Prefix (1, d, e),
         new Delta (e, a),
         new Printer (a[3], "--> ", "\n")
       }
     ).run ();
 
   }
 
 }
 

Author:
P.H.Welch
See Also:
Merge

Constructor Summary
Merge2(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
 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

Merge2

public Merge2(ChannelInput in0,
              ChannelInput in1,
              ChannelOutput out)
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 channel
in1 - an input channel
out - the output channel
Method Detail

run

public void run()
The main body of this process.
Specified by:
run in interface CSProcess

CSP for Java
(JCSP) 1.0-rc4

Submit a bug or feature to jcsp-team@ukc.ac.uk
Version 1.0-rc4 of the JCSP API Specification (Copyright 1997-2000 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.