bits
Class BitSequence

java.lang.Object
  extended by java.util.BitSet
      extended by bits.BitSequence
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class BitSequence
extends java.util.BitSet

Author:
Jonathan L Dautrich Jr.
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Default serialVersionUID
private  int size
           
 
Constructor Summary
BitSequence()
          Creates a new BitSequence without specifying the size.
BitSequence(byte[] bytes)
          Creates a new BitSequence from the specified array of bytes.
BitSequence(int targetSize)
           
BitSequence(int targetSize, int sequenceSize)
          Creates a new BitSequence with an underlying representation of size targetSize and an initial BitSequence size of sequenceSize such that a subsequent append operation would occur at index sequenceSize.
 
Method Summary
 void append(BitSequence bitSequence)
          Appends all bits in bitSequence to the current bit sequence.
 void append(boolean bit)
          Append, not aritmetic add.
 void append(byte newByte)
          Add as in append, not aritmetic add.
 void append(byte[] bytes)
          Add as in append, not aritmetic add.
 void append(byte[] bytes, int start, int count)
          TODO: Unchecked...may throw an out of bounds exception
 void append(int x, int n)
          Appends the last n bits of the integer x to the current BitSequence in the order they appear in the integer x.
 int bitCount()
          Returns the total number of bits in this sequence.
 int bitSetLength()
          Returns the length of the underlying BitSet representation.
 int bitSetSize()
          Returns the size of the underlying BitSet representation.
static java.util.BitSet byteToBitSet(byte newByte)
           
 BitSequence compress()
          Produces a new BitSequence resulting from compressing the entire current BitSequence using a specific algorithm.
 BitSequence decompress()
          Produces a new BitSequence resulting from de-compressing the entire current BitSequence using a specific algorithm.
 BitSequence get(int fromIndex, int count)
          Gets a subsequence of the current BitSequence of size count starting from fromIndex
 byte[] getBytes()
          Get the entire BitSequence as a byte array.
static BitSequence integerToBitSequence(int x, int n)
          Creates a new BitSequence consisting of the last n bits in the integer x.
 int length()
          Returns the total number of bits in this sequence.
 void printAllBits()
          Prints all bits in the sequence.
 void setSize(int newSize)
          Sets the size of this BitSequence to the specified value.
 int size()
          Returns the total number of bits in this sequence.
 java.lang.String toAsciiString()
          Returns the entire current BitSequence as an ASCII string.
 
Methods inherited from class java.util.BitSet
and, andNot, cardinality, clear, clear, clear, clone, equals, flip, flip, get, hashCode, intersects, isEmpty, nextClearBit, nextSetBit, or, set, set, set, set, toString, xor
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Default serialVersionUID

See Also:
Constant Field Values

size

private int size
Constructor Detail

BitSequence

public BitSequence()
Creates a new BitSequence without specifying the size.


BitSequence

public BitSequence(int targetSize)
Parameters:
targetSize - The default size of the underlying BitSet. Note that this does NOT set the size of the BitSequence itself, which remains at zero.

BitSequence

public BitSequence(int targetSize,
                   int sequenceSize)
Creates a new BitSequence with an underlying representation of size targetSize and an initial BitSequence size of sequenceSize such that a subsequent append operation would occur at index sequenceSize. Specifying targetSize separately may be redundant for most cases in which this constructor would be used. The bits up to sequenceSize will all be initialized to 0.

Parameters:
targetSize -
sequenceSize -

BitSequence

public BitSequence(byte[] bytes)
Creates a new BitSequence from the specified array of bytes.

Parameters:
bytes -
Method Detail

append

public void append(boolean bit)
Append, not aritmetic add.

Parameters:
bit -

append

public void append(byte newByte)
Add as in append, not aritmetic add.

Parameters:
newByte -

append

public void append(byte[] bytes)
Add as in append, not aritmetic add.

Parameters:
bytes -

append

public void append(byte[] bytes,
                   int start,
                   int count)
TODO: Unchecked...may throw an out of bounds exception

Parameters:
bytes -
start -
count -

append

public void append(BitSequence bitSequence)
Appends all bits in bitSequence to the current bit sequence.

Parameters:
bitSequence -

append

public void append(int x,
                   int n)
Appends the last n bits of the integer x to the current BitSequence in the order they appear in the integer x.

Parameters:
x -
n -

get

public BitSequence get(int fromIndex,
                       int count)
Gets a subsequence of the current BitSequence of size count starting from fromIndex

Overrides:
get in class java.util.BitSet
Parameters:
fromIndex - index of the first bit in the subsequence
count - number of bits to return in the subsequence
Returns:

byteToBitSet

public static java.util.BitSet byteToBitSet(byte newByte)

compress

public BitSequence compress()
Produces a new BitSequence resulting from compressing the entire current BitSequence using a specific algorithm.

Returns:

decompress

public BitSequence decompress()
Produces a new BitSequence resulting from de-compressing the entire current BitSequence using a specific algorithm.

Returns:

getBytes

public byte[] getBytes()
Get the entire BitSequence as a byte array. Note that up to seven trailing zero bits may be included in the final byte, since the BitSequence size may not be a multiple of eight.

Returns:

printAllBits

public void printAllBits()
Prints all bits in the sequence.


bitCount

public int bitCount()
Returns the total number of bits in this sequence. Identical to size()

Returns:

size

public int size()
Returns the total number of bits in this sequence. For the size of the underlying bitset representation, use bitSetSize() Identical to bitCount()

Overrides:
size in class java.util.BitSet
Returns:

length

public int length()
Returns the total number of bits in this sequence. For the length of the underlying bitset representation, use Identical to size()

Overrides:
length in class java.util.BitSet
Returns:

setSize

public void setSize(int newSize)
Sets the size of this BitSequence to the specified value. Calling this method clears any bits that now no longer fit into this sequence.


bitSetSize

public int bitSetSize()
Returns the size of the underlying BitSet representation. Same as BitSet.size()

Returns:

bitSetLength

public int bitSetLength()
Returns the length of the underlying BitSet representation. Same as BitSet.length()

Returns:

toAsciiString

public java.lang.String toAsciiString()
Returns the entire current BitSequence as an ASCII string.


integerToBitSequence

public static BitSequence integerToBitSequence(int x,
                                               int n)
Creates a new BitSequence consisting of the last n bits in the integer x.

Parameters:
x -
n -
Returns: