Java Reference
In-Depth Information
/** set the value of a cell in the Matrix */
public function set(row:Integer, col:Integer,
value: Object ):Void{
sequence[getIndex(row,col)] = value;
}
/** get the value of a cell from the Matrix */
public function get(row:Integer, col:Integer) : Object {
sequence[getIndex(row,col)];
}
There are three functions that retrieve sets of values out of the Matrix . The function
getRow() returns a sequence of all the values in a row, whereas getColumn()
returns all the values in a given column. The function subMatrix() retrieves a
rectangular subset from the matrix based on starting row and column and ending
row and column. It returns a new Matrix . These functions are implemented in
Listing 12.26.
Listing 12.26
Matrix - getRow(), getColumn(), subMatrix()
/** get a row from the matrix */
public function getRow (row:Integer):Object[] {
var ndx = getIndex(row, 0);
sequence[ndx..<ndx+columns];
}
/** get a column from the matrix */
public function getColumn (col:Integer): Object[] {
var ndx = getIndex(0, col);
for(i in [ndx..<sizeof sequence step columns]) {
sequence[i];
}
}
/** get a sub matrix from this matrix */
public function subMatrix (startRow: Integer,
startColumn: Integer,
endRow:Integer,
endColumn:Integer): Matrix {
var ncols = endColumn - startColumn + 1;
var ndx = getIndex(startRow, startColumn);
var sub = for(row in [startRow..endRow]) {
var ndx1 = ndx;
ndx += columns;
sequence[ndx1..<ndx1+ncols];
};
continues
Search WWH ::




Custom Search