org.mymedialite.datatype
Class SparseBooleanMatrix

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

public class SparseBooleanMatrix
extends java.lang.Object
implements IBooleanMatrix

Sparse representation of a boolean matrix, using HashSets. Fast row-wise access is possible. Indexes are zero-based. TODO Implement the classes below. If you need a more memory-efficient data structure, try SparseBooleanMatrixBinarySearch or SparseBooleanMatrixStatic.


Constructor Summary
SparseBooleanMatrix()
          Default constructor
 
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.
 java.lang.Boolean get(int x, int y)
          Get the value at (i,j)
 IntList getEntriesByColumn(int column_id)
          Takes O(N) worst-case time, where N is the number of rows, if the internal hash table can be queried in constant time.
 IntList getEntriesByRow(int row_id)
          Get all true entries (column IDs) of a row.
 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()
          Get 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)
 java.util.HashMap<java.lang.Integer,IntSet> nonEmptyRows()
          The non-empty rows of the matrix (the ones that contain at least one true entry), with their IDs.
 int numberOfColumns()
          Get the number of columns of the matrix.
 int numberOfEntries()
          Returns the number of (true) entries.
 int numberOfRows()
          Get the number of rows of 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)
 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
 

Constructor Detail

SparseBooleanMatrix

public SparseBooleanMatrix()
Default constructor

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)
Get a row.

Specified by:
get in interface IBooleanMatrix
Parameters:
x - the row ID
Returns:
the 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) worst-case time, where N is the number of rows, if the internal hash table can be queried in constant time.

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

nonEmptyRows

public java.util.HashMap<java.lang.Integer,IntSet> nonEmptyRows()
The non-empty rows of the matrix (the ones that contain at least one true entry), with their IDs.

Returns:
The non-empty rows of the matrix (the ones that contain at least one true entry), with their IDs

nonEmptyRowIDs

public IntCollection nonEmptyRowIDs()
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()
Get 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()
Description copied from interface: IMatrix
Get the number of rows of the matrix.

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

numberOfColumns

public int numberOfColumns()
Description copied from interface: IMatrix
Get the number of columns of the matrix.

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

numberOfEntries

public int numberOfEntries()
Returns the number of (true) entries.

Specified by:
numberOfEntries in interface IBooleanMatrix

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 (copy)

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