coins.alias.util
Class BitVector

java.lang.Object
  extended bycoins.alias.util.BitVector
Direct Known Subclasses:
TagVector, TagVector2

public class BitVector
extends java.lang.Object

BitVector class: Unlike java.util.BitSet class, this class offers methods for non-destructive bit operations, where the result of the operation will be stored in the last argument of such methods.


Field Summary
protected  int fBitLength
          Length of this BitVector.
protected  int fLongWordLength
          Length of the long array that internally holds data.
protected static int fShiftMax
          Maximum possible shift of bits within a long word, or 63.
protected  long[] fVectorWord
          Array of longs that internally holds data.
 
Constructor Summary
BitVector(int pBitLength)
          Creates an instance of BitVector with the specified length.
 
Method Summary
 BitVectorIterator bitVectorIterator()
          Returns the BitVectorIterator that is backed by this BitVector.
 boolean equals(java.lang.Object pObject)
          The equality for two BitVector objects is specified by vectorEqual().
 int getBit(int pInx)
          Returns bit state at the specified position.
 int getBitLength()
          Returns the length of this BitVector.
 long[] getVectorWord()
          Returns the long array that internally holds data for this BitVector.
 int getWordLength()
          Returns the length of the long array that internally holds data for this BitVector.
 boolean isSet(int pInx)
          Queries if the specified bit is set.
 boolean isZero()
          Queries if all the bits of this BitVector's is unset.
 void resetBit(int pInx)
          Resets bit at the specified position.
 void setBit(int pInx)
          Sets bit at the specified position.
 java.lang.String toString()
          Returns a String representation of this BitVector.
 java.lang.String toStringDescriptive()
          Returns a String representation of this BitVector, which is at least as descriptive as the one returned by toString().
 BitVector vectorAnd(BitVector pOperand2, BitVector pResult)
          Performs the bitwise AND operation between this BitVector and the argument pOperand2, and stores the result into pResult.
 BitVector vectorCopy(BitVector pResult)
          Copies the contents of this BitVector into the specified argument.
 boolean vectorEqual(BitVector pOperand2)
          Compares this BitVector with the specified argument for equality.
 BitVector vectorNot(BitVector pResult)
          Performs the bitwise NOT operation on this BitVector and store the result into the specified argument.
 BitVector vectorOr(BitVector pOperand2, BitVector pResult)
          Performs the bitwise OR operation between this BitVector and the argument pOperand2, and stores the result into pResult.
 BitVector vectorReset()
          Resets all the bits of this BitVector.
 BitVector vectorSub(BitVector pOperand2, BitVector pResult)
          Performs the bitwise subtraction operation between this BitVector and the argument pOperand2, and stores the result into pResult.
 BitVector vectorXor(BitVector pOperand2, BitVector pResult)
          Performs the bitwise exclusive OR (XOR) operation between this BitVector and the argument pOperand2, and stores the result into pResult.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fVectorWord

protected final long[] fVectorWord
Array of longs that internally holds data.


fLongWordLength

protected final int fLongWordLength
Length of the long array that internally holds data.


fBitLength

protected final int fBitLength
Length of this BitVector.


fShiftMax

protected static final int fShiftMax
Maximum possible shift of bits within a long word, or 63.

See Also:
Constant Field Values
Constructor Detail

BitVector

public BitVector(int pBitLength)
Creates an instance of BitVector with the specified length.

Parameters:
pBitLength - the length of the BitVector
Method Detail

setBit

public void setBit(int pInx)
Sets bit at the specified position.

Parameters:
pInx - the index (position) of the bit to be set.

resetBit

public void resetBit(int pInx)
Resets bit at the specified position.

Parameters:
pInx - the index (position) of the bit to be reset.

getBit

public int getBit(int pInx)
Returns bit state at the specified position.

Parameters:
pInx - the index (position) of the bit to get.
Returns:
1 if the specified bit is set, 0 otherwise.

isSet

public boolean isSet(int pInx)
Queries if the specified bit is set.

Parameters:
pInx - the index (position) of the bit to query.
Returns:
true if the specified bit is set.

isZero

public boolean isZero()
Queries if all the bits of this BitVector's is unset.

Returns:
true if all the bits are unset.

getBitLength

public int getBitLength()
Returns the length of this BitVector.

Returns:
the length of this BitVector.

getVectorWord

public long[] getVectorWord()
Returns the long array that internally holds data for this BitVector.

