SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.util.BitVector Class Reference

This class implements vectors of bits and the operations needed to use them. More...

Inheritance diagram for umontreal.ssj.util.BitVector:

Public Member Functions

 BitVector (int length)
 Creates a new BitVector of length length with all its bits set to 0.
 BitVector (int[] vect, int length)
 Creates a new BitVector of length length using the data in vect.
 BitVector (int[] vect)
 Creates a new BitVector using the data in vect.
 BitVector (BitVector that)
 Creates a copy of the BitVector that.
Object clone ()
 Creates a copy of the BitVector.
boolean equals (BitVector that)
 Verifies if two BitVector’s have the same length and the same data.
int size ()
 Returns the length of the BitVector.
void enlarge (int size, boolean filling)
 Resizes the BitVector so that its length is equal to size.
void enlarge (int size)
 Resizes the BitVector so that its length is equal to size.
boolean getBool (int pos)
 Gives the value of the bit in position pos.
void setBool (int pos, boolean value)
 Sets the value of the bit in position pos.
int getInt (int pos)
 Returns an int containing all the bits in the interval.
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 not ()
 Returns a BitVector which is the result of the not operator on the current BitVector.
BitVector selfNot ()
 Applies the not operator on the current BitVector and returns it.
BitVector xor (BitVector that)
 Returns a BitVector which is the result of the xor operator applied on this and that.
BitVector selfXor (BitVector that)
 Applies the xor operator on this with that.
BitVector and (BitVector that)
 Returns a BitVector which is the result of the and operator with both the this and that BitVector’s.
BitVector selfAnd (BitVector that)
 Applies the and operator on this with that.
BitVector or (BitVector that)
 Returns a BitVector which is the result of the or operator with both the this and that BitVector’s.
BitVector selfOr (BitVector that)
 Applies the or operator on this with that.
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.
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.
boolean scalarProduct (BitVector that)
 Returns the scalar product of two BitVector’s modulo 2.

Detailed Description

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. In the implementation, the vector is split in blocks of 32 bits and each block is represented as an integer.

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.

Definition at line 45 of file BitVector.java.

Constructor & Destructor Documentation

◆ BitVector() [1/4]

umontreal.ssj.util.BitVector.BitVector ( int length)

Creates a new BitVector of length length with all its bits set to 0.

Parameters
lengththe length of the BitVector

Definition at line 67 of file BitVector.java.

◆ BitVector() [2/4]

umontreal.ssj.util.BitVector.BitVector ( int[] vect,
int length )

Creates a new BitVector of length length using the data in vect.

Component vect[0] makes the 32 lowest order bits, with vect[1] being the 32 next lowest order bits, and so on. The normal bit order is then used to fill the 32 bits (the first bit is the lowest order bit and the last bit is largest order bit). Note that the sign bit is used as the largest order bit.

Parameters
vectthe bits data
lengththe length of the vector
Exceptions
IllegalArgumentExceptionwhen the length of `vect` is not compatible with the length provided

Definition at line 86 of file BitVector.java.

◆ BitVector() [3/4]

umontreal.ssj.util.BitVector.BitVector ( int[] vect)

Creates a new BitVector using the data in vect.

The length of the BitVector is always equals to 32 times the length of vect.

Parameters
vectthe bits data

Definition at line 105 of file BitVector.java.

◆ BitVector() [4/4]

umontreal.ssj.util.BitVector.BitVector ( BitVector that)

Creates a copy of the BitVector that.

Parameters
thatthe BitVector to copy

Definition at line 114 of file BitVector.java.

Member Function Documentation

◆ and()

BitVector umontreal.ssj.util.BitVector.and ( BitVector that)

Returns a BitVector which is the result of the and operator with both the this and that BitVector’s.

The and operator is equivalent to the & 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.

Parameters
thatthe second operand to the and operator
Returns
the result of the and operation

Definition at line 359 of file BitVector.java.

◆ clone()

Object umontreal.ssj.util.BitVector.clone ( )

Creates a copy of the BitVector.

Returns
a deep copy of the BitVector

Definition at line 126 of file BitVector.java.

◆ enlarge() [1/2]

void umontreal.ssj.util.BitVector.enlarge ( int size)

Resizes the BitVector so that its length is equal to size.

Any new bit added is set to 0.

Parameters
sizethe new size of the BitVector

Definition at line 197 of file BitVector.java.

◆ enlarge() [2/2]

void umontreal.ssj.util.BitVector.enlarge ( int size,
boolean filling )

Resizes the BitVector so that its length is equal to size.

If the BitVector is enlarged, then the newly added bits are given the value 1 if filling is set to true and 0 otherwise.

Parameters
sizethe new size of the BitVector
fillingthe state of the new bits

Definition at line 171 of file BitVector.java.

◆ equals()

boolean umontreal.ssj.util.BitVector.equals ( BitVector that)

Verifies if two BitVector’s have the same length and the same data.

Parameters
thatthe other BitVector to compare to
Returns
if the two BitVector’s are identiqual

