com.googlecode.javaewah.datastructure
Class StaticBitSet

java.lang.Object
  extended by com.googlecode.javaewah.datastructure.StaticBitSet

public class StaticBitSet
extends Object

This is an optimized version of Java's BitSet.

Since:
0.8.0
Author:
Daniel Lemire

Constructor Summary
StaticBitSet(int sizeinbits)
          Construct a bitset with the specified number of bits (initially all false).
 
Method Summary
 int cardinality()
          Compute the number of bits set to 1
 void clear()
          Reset all bits to false
 boolean get(int i)
           
 int nextSetBit(int i)
          Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }
 int nextUnsetBit(int i)
          Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }
 void resize(int sizeinbits)
          Resize the bitset
 void set(int i)
          Set to true
 void set(int i, boolean b)
           
 int size()
          Query the size
 void unset(int i)
          Set to false
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticBitSet

public StaticBitSet(int sizeinbits)
Construct a bitset with the specified number of bits (initially all false). The number of bits is rounded up to the nearest multiple of 64.

Parameters:
sizeinbits - the size in bits
Method Detail

size

public int size()
Query the size

Returns:
the size in bits.

resize

public void resize(int sizeinbits)
Resize the bitset

Parameters:
sizeinbits - new number of bits

clear

public void clear()
Reset all bits to false


cardinality

public int cardinality()
Compute the number of bits set to 1

Returns:
the number of bits

get

public boolean get(int i)
Parameters:
i - index
Returns:
value of the bit

set

public void set(int i)
Set to true

Parameters:
i - index of the bit

unset

public void unset(int i)
Set to false

Parameters:
i - index of the bit

set

public void set(int i,
                boolean b)
Parameters:
i - index
b - value of the bit

nextSetBit

public int nextSetBit(int i)
Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }

Parameters:
i - current set bit
Returns:
next set bit or -1

nextUnsetBit

public int nextUnsetBit(int i)
Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }

Parameters:
i - current unset bit
Returns:
next unset bit or -1


Copyright © 2014. All Rights Reserved.