public class SparseHashMatrix extends AbstractMatrix implements SparseMatrix
SparseMatrix
backed by vectors that provide amortized O(1) access
to their elements. Each row is implemented using a hashing-based vector.
This class provides an alternate implementation to YaleSparseMatrix
;
this class potentially uses more memory than YaleSparseMatrix
, but
provides O(1) access instead of O(log(n)). The size of this matrix is fixed,
and attempts to access rows or columns beyond the size will throw an IndexOutOfBoundsException
.Matrix.Type
Constructor and Description |
---|
SparseHashMatrix(int rows,
int columns)
Constructs a sparse matrix with the specified dimensions.
|
Modifier and Type | Method and Description |
---|---|
int |
columns()
Returns the number of columns in this
Matrix . |
SparseDoubleVector |
getColumnVector(int column)
Returns the column as a vector.
|
SparseDoubleVector |
getRowVector(int row)
Returns a
DoubleVector for an entire row. |
int |
rows()
Returns the number of rows in this
Matrix . |
void |
set(int row,
int col,
double val)
Throws an
UnsupportedOperationException if called (matrix is
unmodifiable). |
equals, get, getColumn, getRow, hashCode, setColumn, setColumn, setRow, setRow, toDenseArray
public SparseHashMatrix(int rows, int columns)
public int columns()
Matrix
.columns
in interface Matrix
columns
in class AbstractMatrix
Matrix
.public SparseDoubleVector getColumnVector(int column)
SparseVector
instance.getColumnVector
in interface Matrix
getColumnVector
in interface SparseMatrix
getColumnVector
in class AbstractMatrix
column
- The column to return a DoubleVector
for.DoubleVector
representing the column at column
.public SparseDoubleVector getRowVector(int row)
DoubleVector
for an entire row. Implementations should
return an approriately typed DoubleVector. Whether updates to the vector
are written through to the backing matrix is left open to the specific
implementation. Implementations that maintain their data in a sparse
format are encouraged to return a SparseVector
instance.getRowVector
in interface Matrix
getRowVector
in interface SparseMatrix
getRowVector
in class AbstractMatrix
row
- the index of the row to return.DoubleVector
representing the row at row
.public int rows()
Matrix
.rows
in interface Matrix
rows
in class AbstractMatrix
Matrix
.public void set(int row, int col, double val)
UnsupportedOperationException
if called (matrix is
unmodifiable).set
in interface Matrix
set
in class AbstractMatrix
row
- The row of the cell to update.col
- The column of the cell to update.val
- The new value of the specified cell.Copyright © 2012. All Rights Reserved.