org.basex.util
Class BitArray

java.lang.Object
  extended by org.basex.util.BitArray

public final class BitArray
extends java.lang.Object

Bit array that grows when needed. The implementation is similar to BitSet.

Author:
BaseX Team 2005-12, BSD License, Dimitar Popov

Constructor Summary
BitArray()
          Construct a new bit array.
BitArray(int n)
          Construct a new bit array with the specified number of bits.
BitArray(long[] a, int l)
          Construct a new bit array with the specified backing array.
 
Method Summary
 int cardinality()
          Returns the number of bits set to true.
 void clear(int i)
          Set the ith bit to 0.
 boolean get(int i)
          Get the value of the ith bit.
 void init()
          Initialize the bit array with an empty array.
 void init(long[] a, int l)
          Initialize the bit array with the specified backing array.
 int nextFree(int i)
          Get the next bit set to 0, starting from the ith bit.
 int nextSet(int i)
          Get the next bit set to 1, starting from the ith bit.
 void set(int i)
          Set the ith bit to 1.
 long[] toArray()
          The word array used to store the bits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitArray

public BitArray()
Construct a new bit array.


BitArray

public BitArray(int n)
Construct a new bit array with the specified number of bits.

Parameters:
n - initial number of bits (> 0)

BitArray

public BitArray(long[] a,
                int l)
Construct a new bit array with the specified backing array.

Parameters:
a - array with bits
l - number of used bits
Method Detail

init

public void init()
Initialize the bit array with an empty array.


init

public void init(long[] a,
                 int l)
Initialize the bit array with the specified backing array.

Parameters:
a - array with bits
l - number of used bits

toArray

public long[] toArray()
The word array used to store the bits. The array is shrunk to the last word, where a bit is set.

Returns:
array of longs

cardinality

public int cardinality()
Returns the number of bits set to true.

Returns:
the number of bits set to true

get

public boolean get(int i)
Get the value of the ith bit.

Parameters:
i - index of the bit
Returns:
true if the ith bit is set

set

public void set(int i)
Set the ith bit to 1.

Parameters:
i - index of the bit

clear

public void clear(int i)
Set the ith bit to 0.

Parameters:
i - index of the bit

nextFree

public int nextFree(int i)
Get the next bit set to 0, starting from the ith bit.

Parameters:
i - index from which to start the search (inclusive)
Returns:
index of the next clear bit after the ith bit

nextSet

public int nextSet(int i)
Get the next bit set to 1, starting from the ith bit.

Parameters:
i - index from which to start the search (inclusive)
Returns:
index of the next set bit after the ith bit