Package com.jogamp.common.util
Interface Bitfield
-
public interface Bitfield
Simple bitfield interface for efficient bit storage access in O(1).- Since:
- 2.3.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Bitfield.Factory
SimpleBitfield
factory for returning the efficient implementation.static class
Bitfield.Util
Bit operation utilities (static).
-
Field Summary
Fields Modifier and Type Field Description static int
UNSIGNED_INT_MAX_VALUE
Maximum 32 bit Unsigned Integer Value:0xffffffff
== -1.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
bitCount()
Returns the number of one bits within this bitfield.void
clear(int bitnum)
Clear the bit at positionbitnum
according tobit
.void
clearField(boolean bit)
Set all bits of this bitfield to the given valuebit
.boolean
copy(int srcBitnum, int dstBitnum)
Copies the bit at positionsrcBitnum
to positiondstBitnum
and returningtrue
if the bit is set, otherwisefalse
.int
copy32(int srcLowBitnum, int dstLowBitnum, int length)
Copieslength
bits at positionsrcLowBitnum
to positiondstLowBitnum
and returning the bits.boolean
get(int bitnum)
Returntrue
if the bit at positionbitnum
is set, otherwisefalse
.int
get32(int lowBitnum, int length)
Returnslength
bits from this storage, starting with the lowest bit from the storage positionlowBitnum
.boolean
put(int bitnum, boolean bit)
Set or clear the bit at positionbitnum
according tobit
and return the previous value.void
put32(int lowBitnum, int length, int data)
Putslength
bits of givendata
into this storage, starting w/ the lowest bit to the storage positionlowBitnum
.void
set(int bitnum)
Set the bit at positionbitnum
according tobit
.int
size()
Returns the storage size in bit units, e.g.
-
-
-
Field Detail
-
UNSIGNED_INT_MAX_VALUE
static final int UNSIGNED_INT_MAX_VALUE
Maximum 32 bit Unsigned Integer Value:0xffffffff
== -1.- See Also:
- Constant Field Values
-
-
Method Detail
-
size
int size()
Returns the storage size in bit units, e.g. 32 bit for implementations using oneint
field.
-
clearField
void clearField(boolean bit)
Set all bits of this bitfield to the given valuebit
.
-
get32
int get32(int lowBitnum, int length) throws IndexOutOfBoundsException
Returnslength
bits from this storage, starting with the lowest bit from the storage positionlowBitnum
.- Parameters:
lowBitnum
- storage bit position of the lowest bit, restricted to [0..size()
-length
].length
- number of bits to read, constrained to [0..32].- Throws:
IndexOutOfBoundsException
- ifrightBitnum
is out of bounds- See Also:
put32(int, int, int)
-
put32
void put32(int lowBitnum, int length, int data) throws IndexOutOfBoundsException
Putslength
bits of givendata
into this storage, starting w/ the lowest bit to the storage positionlowBitnum
.- Parameters:
lowBitnum
- storage bit position of the lowest bit, restricted to [0..size()
-length
].length
- number of bits to write, constrained to [0..32].data
- the actual bits to be put into this storage- Throws:
IndexOutOfBoundsException
- ifrightBitnum
is out of bounds- See Also:
get32(int, int)
-
copy32
int copy32(int srcLowBitnum, int dstLowBitnum, int length) throws IndexOutOfBoundsException
Copieslength
bits at positionsrcLowBitnum
to positiondstLowBitnum
and returning the bits.Implementation shall operate as if invoking
get32(int, int)
and thenput32(int, int, int)
sequentially.- Parameters:
srcLowBitnum
- source bit number, restricted to [0..size()
-1].dstLowBitnum
- destination bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds- See Also:
get32(int, int)
,put32(int, int, int)
-
get
boolean get(int bitnum) throws IndexOutOfBoundsException
Returntrue
if the bit at positionbitnum
is set, otherwisefalse
.- Parameters:
bitnum
- bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds
-
put
boolean put(int bitnum, boolean bit) throws IndexOutOfBoundsException
Set or clear the bit at positionbitnum
according tobit
and return the previous value.- Parameters:
bitnum
- bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds
-
set
void set(int bitnum) throws IndexOutOfBoundsException
Set the bit at positionbitnum
according tobit
.- Parameters:
bitnum
- bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds
-
clear
void clear(int bitnum) throws IndexOutOfBoundsException
Clear the bit at positionbitnum
according tobit
.- Parameters:
bitnum
- bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds
-
copy
boolean copy(int srcBitnum, int dstBitnum) throws IndexOutOfBoundsException
Copies the bit at positionsrcBitnum
to positiondstBitnum
and returningtrue
if the bit is set, otherwisefalse
.- Parameters:
srcBitnum
- source bit number, restricted to [0..size()
-1].dstBitnum
- destination bit number, restricted to [0..size()
-1].- Throws:
IndexOutOfBoundsException
- ifbitnum
is out of bounds
-
bitCount
int bitCount()
Returns the number of one bits within this bitfield.Utilizes {#link
Bitfield.Util.bitCount(int)
}.
-
-