SSJ
V. labo.

umontreal.iro.lecuyer.util
Class BitVector

java.lang.Object
  extended by umontreal.iro.lecuyer.util.BitVector
All Implemented Interfaces:
Serializable, Cloneable

public class BitVector
extends Object
implements Serializable, Cloneable

BitVector

This class implements vectors of bits and the operations needed to use them. The vectors can be of arbitrary length. The operations provided are all the binary operations available to the int and long primitive types in Java.

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.

See Also:
Serialized Form

Constructor Summary
BitVector(BitVector that)
          .
BitVector(int length)
          .
BitVector(int[] vect)
          .
BitVector(int[] vect, int length)
          .
 
Method Summary
 BitVector and(BitVector that)
          .
 Object clone()
          .
 void enlarge(int size)
          .
 void enlarge(int size, boolean filling)
          .
 boolean equals(BitVector that)
          .
 boolean getBool(int pos)
          .
 int getInt(int pos)
          .
 BitVector not()
          .
 BitVector or(BitVector that)
          .
 boolean scalarProduct(BitVector that)
          .
 BitVector selfAnd(BitVector that)
          .
 BitVector selfNot()
          .
 BitVector selfOr(BitVector that)
          .
 BitVector selfShift(int j)
          .
 BitVector selfXor(BitVector that)
          .
 void setBool(int pos, boolean value)
          .
 BitVector shift(int j)
          .
 int size()
          .
 String toString()
          .
 BitVector xor(BitVector that)
          .
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitVector

public BitVector(int length)
. \begin{tabb}Creates a new \texttt{BitVector} of length \texttt{length} with
 all its bits set to 0.
 \end{tabb}
lengththe length of the BitVector


BitVector

public BitVector(int[] vect,
                 int length)
. \begin{tabb}Creates a new \texttt{BitVector} of length \texttt{length} using
 th...
 ...rder bit).
 Note that the sign bit is used as the largest order bit.
 \end{tabb}
vectthe bits data lengththe length of the vector IllegalArgumentExceptionwhen the length of vect is not compatible with the length provided


BitVector

public BitVector(int[] vect)
. \begin{tabb}Creates a new \texttt{BitVector} using the data in \texttt{vect}.
 T...
 ...itVector} is always equals to 32 times the
 length of \texttt{vect}.
 \end{tabb}
vectthe bits data


BitVector

public BitVector(BitVector that)
. \begin{tabb}Creates a copy of the \texttt{BitVector that}.
 \end{tabb}
thatthe BitVector to copy

Method Detail

clone

public Object clone()
. \begin{tabb}Creates a copy of the \texttt{BitVector}.
 \end{tabb}
a deep copy of the BitVector

Overrides:
clone in class Object

equals

public boolean equals(BitVector that)
. \begin{tabb}Verifies if two \texttt{BitVector}'s have the same length and
 the same data.
 \end{tabb}
thatthe other BitVector to compare to if the two BitVector's are identiqual


size

public int size()
. \begin{tabb}Returns the length of the \texttt{BitVector}.
 \end{tabb}
the length of the BitVector


enlarge

public void enlarge(int size,
                    boolean filling)
. \begin{tabb}Resizes the \texttt{BitVector} so that its length is equal
 to \text...
 ...alue 1 if \texttt{filling} is set to
 \texttt{true} and 0 otherwise.
 \end{tabb}
sizethe new size of the BitVector fillingthe state of the new bits


enlarge

public void enlarge(int size)
. \begin{tabb}Resizes the \texttt{BitVector} so that its length is equal
 to \texttt{size}. Any new bit added is set to 0.
 \end{tabb}
sizethe new size of the BitVector


getBool

public boolean getBool(int pos)
. \begin{tabb}Gives the value of the bit in position \texttt{pos}. If the
 value is 1, returns \texttt{true}; otherwise, returns \texttt{false}.
 \end{tabb}
posthe position of the checked bit the value of the bit as a boolean ArrayIndexOutOfBoundsExceptionif pos is outside the range of the BitVector


setBool

