com.ibm.tspaces.examples.mergesort
Class SortThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.ibm.tspaces.examples.mergesort.SortThread

public class SortThread
extends java.lang.Thread

This class implements a merge sort using a TupleSpace to hold the values to be sorted and intermediate results.

Author:
Daniel Ford
See Also:
MergeSort, Tuple, Field, TupleSpace

Field Summary
 int t1cnt
          Count of Tuple reads.
 int t2cnt
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SortThread(TupleSpace ts, int i)
          Create a SortThread.
 
Method Summary
static void main(java.lang.String[] argv)
          The starting point of execution for the sort thread
 DataTuple mergeTuples(DataTuple t1, DataTuple t2)
          Extract the two Vectors of integers from some data Tuples and merge sort them to produce a data Tuple with the values sorted.
 VectorWithEquals mergeVectors(java.util.Vector v1, java.util.Vector v2)
          Merge sort two vectors of sorted integers.
 void run()
          The starting point of execution.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

t1cnt

public int t1cnt
Count of Tuple reads.

t2cnt

public int t2cnt
Constructor Detail

SortThread

public SortThread(TupleSpace ts,
                  int i)
Create a SortThread.
Parameters:
ts - the TupleSpace where the values to be sorted are stored.
i - the index of the thread.
See Also:
TupleSpace
Method Detail

run

public void run()
The starting point of execution.
Overrides:
run in class java.lang.Thread

mergeTuples

public DataTuple mergeTuples(DataTuple t1,
                             DataTuple t2)
                      throws TupleSpaceException
Extract the two Vectors of integers from some data Tuples and merge sort them to produce a data Tuple with the values sorted.
Parameters:
t1 - A Tuple with the second field a Vector of sorted integers.
t2 - A Tuple with the second field a Vector of sorted integers.
Returns:
A DataTuple that contains the sorted collection of the two vectors extracted from the parameter Tuples.
Throws:
TupleSpaceException - if the format of the tuple is incorrect.

mergeVectors

public VectorWithEquals mergeVectors(java.util.Vector v1,
                                     java.util.Vector v2)
Merge sort two vectors of sorted integers.
Parameters:
v1 - A Vector of integers in increasing sorted order.
v2 - A Vector of integers in increasing sorted order.
Returns:
A Vector of the integers merge sorted.

main

public static void main(java.lang.String[] argv)
The starting point of execution for the sort thread