org.mymedialite.datatype
Class SparseBooleanMatrixStatic

java.lang.Object
  extended by org.mymedialite.datatype.SparseBooleanMatrixStatic
All Implemented Interfaces:
IBooleanMatrix, IMatrix<java.lang.Boolean>

public class SparseBooleanMatrixStatic
extends java.lang.Object
implements IBooleanMatrix

Sparse representation of a boolean matrix, using binary search (memory efficient). This data structure is static, which means that rows are represented as int arrays, a can be assigned, but not modified. Fast row-wise access is possible. Indexes are zero-based.


Field Summary
protected  java.util.List<int[]> row_list
          Internal representation of this data: list of rows.
 
Constructor Summary
SparseBooleanMatrixStatic()
           
 
Method Summary
 IMatrix<java.lang.Boolean> createMatrix(int x, int y)
          Create a matrix with a given number of rows and columns.
 IntSet get(int x)
          Get a row of the matrix.
 java.lang.Boolean get(int x, int y)
          Get the value at (i,j)
 IntList getEntriesByColumn(int column_id)
          Takes O(N log(M)) worst-case time, where N is the number of rows and M is the number of columns.
 IntList getEntriesByRow(int row_id)
          Get all true entries (column IDs) of a row.
 java.util.List<Pair<java.lang.Integer,int[]>> getNonEmptyRows()
          The non-empty rows of the matrix (the ones that contain at least one true entry), with their IDs.
 void grow(int num_rows, int num_cols)
          Grows the matrix to the requested size, if necessary.
 boolean isSymmetric()
          True if the matrix is symmetric, false otherwise.
 IntCollection nonEmptyColumnIDs()
          The IDs of the non-empty columns in the matrix (the ones that contain at least one true entry).
 IntCollection nonEmptyRowIDs()
          The IDs of the non-empty rows in the matrix (the ones that contain at least one true entry).
 int numberOfColumns()
          The number of columns in the matrix.
 int numberOfEntries()
          The number of (true) entries.
 int numberOfRows()
          The number of rows in the matrix.
 int numEntriesByColumn(int column_id)
          Get all the number of entries in a column.
 int numEntriesByRow(int row_id)
          Get all the number of entries in a row.
 int overlap(IBooleanMatrix s)
          Get the overlap of two matrices, i.e.
 void set(int x, int y, java.lang.Boolean value)
          Set the value at (i,j)
 void setRow(int x, int[] row)
           
 IMatrix<java.lang.Boolean> transpose()
          Get the transpose of the matrix, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row_list

protected java.util.List<int[]> row_list
Internal representation of this data: list of rows.

Constructor Detail

SparseBooleanMatrixStatic

public SparseBooleanMatrixStatic()
Method Detail

get

public java.lang.Boolean get(int x,
                             int y)
Description copied from interface: IMatrix
Get the value at (i,j)

Specified by:
get in interface IMatrix<java.lang.Boolean>
Parameters:
x - the row ID
y - the column ID
Returns:
the value at (i,j)

set

public void set(int x,
                int y,
                java.lang.Boolean value)
Description copied from interface: IMatrix
Set the value at (i,j)

Specified by:
set in interface IMatrix<java.lang.Boolean>
Parameters:
x - the row ID
y - the column ID
value - the value

get

public IntSet get(int x)
Description copied from interface: IBooleanMatrix
Get a row of the matrix.

Specified by:
get in interface IBooleanMatrix
Parameters:
x - the row ID

setRow

public void setRow(int x,
                   int[] row)

isSymmetric

public boolean isSymmetric()
Description copied from interface: IMatrix
True if the matrix is symmetric, false otherwise.

Specified by:
isSymmetric in interface IMatrix<java.lang.Boolean>
Returns:
true if the matrix is symmetric, false otherwise

createMatrix

public IMatrix<java.lang.Boolean> createMatrix(int x,
                                               int y)
Description copied from interface: IMatrix
Create a matrix with a given number of rows and columns.

Specified by:
createMatrix in interface IMatrix<java.lang.Boolean>
Parameters:
x - the number of rows
y - the number of columns
Returns:
a matrix with num_rows rows and num_column columns

getEntriesByRow

public IntList getEntriesByRow(int row_id)
Description copied from interface: IBooleanMatrix
Get all true entries (column IDs) of a row.

Specified by:
getEntriesByRow in interface IBooleanMatrix
Parameters:
row_id - the row ID
Returns:
a list of column IDs

numEntriesByRow

public int numEntriesByRow(int row_id)
Description copied from interface: IBooleanMatrix
Get all the number of entries in a row.

Specified by:
numEntriesByRow in interface IBooleanMatrix
Parameters:
row_id - the row ID
Returns:
the number of entries in row row_id

getEntriesByColumn

public IntList getEntriesByColumn(int column_id)
Takes O(N log(M)) worst-case time, where N is the number of rows and M is the number of columns.

Specified by:
getEntriesByColumn in interface IBooleanMatrix
Parameters:
column_id - the column ID
Returns:
a list of row IDs

numEntriesByColumn

public int numEntriesByColumn(int column_id)
Description copied from interface: IBooleanMatrix
Get all the number of entries in a column.

Specified by:
numEntriesByColumn in interface IBooleanMatrix
Parameters:
column_id - the column ID
Returns:
the number of entries in column column_id

getNonEmptyRows

public java.util.List<Pair<java.lang.Integer,int[]>> getNonEmptyRows()
The non-empty rows of the matrix (the ones that contain at least one true entry), with their IDs.


nonEmptyRowIDs

public IntCollection nonEmptyRowIDs()
Description copied from interface: IBooleanMatrix
The IDs of the non-empty rows in the matrix (the ones that contain at least one true entry).

Specified by:
nonEmptyRowIDs in interface IBooleanMatrix

nonEmptyColumnIDs

public IntCollection nonEmptyColumnIDs()
Description copied from interface: IBooleanMatrix
The IDs of the non-empty columns in the matrix (the ones that contain at least one true entry).

Specified by:
nonEmptyColumnIDs in interface IBooleanMatrix

numberOfRows

public int numberOfRows()
The number of rows in the matrix.

Specified by:
numberOfRows in interface IMatrix<java.lang.Boolean>
Returns:
The number of rows in the matrix

numberOfColumns

public int numberOfColumns()
The number of columns in the matrix.

Specified by:
numberOfColumns in interface IMatrix<java.lang.Boolean>
Returns:
The number of columns in the matrix

numberOfEntries

public int numberOfEntries()
The number of (true) entries.

Specified by:
numberOfEntries in interface IBooleanMatrix
Returns:
The number of (true) entries

grow

public void grow(int num_rows,
                 int num_cols)
Description copied from interface: IMatrix
Grows the matrix to the requested size, if necessary. The new entries are filled with zeros.

Specified by:
grow in interface IMatrix<java.lang.Boolean>
Parameters:
num_rows - the minimum number of rows
num_cols - the minimum number of columns

transpose

public IMatrix<java.lang.Boolean> transpose()
Get the transpose of the matrix, i.e. a matrix where rows and columns are interchanged.

Specified by:
transpose in interface IMatrix<java.lang.Boolean>
Returns:
the transpose of the matrix

overlap

public int overlap(IBooleanMatrix s)
Description copied from interface: IBooleanMatrix
Get the overlap of two matrices, i.e. the number of true entries where they agree.

Specified by:
overlap in interface IBooleanMatrix
Parameters:
s - the to compare to
Returns:
the number of entries that are true in both matrices