25package umontreal.ssj.util;
27import java.io.Serializable;
36public class BitMatrix implements Serializable, Cloneable {
38 static final long serialVersionUID = 2472769969919959608L;
52 for (
int i = 0; i < r; i++)
66 for (
int i = 0; i < rows.length; i++)
69 this.c = r > 0 ? rows[0].size() : 0;
85 for (
int i = 0; i < r; i++)
100 for (
int i = 0; i < this.r; i++)
101 this.rows[i] =
new BitVector(that.rows[i]);
113 for (
int i = 0; i < rows.length; i++)
116 }
catch (CloneNotSupportedException e) {
117 IllegalStateException ne =
new IllegalStateException();
131 if (this.r != that.r ||
this.c != that.c)
133 for (
int i = 0; i < r; i++)
134 if (!this.rows[i].
equals(that.rows[i]))
148 StringBuffer sb =
new StringBuffer();
155 for (
int i = 0; i < rows.length - 1; i++) {
156 for (
int j = 0; j < rows[i].size(); j++)
157 sb.append(rows[i].getBool(j) ?
"1" :
"0");
161 for (
int j = 0; j < c; j++)
162 sb.append(rows[r - 1].getBool(j) ?
"1" :
"0");
167 return sb.toString();
180 StringBuffer sb =
new StringBuffer();
183 for (
int i = 0; i < r; i++) {
185 for (
int j = 0; j < (c + 31) / 32; j++) {
186 sb.append(rows[i].getInt(j));
187 if (j != (c - 1) / 32)
196 return sb.toString();
229 if (row >= r || column >= c)
230 throw new IndexOutOfBoundsException();
232 return rows[row].getBool(column);
245 public void setBool(
int row,
int column,
boolean value) {
246 if (row >= r || column >= c)
247 throw new IndexOutOfBoundsException();
249 rows[row].setBool(column, value);
260 for (
int i = 0; i < r; i++)
261 for (
int j = 0; j < c; j++)
262 result.rows[j].
setBool(i, rows[i].getBool(j));
276 for (
int i = 0; i < r; i++)
293 if (this.c != that.c ||
this.r != that.r)
295 +
"x" + this.c +
" matrix " +
"while that is a " + that.r +
"x" + that.c +
" matrix.");
297 for (
int i = 0; i < r; i++)
298 result.rows[i].
selfAnd(that.rows[i]);
314 if (this.c != that.c ||
this.r != that.r)
316 +
"x" + this.c +
" matrix " +
"while that is a " + that.r +
"x" + that.c +
" matrix.");
318 for (
int i = 0; i < r; i++)
319 result.rows[i].
selfOr(that.rows[i]);
335 if (this.c != that.c ||
this.r != that.r)
337 +
"x" + this.c +
" matrix " +
"while that is a " + that.r +
"x" + that.c +
" matrix.");
339 for (
int i = 0; i < r; i++)
340 result.rows[i].
selfXor(that.rows[i]);
355 for (
int i = 0; i < r; i++)
356 res.
setBool(i, rows[i].scalarProduct(vect));
390 if (this.c != that.r)
392 +
") must be equal to the number of rows of that (" + that.r +
").");
410 for (
int i = 0; i < res.r; i++)
411 for (
int j = 0; j < res.c; j++)
413 res.rows[i].
selfXor(that.rows[j]);
432 throw new IllegalArgumentException(
"Only non-negative powers are accepted.");
437 for (
int i = 0; i < r; i++)
465 for (
int i = 0; i < e; i++)
479 public class IncompatibleDimensionException
extends RuntimeException {
480 private IncompatibleDimensionException() {
484 private IncompatibleDimensionException(String message) {
Runtime exception raised when the dimensions of the BitMatrix are not appropriate for the operation.
BitMatrix(BitMatrix that)
Copy constructor.
BitMatrix power(long p)
Raises the BitMatrix to the power p.
BitMatrix(int r, int c)
Creates a new BitMatrix with r rows and c columns filled with 0’s.
String printData()
Creates a String containing all the data of the BitMatrix.
Object clone()
Creates a copy of the BitMatrix.
int numColumns()
Returns the number of columns of the BitMatrix.
boolean equals(BitMatrix that)
Verifies that this and that are strictly identical.
void setBool(int row, int column, boolean value)
Changes the value of the bit in the specified row and column.
int numRows()
Returns the number of rows of the BitMatrix.
BitVector multiply(BitVector vect)
Multiplies the column BitVector by a BitMatrix and returns the result.
BitMatrix power2e(int e)
Raises the BitMatrix to power .
BitMatrix(BitVector[] rows)
Creates a new BitMatrix using the data in rows.
BitMatrix not()
Returns the BitMatrix resulting from the application of the not operator on the original BitMatrix.
BitMatrix(int[][] data, int r, int c)
Creates a new BitMatrix with r rows and c columns using the data in data.
BitMatrix xor(BitMatrix that)
Returns the BitMatrix resulting from the application of the xor operator on the original BitMatrix an...
BitMatrix multiply(BitMatrix that)
Multiplies two BitMatrix’s together.
String toString()
Creates a String containing all the data of the BitMatrix.
boolean getBool(int row, int column)
Returns the value of the bit in the specified row and column.
int multiply(int vect)
Multiplies vect, seen as a column BitVector, by a BitMatrix.
BitMatrix or(BitMatrix that)
Returns the BitMatrix resulting from the application of the or operator on the original BitMatrix and...
BitMatrix and(BitMatrix that)
Returns the BitMatrix resulting from the application of the and operator on the original BitMatrix an...
BitMatrix transpose()
Returns the transposed matrix.
This class implements vectors of bits and the operations needed to use them.
int getInt(int pos)
Returns an int containing all the bits in the interval.
BitVector selfNot()
Applies the not operator on the current BitVector and returns it.
BitVector selfXor(BitVector that)
Applies the xor operator on this with that.
void setBool(int pos, boolean value)
Sets the value of the bit in position pos.
BitVector selfOr(BitVector that)
Applies the or operator on this with that.
BitVector selfAnd(BitVector that)
Applies the and operator on this with that.