Returns:
the long array that internally holds data.

getWordLength

public int getWordLength()
Returns the length of the long array that internally holds data for this BitVector.

Returns:
the length of the long array that internally holds data.

bitVectorIterator

public BitVectorIterator bitVectorIterator()
Returns the BitVectorIterator that is backed by this BitVector.

Returns:
the BitVectorIterator that is backed by this BitVector.

vectorNot

public BitVector vectorNot(BitVector pResult)
Performs the bitwise NOT operation on this BitVector and store the result into the specified argument. The argument must have the same length as this BitVector.

Parameters:
pResult - the BitVector where the result of the NOT operation is stored.
Returns:
pResult, the result of the NOT operation.

vectorAnd

public BitVector vectorAnd(BitVector pOperand2,
                           BitVector pResult)
Performs the bitwise AND operation between this BitVector and the argument pOperand2, and stores the result into pResult. Both pOperand2 and pResult must have the same length as this BitVector.

Parameters:
pOperand2 - the BitVector with which this BitVector is ANDed.
pResult - the BitVector where the result of the AND operation is stored.
Returns:
pResult, the result of the AND operation.

vectorOr

public BitVector vectorOr(BitVector pOperand2,
                          BitVector pResult)
Performs the bitwise OR operation between this BitVector and the argument pOperand2, and stores the result into pResult. Both pOperand2 and pResult must have the same length as this BitVector.

Parameters:
pOperand2 - the BitVector with which this BitVector is ORed.
pResult - the BitVector where the result of the OR operation is stored.
Returns:
pResult, the result of the OR operation.

vectorXor

public BitVector vectorXor(BitVector pOperand2,
                           BitVector pResult)
Performs the bitwise exclusive OR (XOR) operation between this BitVector and the argument pOperand2, and stores the result into pResult. Both pOperand2 and pResult must have the same length as this BitVector.

Parameters:
pOperand2 - the BitVector with which this BitVector is XORed.
pResult - the BitVector where the result of the XOR operation is stored.
Returns:
pResult, the result of the XOR operation.

vectorSub

public BitVector vectorSub(BitVector pOperand2,
                           BitVector pResult)
Performs the bitwise subtraction operation between this BitVector and the argument pOperand2, and stores the result into pResult. Both pOperand2 and pResult must have the same length as this BitVector.

Parameters:
pOperand2 - the BitVector by which amount this BitVector is reduced (the second operand of the bitwise subtraction operation).
pResult - the BitVector where the result of the subtraction operation is stored.
Returns:
pResult, the result of the subtraction operation.

vectorCopy

public BitVector vectorCopy(BitVector pResult)
Copies the contents of this BitVector into the specified argument. The argument must have the same length as this BitVector.

Parameters:
pResult - the destination of the copy operation.
Returns:
pResult, the result of the copy operation.

vectorEqual

public boolean vectorEqual(BitVector pOperand2)
Compares this BitVector with the specified argument for equality. Two BitVectors are equal when they have the same contents (bit sequences). The argument must have the same length as this BitVector.

Parameters:
pOperand2 - the BitVector to be compared with this BitVector.
Returns:
true if all the bits of this BitVector and those of the argument are equal.

equals

public boolean equals(java.lang.Object pObject)
The equality for two BitVector objects is specified by vectorEqual(). This method returns true if and only if the specified argument pObject is an instance of BitVector, its length is equal to the length of this BitVector, and vectorEqual((BitVector)pObject) returns true.

Parameters:
pObject - the object to be compared with this BitVector.
Returns:
true if the specified argument pObject is a BitVector having the same length as this one and vectorEqual((BitVector)pObject) returns true.
See Also:
vectorEqual(coins.alias.util.BitVector)

vectorReset

public BitVector vectorReset()
Resets all the bits of this BitVector.

Returns:
this BitVector with all the bits reset.

toString

public java.lang.String toString()
Returns a String representation of this BitVector. The resultant String contains the bit positions of the set bits separated by spaces.

Returns:
the String representation of this BitVector.

toStringDescriptive

public java.lang.String toStringDescriptive()
Returns a String representation of this BitVector, which is at least as descriptive as the one returned by toString(). It should usually contain the String representation of the objects that are associated with the set bits. This method returns the same String as toString() for this class.

Returns:
the String representation of this BitVector that is possibly more detailed than that returned by toString.