Definition at line 145 of file BitVector.java.

◆ getBool()

boolean umontreal.ssj.util.BitVector.getBool ( int pos)

Gives the value of the bit in position pos.

If the value is 1, returns true; otherwise, returns false.

Parameters
posthe position of the checked bit
Returns
the value of the bit as a boolean
Exceptions
ArrayIndexOutOfBoundsExceptionif `pos` is outside the range of the BitVector

Definition at line 211 of file BitVector.java.

◆ getInt()

int umontreal.ssj.util.BitVector.getInt ( int pos)

Returns an int containing all the bits in the interval.

\([\mathtt{pos} \times32, \mathtt{pos} \times32 + 31]\).

Parameters
posthe selected position
Returns
the int at the specified position
Exceptions
ArrayIndexOutOfBoundsExceptionif `pos` is outside the range of the BitVector

Definition at line 245 of file BitVector.java.

◆ not()

BitVector umontreal.ssj.util.BitVector.not ( )

Returns a BitVector which is the result of the not operator on the current BitVector.

The not operator is equivalent to the ~ operator in Java and thus swap all bits (bits previously set to 0 become 1 and bits previously set to 1 become 0).

Returns
the effect of the not operator

Definition at line 276 of file BitVector.java.

◆ or()

BitVector umontreal.ssj.util.BitVector.or ( BitVector that)

Returns a BitVector which is the result of the or operator with both the this and that BitVector’s.

The or operator is equivalent to the | operator in Java. Only bits which are set to 0 in both this and that are set to to 0 in the result, all the others are set to 1.

Parameters
thatthe second operand to the or operator
Returns
the result of the or operation

Definition at line 409 of file BitVector.java.

◆ scalarProduct()

boolean umontreal.ssj.util.BitVector.scalarProduct ( BitVector that)

Returns the scalar product of two BitVector’s modulo 2.

It returns true if there is an odd number of bits with a value of 1 in the result of the and operator applied on this and that, and returns false otherwise.

Parameters
thatthe other BitVector with which to do the scalar product
Returns
the scalar product

Definition at line 549 of file BitVector.java.

◆ selfAnd()

BitVector umontreal.ssj.util.BitVector.selfAnd ( BitVector that)

Applies the and operator on this with that.

Stores the result in this and returns it.

Parameters
thatthe second operand to the and operator
Returns
this

Definition at line 386 of file BitVector.java.

◆ selfNot()

BitVector umontreal.ssj.util.BitVector.selfNot ( )

Applies the not operator on the current BitVector and returns it.

Returns
the BitVector itself

Definition at line 292 of file BitVector.java.

◆ selfOr()

BitVector umontreal.ssj.util.BitVector.selfOr ( BitVector that)

Applies the or operator on this with that.

Stores the result in this and returns it.

Parameters
thatthe second operand to the or operator
Returns
this

Definition at line 434 of file BitVector.java.

◆ selfShift()

BitVector umontreal.ssj.util.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.

The new bits that appears to the left or to the rigth are set to 0. Returns this.

Parameters
jthe size of the shift
Returns
this

Definition at line 499 of file BitVector.java.

◆ selfXor()

BitVector umontreal.ssj.util.BitVector.selfXor ( BitVector that)

Applies the xor operator on this with that.

Stores the result in this and returns it.

Parameters
thatthe second operand to the xor operator
Returns
this

Definition at line 337 of file BitVector.java.

◆ setBool()

void umontreal.ssj.util.BitVector.setBool ( int pos,
boolean value )

Sets the value of the bit in position pos.

If value is equal to true, sets it to 1; otherwise, sets it to 0.

Parameters
posthe position of the bit to modify
valuethe new value of the bit as a boolean
Exceptions
ArrayIndexOutOfBoundsExceptionif `pos` is outside the range of the BitVector

Definition at line 226 of file BitVector.java.

◆ shift()

BitVector umontreal.ssj.util.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.

The new bits that appears to the left or to the right are set to 0. If j is positive, this operation is equivalent to the >>> operator in Java, otherwise, it is equivalent to the << operator.

Parameters
jthe size of the shift
Returns
the shifted BitVector

Definition at line 457 of file BitVector.java.

◆ size()

int umontreal.ssj.util.BitVector.size ( )

Returns the length of the BitVector.

Returns
the length of the BitVector

Definition at line 159 of file BitVector.java.

◆ toString()

String umontreal.ssj.util.BitVector.toString ( )

Returns a string containing all the bits of the BitVector, starting with the highest order bit and finishing with the lowest order bit.

The bits are grouped by groups of 8 bits for ease of reading.

Returns
all the bits of the BitVector

Definition at line 258 of file BitVector.java.

◆ xor()

BitVector umontreal.ssj.util.BitVector.xor ( BitVector that)

Returns a BitVector which is the result of the xor operator applied on this and that.

The xor operator is equivalent to the ^ 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.

Parameters
thatthe second operand to the xor operator
Returns
the result of the xor operation

Definition at line 312 of file BitVector.java.


The documentation for this class was generated from the following file: