com.topologi.diffx.algorithm
Class MatrixShort

java.lang.Object
  extended by com.topologi.diffx.algorithm.MatrixShort
All Implemented Interfaces:
Matrix

public final class MatrixShort
extends Object
implements Matrix

A matrix implementation which backbone is a matrix of short numbers.

Version:
7 April 2005
Author:
Christophe Lauret (Allette Systems)

Constructor Summary
MatrixShort()
           
 
Method Summary
 int get(int i, int j)
          Returns the value at the given position.
 void incrementByMaxPath(int i, int j)
          Increment by the maximum path.
 void incrementPathBy(int i, int j, int n)
          Increment the path.
 boolean isGreaterX(int i, int j)
          Returns true we should move on the X direction.
 boolean isGreaterY(int i, int j)
          Returns true we should move on the X direction.
 boolean isSameXY(int i, int j)
          Returns true we moving on the X direction is equivalent to moving on the Y direction.
 void release()
          Gets rid of the underlying matrix so that garbage collector can do its work.
 void set(int i, int j, int x)
          Sets the value of the matrix at the given position.
 void setup(int width, int height)
          Create a matrix of the given width and height.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MatrixShort

public MatrixShort()
Method Detail

setup

public void setup(int width,
                  int height)
Description copied from interface: Matrix
Create a matrix of the given width and height.

Specified by:
setup in interface Matrix
Parameters:
width - The number of columns.
height - The number of rows.
See Also:
Matrix.setup(int, int)

set

public void set(int i,
                int j,
                int x)
Description copied from interface: Matrix
Sets the value of the matrix at the given position.

Specified by:
set in interface Matrix
Parameters:
i - The column index.
j - The row index.
x - The value to set.
See Also:
Matrix.set(int, int, int)

get

public int get(int i,
               int j)
Description copied from interface: Matrix
Returns the value at the given position.

Specified by:
get in interface Matrix
Parameters:
i - The column index.
j - The row index.
Returns:
The value at the given position.
See Also:
Matrix.get(int, int)

incrementPathBy

public void incrementPathBy(int i,
                            int j,
                            int n)
Description copied from interface: Matrix
Increment the path.

value(i, j) := value(i+1, j+1) + n

Specified by:
incrementPathBy in interface Matrix
Parameters:
i - The column index.
j - The row index.
n - The increment number.
See Also:
Matrix.incrementPathBy(int, int, int)

incrementByMaxPath

public void incrementByMaxPath(int i,
                               int j)
Description copied from interface: Matrix
Increment by the maximum path.

value(i, j) := max( value(i+1, j) , value(i, j+1) )

Specified by:
incrementByMaxPath in interface Matrix
Parameters:
i - The column index.
j - The row index.
See Also:
Matrix.incrementByMaxPath(int, int)

isGreaterX

public boolean isGreaterX(int i,
                          int j)
Description copied from interface: Matrix
Returns true we should move on the X direction.

if value(i+1, j) > value(i, j+1)

Specified by:
isGreaterX in interface Matrix
Parameters:
i - The column index.
j - The row index.
Returns:
true to move to i+1; false otherwise.
See Also:
Matrix.isGreaterX(int, int)

isGreaterY

public boolean isGreaterY(int i,
                          int j)
Description copied from interface: Matrix
Returns true we should move on the X direction.

if value(i+1, j) < value(i, j+1)

Specified by:
isGreaterY in interface Matrix
Parameters:
i - The column index.
j - The row index.
Returns:
true to move to j+1; false otherwise.
See Also:
Matrix.isGreaterY(int, int)

isSameXY

public boolean isSameXY(int i,
                        int j)
Description copied from interface: Matrix
Returns true we moving on the X direction is equivalent to moving on the Y direction.

if value(i+1, j) == value(i, j+1)

Specified by:
isSameXY in interface Matrix
Parameters:
i - The column index.
j - The row index.
Returns:
true if it is the same; false otherwise.
See Also:
Matrix.isSameXY(int, int)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

release

public void release()
Gets rid of the underlying matrix so that garbage collector can do its work.

Specified by:
release in interface Matrix
See Also:
Matrix.release()