public class BinaryMatrix extends Object implements Cloneable, Comparable<BinaryMatrix>
IntSet but for pairs of ints, that is a binary matrixIntSet| Modifier and Type | Class and Description |
|---|---|
static interface |
BinaryMatrix.CellIterator
An
Iterator-like interface |
| Constructor and Description |
|---|
BinaryMatrix(IntSet template)
Creates an empty matrix.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int row,
int col)
Adds the specified cell to this matrix if it is not already present.
|
boolean |
addAll(BinaryMatrix other)
Adds all of the cells in the specified collection to this matrix if
they're not already present.
|
boolean |
addAll(int row,
IntSet cols)
Adds the specified cells to this matrix, if not already present.
|
boolean |
addAll(IntSet rowSet,
int col)
Adds the specified cells to this matrix, if not already present.
|
boolean |
addAll(IntSet rowSet,
IntSet colSet)
Adds the specified cells to this matrix, if not already present.
|
double |
bitmapCompressionRatio()
|
void |
clear()
Removes all of the cells from this matrix.
|
void |
clear(int fromRow,
int fromCol,
int toRow,
int toCol)
Removes from the set all the cells of the specified sub-matrix, both
corners included.
|
BinaryMatrix |
clone()
See the
clone() of Object |
double |
collectionCompressionRatio()
|
int |
compareTo(BinaryMatrix o) |
void |
complement()
Complements the current matrix.
|
BinaryMatrix |
complemented()
Generates the complement matrix, namely flipping all the cells.
|
int |
complementSize()
Computes the complement set size.
|
boolean |
contains(int row,
int col)
Returns true if this set contains the specified cell.
|
boolean |
containsAll(BinaryMatrix other)
Returns true if this matrix contains all of the cells of the
specified collection.
|
boolean |
containsAll(int row,
IntSet colSet)
Returns true if this matrix contains all of the cells of the
specified collection.
|
boolean |
containsAll(IntSet rowSet,
int col)
Returns true if this matrix contains all of the cells of the
specified collection.
|
boolean |
containsAll(IntSet rowSet,
IntSet colSet)
Returns true if this matrix contains all of the cells of the
specified collection.
|
boolean |
containsAny(BinaryMatrix other)
Returns
true if the specified BinaryMatrix instance
contains any cell that is also contained within this BinaryMatrix
instance |
boolean |
containsAtLeast(BinaryMatrix other,
int minCells)
Returns
true if the specified BinaryMatrix instance
contains at least minElements cells that are also contained
within this BinaryMatrix instance |
BinaryMatrix |
convert(boolean[][] a)
Converts a given matrix of boolean n x m into an instance
of the current class.
|
String |
debugInfo()
Prints debug info about the given
BinaryMatrix implementation |
BinaryMatrix.CellIterator |
descendingIterator() |
BinaryMatrix |
difference(BinaryMatrix other)
Generates the difference matrix
|
int |
differenceSize(BinaryMatrix other)
Computes the difference matrix size.
|
BinaryMatrix |
empty()
Generates an empty matrix of the same dimension
|
IntSet |
emptyRow() |
boolean |
equals(Object obj) |
void |
fill(int fromRow,
int fromCol,
int toRow,
int toCol)
Adds to the matrix all the cells of the specified sub-matrix, both
corners included.
|
int[] |
first()
Returns the first (lowest) cell currently in this set.
|
void |
flip(int row,
int col)
Adds the cell if it not existing, or removes it if existing
|
int[] |
get(int i)
Gets the
ith cell of the matrix. |
IntSet |
getCol(int col)
Gets a copy of the column with the given index
|
IntSet |
getRow(int row)
Gets a copy of the row with the given index
|
int |
hashCode() |
int |
indexOf(int row,
int col)
Provides position of cell within the matrix.
|
BinaryMatrix |
intersection(BinaryMatrix other)
Generates the intersection matrix
|
int |
intersectionSize(BinaryMatrix other)
Computes the intersection matrix size.
|
IntSet |
involvedCols() |
IntSet |
involvedRows() |
boolean |
isEmpty() |
BinaryMatrix.CellIterator |
iterator() |
int[] |
last()
Returns the last (highest) cell currently in this set.
|
int |
maxCol() |
int |
maxRow() |
boolean |
remove(int row,
int col)
Removes the specified cell from this matrix if it is present.
|
boolean |
removeAll(BinaryMatrix other)
Removes from this matrix all of its cells that are contained in the
specified collection.
|
boolean |
removeAll(int row,
IntSet cols)
Removes the specified cells from this matrix.
|
boolean |
removeAll(IntSet rowSet,
int col)
Removes the specified cells from this matrix.
|
boolean |
removeAll(IntSet rowSet,
IntSet colSet)
Removes the specified cells from this matrix.
|
boolean |
retainAll(BinaryMatrix other)
Retains only the cells in this matrix that are contained in the specified
collection.
|
boolean |
retainAll(int row,
IntSet cols)
Retains the specified cells from this matrix.
|
boolean |
retainAll(IntSet rowSet,
int col)
Removes the specified cells from this matrix.
|
boolean |
retainAll(IntSet rowSet,
IntSet colSet)
Removes the specified cells from this matrix.
|
int |
size() |
BinaryMatrix |
symmetricDifference(BinaryMatrix other)
Generates the symmetric difference matrix
|
int |
symmetricDifferenceSize(BinaryMatrix other)
Computes the symmetric difference matrix size.
|
boolean[][] |
toArray() |
boolean[][] |
toArray(boolean[][] a)
Returns an array containing all of the cells in this matrix.
|
String |
toString()
Generates an ASCII-art matrix representation
|
BinaryMatrix |
transposed()
Generated a transposed matrix
|
BinaryMatrix |
union(BinaryMatrix other)
Generates the union matrix
|
int |
unionSize(BinaryMatrix other)
Computes the union matrix size.
|
public BinaryMatrix(IntSet template)
IntSet instance must be used to internally
represent rows.template - IntSet instance to create empty rowspublic BinaryMatrix intersection(BinaryMatrix other)
other - BinaryMatrix instance that represents the right
operandretainAll(BinaryMatrix)public BinaryMatrix union(BinaryMatrix other)
other - BinaryMatrix instance that represents the right
operandaddAll(BinaryMatrix)public BinaryMatrix difference(BinaryMatrix other)
other - BinaryMatrix instance that represents the right
operandremoveAll(BinaryMatrix)public BinaryMatrix symmetricDifference(BinaryMatrix other)
other - BinaryMatrix instance that represents the right
operandflip(int, int)public BinaryMatrix complemented()
complement()public void complement()
complemented()public boolean containsAny(BinaryMatrix other)
true if the specified BinaryMatrix instance
contains any cell that is also contained within this BinaryMatrix
instanceother - BinaryMatrix to intersect withBinaryMatrix intersects
the specified BinaryMatrix.public boolean containsAtLeast(BinaryMatrix other, int minCells)
true if the specified BinaryMatrix instance
contains at least minElements cells that are also contained
within this BinaryMatrix instanceother - BinaryMatrix instance to intersect withminCells - minimum number of cells to be contained within this
BinaryMatrix instanceBinaryMatrix intersects
the specified BinaryMatrix.IllegalArgumentException - if minElements < 1public int intersectionSize(BinaryMatrix other)
This is faster than calling intersection(BinaryMatrix) and then
size()
other - BinaryMatrix instance that represents the right
operandpublic int unionSize(BinaryMatrix other)
This is faster than calling union(BinaryMatrix) and then
size()
other - BinaryMatrix instance that represents the right
operandpublic int symmetricDifferenceSize(BinaryMatrix other)
This is faster than calling symmetricDifference(BinaryMatrix)
and then size()
other - BinaryMatrix instance that represents the right
operandpublic int differenceSize(BinaryMatrix other)
This is faster than calling difference(BinaryMatrix) and then
size()
other - BinaryMatrix instance that represents the right
operandpublic int complementSize()
This is faster than calling complemented() and then
size()
public BinaryMatrix empty()
public BinaryMatrix clone()
clone() of Objectpublic double bitmapCompressionRatio()
BitSet, 2 means twice the size of BitSet, etc.)public double collectionCompressionRatio()
ArrayList, 2 means twice the size of ArrayList, etc.)public BinaryMatrix.CellIterator iterator()
BinaryMatrix.CellIterator instance to iterate over the matrixpublic BinaryMatrix.CellIterator descendingIterator()
BinaryMatrix.CellIterator instance to iterate over the matrix in
descending orderpublic String debugInfo()
BinaryMatrix implementationpublic void fill(int fromRow,
int fromCol,
int toRow,
int toCol)
fromRow - first row of the sub-matrixfromCol - first column of the sub-matrixtoRow - last row of the sub-matrixtoCol - last column of the sub-matrixpublic void clear(int fromRow,
int fromCol,
int toRow,
int toCol)
fromRow - first row of the sub-matrixfromCol - first column of the sub-matrixtoRow - last row of the sub-matrixtoCol - last column of the sub-matrixpublic void flip(int row,
int col)
row - row of the cell to flipcol - column of the cell to flipsymmetricDifference(BinaryMatrix)public int[] get(int i)
ith cell of the matrix.
IMPORTANT: each call returns an array of two elements, where the
first element is the row, while the second element is the column of the
current cell. In order to reduce the produced heap garbage, there is only
one array instantiated for each BinaryMatrix instance,
whose content is overridden at each method call.i - position of the cell in the sorted matrixith cell of the matrix, as a pair
<row,column>IndexOutOfBoundsException - if i is less than zero, or greater or equal to
size()public int indexOf(int row,
int col)
It returns -1 if the cell does not exist within the set.
row - row of the cellcol - column of the cellpublic BinaryMatrix convert(boolean[][] a)
a - array to use to generate the new instancepublic int[] first()
BinaryMatrix instance, whose content is
overridden at each method call.NoSuchElementException - if this set is emptypublic int[] last()
BinaryMatrix instance, whose content is
overridden at each method call.NoSuchElementException - if this set is emptypublic int size()
public boolean isEmpty()
public boolean contains(int row,
int col)
row - row of the cellcol - column of the cellpublic boolean add(int row,
int col)
row - row of the cellcol - column of the cellIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean addAll(int row,
IntSet cols)
row - index of the rowcols - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean addAll(IntSet rowSet, int col)
rowSet - indices of the rowscol - index of the columnIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean addAll(IntSet rowSet, IntSet colSet)
rowSet - indices of the rowscolSet - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean remove(int row,
int col)
row - row of the cellcol - column of the cellUnsupportedOperationException - if the remove operation is not supported by this
matrixpublic boolean removeAll(int row,
IntSet cols)
row - index of the rowcols - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
removed from this matrixpublic boolean removeAll(IntSet rowSet, int col)
rowSet - indices of the rowscol - index of the columnIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean removeAll(IntSet rowSet, IntSet colSet)
rowSet - indices of the rowscolSet - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean retainAll(int row,
IntSet cols)
row - index of the rowcols - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
removed from this matrixpublic boolean retainAll(IntSet rowSet, int col)
rowSet - indices of the rowscol - index of the columnIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean retainAll(IntSet rowSet, IntSet colSet)
rowSet - indices of the rowscolSet - indices of the columnsIllegalArgumentException - if some property of the specified cell prevents it from being
added to this matrixpublic boolean containsAll(BinaryMatrix other)
other - matrix to be checked for containment in this matrixNullPointerException - if the specified collection contains one or more null cells
and this matrix does not permit null cells (optional), or if
the specified collection is nullcontains(int, int)public boolean containsAll(IntSet rowSet, IntSet colSet)
rowSet - indices of the rowscolSet - indices of the columnspublic boolean containsAll(int row,
IntSet colSet)
row - index of the rowcolSet - indices of the columnspublic boolean containsAll(IntSet rowSet, int col)
rowSet - indices of the rowscol - index of the columnpublic boolean addAll(BinaryMatrix other)
other - matrix containing cells to be added to this matrixNullPointerException - if the specified collection contains one or more null cells
and this matrix does not permit null cells, or if the
specified collection is nullIllegalArgumentException - if some property of an cell of the specified collection
prevents it from being added to this matrixadd(int, int)public boolean retainAll(BinaryMatrix other)
other - matrix containing cells to be retained in this matrixNullPointerException - if this matrix contains a null cell and the specified
collection does not permit null cells (optional), or if the
specified collection is nullremove(int, int)public boolean removeAll(BinaryMatrix other)
other - matrix containing cells to be removed from this matrixNullPointerException - if this matrix contains a null cell and the specified
collection does not permit null cells (optional), or if the
specified collection is nullremove(int, int),
contains(int, int)public void clear()
UnsupportedOperationException - if the clear method is not supported by this matrixpublic boolean[][] toArray()
public boolean[][] toArray(boolean[][] a)
If this matrix fits in the specified array with room to spare (i.e., the array has more cells than this matrix), the cell in the array immediately following the end of the matrix are left unchanged.
a - the array into which the cells of this matrix are to be
stored.NullPointerException - if the specified array is nullIllegalArgumentException - if this matrix does not fit in the specified arraypublic int compareTo(BinaryMatrix o)
compareTo in interface Comparable<BinaryMatrix>public IntSet getRow(int row)
row - the row indexpublic IntSet getCol(int col)
col - the column indexpublic BinaryMatrix transposed()
public String toString()
public int maxRow()
public int maxCol()
public IntSet involvedRows()
public IntSet involvedCols()
Copyright © 2016. All rights reserved.