Package fr.uga.pddl4j.util
Class BitMatrix
java.lang.Object
fr.uga.pddl4j.util.BitMatrix
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SquareBitMatrix
This class implements a bit matrix. This class introspection mechanism not more allowed with jre version superior
to 1.8.
Revisions:
Revisions:
- 31.03.2020: Add a deep copy constructor.
- 26.06.2020: Change for bit vector intern representation.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a row at a specified index in the matrix.void
Adds a row at the end of the matrix.int
Returns the cardinality of the matrix, i.e., the number of bits set to 1 in the matrix.void
clear(int row, int col)
Sets the bit at a specified row and column position to false.int
columns()
Returns the number of columns of the matrix.boolean
Returnstrue
if this matrix is equals to an other object.boolean
get(int row, int col)
Returns the value of the bit at a specific position in the matrix.getColumn(int col)
Returns the jth column of the matrix.getRow(int row)
Returns the ith row of the matrix.int
hashCode()
Returns the hash code value of this matrix.void
removeColumn(int column)
Remove a column of the matrix.void
removeRow(int row)
Remove the jth row of the matrix.void
resize(int rows, int columns)
Resizes the matrix.int
rows()
Returns the number of rows of the matrix.void
set(int row, int col)
Sets the bit at a specified row and column position to true.void
set(int row, int col, boolean value)
Sets the bit at a specified row and column position to a specified value.Returns a string representation of the matrix based on bit representation.toString()
Returns a string representation of the matrix based on the bit vector representation.
-
Field Details
-
columns
public int columnsThe number of columns.
-
-
Constructor Details
-
BitMatrix
public BitMatrix(int rows, int columns)Creates a new bit matrix with a specified number of rows and columns.- Parameters:
rows
- The number of rows of the matrix.columns
- The number of column of the matrix.
-
BitMatrix
Creates a deep copy from an other matrix.- Parameters:
other
- The other matrix.
-
BitMatrix
public BitMatrix(int size)Creates a new squared matrix of a specific size.- Parameters:
size
- the size of the squared matrix.
-
-
Method Details
-
set
public final void set(int row, int col)Sets the bit at a specified row and column position to true.- Parameters:
row
- the row position.col
- the column position.
-
set
public final void set(int row, int col, boolean value)Sets the bit at a specified row and column position to a specified value.- Parameters:
row
- the row position.col
- the column position.value
- the value to set.
-
clear
public final void clear(int row, int col)Sets the bit at a specified row and column position to false.- Parameters:
row
- the row position.col
- the column position.
-
getRow
Returns the ith row of the matrix.- Parameters:
row
- the index of the row.- Returns:
- the ith row of the matrix.
-
removeRow
public final void removeRow(int row)Remove the jth row of the matrix.- Parameters:
row
- the index of the row to remove.
-
addRow
Adds a row at the end of the matrix.- Parameters:
row
- the row to add.
-
addRow
Adds a row at a specified index in the matrix.- Parameters:
index
- the index where the row must be added.row
- the row to add.
-
getColumn
Returns the jth column of the matrix.- Parameters:
col
- the index of the column.- Returns:
- the jth column of the matrix.
-
removeColumn
public final void removeColumn(int column)Remove a column of the matrix.- Parameters:
column
- the index of the column to remove.
-
get
public final boolean get(int row, int col)Returns the value of the bit at a specific position in the matrix.- Parameters:
row
- The row of the bit.col
- The column of the bit.- Returns:
- the value of the bit at a specific position in the matrix.
-
cardinality
public final int cardinality()Returns the cardinality of the matrix, i.e., the number of bits set to 1 in the matrix.- Returns:
- Returns the cardinality of the matrix.
-
columns
public final int columns()Returns the number of columns of the matrix.- Returns:
- the number of columns of the matrix.
-
rows
public final int rows()Returns the number of rows of the matrix.- Returns:
- the number of rows of the matrix.
-
resize
public final void resize(int rows, int columns)Resizes the matrix.- Parameters:
rows
- the new number of rows.columns
- the new number of columns.
-
equals
Returnstrue
if this matrix is equals to an other object.- Overrides:
equals
in classObject
- Parameters:
obj
- the object to compared.- Returns:
true
if this matrix is equals to an other object;false
otherwise.- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()Returns the hash code value of this matrix.- Overrides:
hashCode
in classObject
- Returns:
- the hash code value of this matrix.
- See Also:
Object.hashCode()
-
toString
Returns a string representation of the matrix based on the bit vector representation.- Overrides:
toString
in classObject
- Returns:
- a string representation of the matrix.
- See Also:
BitSet.toString()
-
toBitString
Returns a string representation of the matrix based on bit representation.- Returns:
- a string representation of the matrix.
-