public class BitVector
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
All bit operations are present in two forms: a normal form and a self form. The normal form returns a newly created object containing the result, while the self form puts the result in the calling object (this). The return value of the self form is the calling object itself. This is done to allow easier manipulation of the results, making it possible to chain operations.
| Constructor and Description |
|---|
BitVector(BitVector that)
Creates a copy of the BitVector that.
|
BitVector(int length)
Creates a new BitVector of length length with
all its bits set to 0.
|
BitVector(int[] vect)
Creates a new BitVector using the data in vect.
|
BitVector(int[] vect,
int length)
Creates a new BitVector of length length using
the data in vect.
|
| Modifier and Type | Method and Description |
|---|---|
BitVector |
and(BitVector that)
Returns a BitVector which is the result of the and
operator with both the this and that BitVector's.
|
java.lang.Object |
clone()
Creates a copy of the BitVector.
|
void |
enlarge(int size)
Resizes the BitVector so that its length is equal
to size.
|
void |
enlarge(int size,
boolean filling)
Resizes the BitVector so that its length is equal
to size.
|
boolean |
equals(BitVector that)
Verifies if two BitVector's have the same length and
the same data.
|
boolean |
getBool(int pos)
Gives the value of the bit in position pos.
|
int |
getInt(int pos)
Returns an int containing all the bits in the interval
[pos×32,pos×32 + 31].
|
BitVector |
not()
Returns a BitVector which is the result of the not
operator on the current BitVector.
|
BitVector |
or(BitVector that)
Returns a BitVector which is the result of the or
operator with both the this and that BitVector's.
|
boolean |
scalarProduct(BitVector that)
Returns the scalar product of two BitVector's modulo 2.
|
BitVector |
selfAnd(BitVector that)
Applies the and operator on this with that.
|
BitVector |
selfNot()
Applies the not operator on the current BitVector
and returns it.
|
BitVector |
selfOr(BitVector that)
Applies the or operator on this with that.
|
BitVector |
selfShift(int j)
Shift all the bits of the current BitVector j
positions to the right if j is positive, and j positions
to the left if j is negative.
|
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 |
shift(int j)
Returns a BitVector equal to the original with
all the bits shifted j positions to the right if j is
positive, and shifted j positions to the left if j is negative.
|
int |
size()
Returns the length of the BitVector.
|
java.lang.String |
toString()
Returns a string containing all the bits of the BitVector,
starting with the highest order bit and finishing with the lowest order bit.
|
BitVector |
xor(BitVector that)
Returns a BitVector which is the result of the xor
operator applied on this and that.
|
public BitVector(int length)
length - the length of the BitVectorpublic BitVector(int[] vect,
int length)
vect - the bits datalength - the length of the vectorjava.lang.IllegalArgumentException - when the length of vect is
not compatible with the length providedpublic BitVector(int[] vect)
vect - the bits datapublic BitVector(BitVector that)
that - the BitVector to copypublic java.lang.Object clone()
clone in class java.lang.Objectpublic boolean equals(BitVector that)
that - the other BitVector to compare topublic int size()
public void enlarge(int size,
boolean filling)
size - the new size of the BitVectorfilling - the state of the new bitspublic void enlarge(int size)
size - the new size of the BitVectorpublic boolean getBool(int pos)
pos - the position of the checked bitjava.lang.ArrayIndexOutOfBoundsException - if pos is outside
the range of the BitVectorpublic void setBool(int pos,
boolean value)
pos - the position of the bit to modifyvalue - the new value of the bit as a booleanjava.lang.ArrayIndexOutOfBoundsException - if pos is outside
the range of the BitVectorpublic int getInt(int pos)
pos - the selected positionjava.lang.ArrayIndexOutOfBoundsException - if pos is outside
the range of the BitVectorpublic java.lang.String toString()
toString in class java.lang.Objectpublic BitVector not()
~ operator in Java and thus swap all bits (bits
previously set to 0 become 1 and bits previously set to 1 become 0).public BitVector selfNot()
public BitVector xor(BitVector that)
^ operator in Java. All bits which were set to 0 in
one of the vector and to 1 in the other vector are set to 1. The others
are set to 0. This is equivalent to the addition in modulo 2 arithmetic.that - the second operand to the xor operatorpublic BitVector selfXor(BitVector that)
that - the second operand to the xor operatorpublic BitVector and(BitVector that)
& operator in Java. Only
bits which are set to 1 in both this and that are set to 1
in the result, all the others are set to 0.that - the second operand to the and operatorpublic BitVector selfAnd(BitVector that)
that - the second operand to the and operatorpublic BitVector or(BitVector that)
that - the second operand to the or operatorpublic BitVector selfOr(BitVector that)
that - the second operand to the or operatorpublic BitVector shift(int j)
j - the size of the shiftpublic BitVector selfShift(int j)
j - the size of the shiftpublic boolean scalarProduct(BitVector that)
that - the other BitVector with which to do the scalar productTo submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.