Top Description Inners Fields Methods
com.jogamp.common.util

public Interface Bitfield

Known Direct Implementers
jogamp.common.util.Int32ArrayBitfield, jogamp.common.util.Int32Bitfield, jogamp.common.util.SyncedBitfield
Imports
jogamp.common.util.SyncedBitfield

Simple bitfield interface for efficient bit storage access in O(1).
Since
2.3.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Bitfield.Factory

Simple Bitfield factory for returning the efficient implementation.

public static class
Bitfield.Util

Bit operation utilities (static).

Field Summary

Modifier and TypeField and Description
public static final int
UNSIGNED_INT_MAX_VALUE

Maximum 32 bit Unsigned Integer Value: 0xffffffff == .

Method Summary

Modifier and TypeMethod and Description
public int
bitCount()

Returns the number of one bits within this bitfield.

public void
clear(final int
bit number, restricted to [0..size()-1].
bitnum
)

Clear the bit at position bitnum according to bit.

public void
clearField(final boolean bit)

Set all bits of this bitfield to the given value bit.

public boolean
copy(final int
source bit number, restricted to [0..size()-1].
srcBitnum
,
final int
destination bit number, restricted to [0..size()-1].
dstBitnum
)

Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set, otherwise false.

public int
copy32(final int
source bit number, restricted to [0..size()-1].
srcLowBitnum
,
final int
destination bit number, restricted to [0..size()-1].
dstLowBitnum
,
final int length)

Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.

public boolean
get(final int
bit number, restricted to [0..size()-1].
bitnum
)

Return true if the bit at position bitnum is set, otherwise false.

public int
get32(final int
storage bit position of the lowest bit, restricted to [0..size()-length].
lowBitnum
,
final int
number of bits to read, constrained to [0..32].
length
)

Returns length bits from this storage, starting with the lowest bit from the storage position lowBitnum.

public boolean
put(final int
bit number, restricted to [0..size()-1].
bitnum
,
final boolean bit)

Set or clear the bit at position bitnum according to bit and return the previous value.

public void
put32(final int
storage bit position of the lowest bit, restricted to [0..size()-length].
lowBitnum
,
final int
number of bits to write, constrained to [0..32].
length
,
final int
the actual bits to be put into this storage
data
)

Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position lowBitnum.

public void
set(final int
bit number, restricted to [0..size()-1].
bitnum
)

Set the bit at position bitnum according to bit.

public int
size()

Returns the storage size in bit units, e.g. 32 bit for implementations using one int field.

Field Detail

UNSIGNED_INT_MAX_VALUEback to summary
public static final int UNSIGNED_INT_MAX_VALUE

Maximum 32 bit Unsigned Integer Value: 0xffffffff == .

Method Detail

bitCountback to summary
public int bitCount()

Returns the number of one bits within this bitfield.

Utilizes {#link Bitfield.Util#bitCount(int)}.

clearback to summary
public void clear(final int bitnum) throws IndexOutOfBoundsException

Clear the bit at position bitnum according to bit.

Parameters
bitnum:int

bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
clearFieldback to summary
public void clearField(final boolean bit)

Set all bits of this bitfield to the given value bit.

copyback to summary
public boolean copy(final int srcBitnum, final int dstBitnum) throws IndexOutOfBoundsException

Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set, otherwise false.

Parameters
srcBitnum:int

source bit number, restricted to [0..size()-1].

dstBitnum:int

destination bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
copy32back to summary
public int copy32(final int srcLowBitnum, final int dstLowBitnum, final int length) throws IndexOutOfBoundsException

Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.

Implementation shall operate as if invoking get32(int, int) and then put32(int, int, int) sequentially.

Parameters
srcLowBitnum:int

source bit number, restricted to [0..size()-1].

dstLowBitnum:int

destination bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
See Also
get32(int, int), put32(int, int, int)
getback to summary
public boolean get(final int bitnum) throws IndexOutOfBoundsException

Return true if the bit at position bitnum is set, otherwise false.

Parameters
bitnum:int

bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
get32back to summary
public int get32(final int lowBitnum, final int length) throws IndexOutOfBoundsException

Returns length bits from this storage, starting with the lowest bit from the storage position lowBitnum.

Parameters
lowBitnum:int

storage bit position of the lowest bit, restricted to [0..size()-length].

length:int

number of bits to read, constrained to [0..32].

Exceptions
IndexOutOfBoundsException:
if rightBitnum is out of bounds
See Also
put32(int, int, int)
putback to summary
public boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException

Set or clear the bit at position bitnum according to bit and return the previous value.

Parameters
bitnum:int

bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
put32back to summary
public void put32(final int lowBitnum, final int length, final int data) throws IndexOutOfBoundsException

Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position lowBitnum.

Parameters
lowBitnum:int

storage bit position of the lowest bit, restricted to [0..size()-length].

length:int

number of bits to write, constrained to [0..32].

data:int

the actual bits to be put into this storage

Exceptions
IndexOutOfBoundsException:
if rightBitnum is out of bounds
See Also
get32(int, int)
setback to summary
public void set(final int bitnum) throws IndexOutOfBoundsException

Set the bit at position bitnum according to bit.

Parameters
bitnum:int

bit number, restricted to [0..size()-1].

Exceptions
IndexOutOfBoundsException:
if bitnum is out of bounds
sizeback to summary
public int size()

Returns the storage size in bit units, e.g. 32 bit for implementations using one int field.

com.jogamp.common.util back to summary

public Class Bitfield.Factory

extends Object
Class Inheritance

Simple Bitfield factory for returning the efficient implementation.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Bitfield
create(final int storageBitSize)

Creates am efficient Bitfield instance based on the requested storageBitSize.

public static Bitfield
synchronize(final Bitfield impl)

Creates a synchronized Bitfield by wrapping the given Bitfield instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Factoryback to summary
public Factory()

Method Detail

createback to summary
public static Bitfield create(final int storageBitSize)

Creates am efficient Bitfield instance based on the requested storageBitSize.

Implementation returns a plain 32 bit integer field implementation for storageBitSize ≤ 32 bits or an 32 bit integer array implementation otherwise.

synchronizeback to summary
public static Bitfield synchronize(final Bitfield impl)

Creates a synchronized Bitfield by wrapping the given Bitfield instance.

com.jogamp.common.util back to summary

public Class Bitfield.Util

extends Object
Class Inheritance

Bit operation utilities (static).

Constructor Summary

AccessConstructor and Description
public
Util()

Method Summary

Modifier and TypeMethod and Description
public static final int
bitCount(int n)

Returns the number of set bits within given 32bit integer in O(1) using a HAKEM 169 Bit Count inspired implementation:

  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/
  http://www.hackersdelight.org/
public static int
getBitMask(final int n)

Returns the 32 bit mask of n-bits, i.e. n low order 1’s.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Utilback to summary
public Util()

Method Detail

bitCountback to summary
public static final int bitCount(int n)

Returns the number of set bits within given 32bit integer in O(1) using a HAKEM 169 Bit Count inspired implementation:

  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/
  http://www.hackersdelight.org/
getBitMaskback to summary
public static int getBitMask(final int n)

Returns the 32 bit mask of n-bits, i.e. n low order 1’s.

Implementation handles n == 32.

Exceptions
IndexOutOfBoundsException:
if b is out of bounds, i.e. > 32