public void setBool(int pos,
                    boolean value)
. \begin{tabb}Sets the value of the bit in position \texttt{pos}. If \texttt{value}
 is equal to \texttt{true}, sets it to 1; otherwise, sets it to 0.
 \end{tabb}
posthe position of the bit to modify valuethe new value of the bit as a boolean ArrayIndexOutOfBoundsExceptionif pos is outside the range of the BitVector


getInt

public int getInt(int pos)
. \begin{tabb}Returns an \texttt{int} containing all the bits in the interval
 $[\mathtt{pos} \times 32, \mathtt{pos} \times 32 + 31]$.
 \end{tabb}
posthe selected position the int at the specified position ArrayIndexOutOfBoundsExceptionif pos is outside the range of the BitVector


toString

public String toString()
. \begin{tabb}Returns a string containing all the bits of the \texttt{BitVector},
 ...
 ...r bit.
 The bits are grouped by groups of 8 bits for ease of reading.
 \end{tabb}
all the bits of the BitVector

Overrides:
toString in class Object

not

public BitVector not()
. \begin{tabb}Returns a \texttt{BitVector} which is the result of the \texttt{not}...
 ... previously set to 0 become 1 and bits previously set to 1 become 0).
 \end{tabb}
the effect of the not operator


selfNot

public BitVector selfNot()
. \begin{tabb}Applies the \texttt{not} operator on the current \texttt{BitVector}
 and returns it.
 \end{tabb}
the BitVector itself


xor

public BitVector xor(BitVector that)
. \begin{tabb}Returns a \texttt{BitVector} which is the result of the \texttt{xor}...
 ... set to 0. This is equivalent to the addition in modulo 2 arithmetic.
 \end{tabb}
thatthe second operand to the xor operator the result of the xor operation


selfXor

public BitVector selfXor(BitVector that)
. \begin{tabb}Applies the \texttt{xor} operator on \texttt{this} with \texttt{that}.
 Stores the result in \texttt{this} and returns it.
 \end{tabb}
thatthe second operand to the xor operator this


and

public BitVector and(BitVector that)
. \begin{tabb}Returns a \texttt{BitVector} which is the result of the \texttt{and}...
 ...exttt{that} are set to 1
 in the result, all the others are set to 0.
 \end{tabb}
thatthe second operand to the and operator the result of the and operation


selfAnd

public BitVector selfAnd(BitVector that)
. \begin{tabb}Applies the \texttt{and} operator on \texttt{this} with \texttt{that}.
 Stores the result in \texttt{this} and returns it.
 \end{tabb}
thatthe second operand to the and operator this


or

public BitVector or(BitVector that)
. \begin{tabb}Returns a \texttt{BitVector} which is the result of the \texttt{or}
 ...
 ...tt{that} are set to to 0
 in the result, all the others are set to 1.
 \end{tabb}
thatthe second operand to the or operator the result of the or operation


selfOr

public BitVector selfOr(BitVector that)
. \begin{tabb}Applies the \texttt{or} operator on \texttt{this} with \texttt{that}.
 Stores the result in \texttt{this} and returns it.
 \end{tabb}
thatthe second operand to the or operator this


shift

public BitVector shift(int j)
. \begin{tabb}Returns a \texttt{BitVector} equal to the original with
 all the bit...
 ...tor in Java, otherwise, it is equivalent to the \texttt{<<} operator.
 \end{tabb}
jthe size of the shift the shifted BitVector


selfShift

public BitVector selfShift(int j)
. \begin{tabb}Shift all the bits of the current \texttt{BitVector} \texttt{j}
 pos...
 ...ars to the left or to the rigth are set to 0.
 Returns \texttt{this}.
 \end{tabb}
jthe size of the shift this


scalarProduct

public boolean scalarProduct(BitVector that)
. \begin{tabb}Returns the scalar product of two \texttt{BitVector}'s modulo 2.
 It...
 ...exttt{this} and
 \texttt{that}, and returns \texttt{false} otherwise.
 \end{tabb}
thatthe other BitVector with which to do the scalar product the scalar product


SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.