com.jogamp.common.util
Class IntBitfield

java.lang.Object
  extended by com.jogamp.common.util.IntBitfield

public class IntBitfield
extends Object

Simple bitfield holder class using an int[] storage.

IntBitfield allows convenient access of a wide field of transient bits using efficient storage in O(1).

It can be used e.g. to map key-codes to pressed-state etc.


Field Summary
static int UNIT_SIZE
          Unit size in bits, here 32 bits for one int unit.
 
Constructor Summary
IntBitfield(int bitCount)
           
IntBitfield(long bitCount)
           
 
Method Summary
 long capacity()
          Return the capacity of this bit field, i.e.
 boolean get(int bitnum)
          Return true if the bit at position bitnum is set, otherwise false.
 boolean get(long bitnum)
          Return true if the bit at position bitnum is set, otherwise false.
 long getBitCount()
          Returns the number of set bits within this bitfield.
static int getBitCount(int n)
          Returns the number of set bits within given 32bit integer in O(1) using HAKEM Bit Count:
 boolean put(int bitnum, boolean bit)
          Set or clear the bit at position bitnum according to bit and return the previous value.
 boolean put(long bitnum, boolean bit)
          Set or clear the bit at position bitnum according to bit and return the previous value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIT_SIZE

public static final int UNIT_SIZE
Unit size in bits, here 32 bits for one int unit.

See Also:
Constant Field Values
Constructor Detail

IntBitfield

public IntBitfield(long bitCount)
Parameters:
bitCount -

IntBitfield

public IntBitfield(int bitCount)
Parameters:
bitCount -
Method Detail

capacity

public final long capacity()
Return the capacity of this bit field, i.e. the number of bits stored int this field.


get

public final boolean get(long bitnum)
Return true if the bit at position bitnum is set, otherwise false.


get

public final boolean get(int bitnum)
Return true if the bit at position bitnum is set, otherwise false.


put

public final boolean put(long bitnum,
                         boolean bit)
Set or clear the bit at position bitnum according to bit and return the previous value.


put

public final boolean put(int bitnum,
                         boolean bit)
Set or clear the bit at position bitnum according to bit and return the previous value.


getBitCount

public static final int getBitCount(int n)
Returns the number of set bits within given 32bit integer in O(1) using HAKEM Bit Count:
   http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html
   http://home.pipeline.com/~hbaker1/hakmem/hacks.html#item169
   http://tekpool.wordpress.com/category/bit-count/
 


getBitCount

public long getBitCount()
Returns the number of set bits within this bitfield.