|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprocope.tools.SparseMatrixInt
public class SparseMatrixInt
Implementation of a matrix (2-dimensional array) of integers. Optimized for sparse matrices, i.e. only relatively few values in the matrix actually have a value.
This implementation reduces the space complexity of a matrix with n*n elements from O(n2) to O(l), where l is the number of nonzero items in the matrix.
Constructor Summary | |
---|---|
SparseMatrixInt(boolean symmetrical)
Creates an empty matrix |
Method Summary | |
---|---|
void |
add(int x,
int y,
int value)
Increase the value of a given cell. |
int |
get(int x,
int y)
Retrieves a value from the matrix. |
int |
getElementCount()
Returns the number of elements set in this matrix |
List<Integer> |
getFirstIndices()
Get the list of indices which are set as a first index |
int[] |
getNeighbors(int first)
Return array of items which have a value associated with the given index |
int[] |
getValues(int first)
Return array of values associated with a given index. |
int |
set(int x,
int y,
int value)
Set a cell in the matrix to a given value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SparseMatrixInt(boolean symmetrical)
symmetrical
- if true
, the values (a,b)
and
(b,a)
will always be equal and only
consume memory onceMethod Detail |
---|
public int set(int x, int y, int value)
x
- first indexy
- second indexvalue
- value
Integer.MIN_VALUE
if the
cell was not set beforepublic int get(int x, int y)
x
- first indexy
- second index
Integer.MIN_VALUE
if the cell is
not setpublic void add(int x, int y, int value)
x
- first indexy
- second indexvalue
- value by which the cell will be increased, can be negativepublic int getElementCount()
public List<Integer> getFirstIndices()
public int[] getNeighbors(int first)
first
- index for which to retrieve neighbors
public int[] getValues(int first)
getNeighbors(int)
.
first
- index for which to retrieve values
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |