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 ClassesModifier and TypeInterfaceDescriptionstatic classSimpleBitfieldfactory for returning the efficient implementation.static classBit operation utilities (static). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum 32 bit Unsigned Integer Value:0xffffffff== -1. -
Method Summary
Modifier and TypeMethodDescriptionintbitCount()Returns the number of one bits within this bitfield.voidclear(int bitnum) Clear the bit at positionbitnumaccording tobit.voidclearField(boolean bit) Set all bits of this bitfield to the given valuebit.booleancopy(int srcBitnum, int dstBitnum) Copies the bit at positionsrcBitnumto positiondstBitnumand returningtrueif the bit is set, otherwisefalse.intcopy32(int srcLowBitnum, int dstLowBitnum, int length) Copieslengthbits at positionsrcLowBitnumto positiondstLowBitnumand returning the bits.booleanget(int bitnum) Returntrueif the bit at positionbitnumis set, otherwisefalse.intget32(int lowBitnum, int length) Returnslengthbits from this storage, starting with the lowest bit from the storage positionlowBitnum.booleanput(int bitnum, boolean bit) Set or clear the bit at positionbitnumaccording tobitand return the previous value.voidput32(int lowBitnum, int length, int data) Putslengthbits of givendatainto this storage, starting w/ the lowest bit to the storage positionlowBitnum.voidset(int bitnum) Set the bit at positionbitnumaccording tobit.intsize()Returns the storage size in bit units, e.g.
-
Field Details
-
UNSIGNED_INT_MAX_VALUE
static final int UNSIGNED_INT_MAX_VALUEMaximum 32 bit Unsigned Integer Value:0xffffffff== -1.- See Also:
-
-
Method Details
-
size
int size()Returns the storage size in bit units, e.g. 32 bit for implementations using oneintfield. -
clearField
void clearField(boolean bit) Set all bits of this bitfield to the given valuebit. -
get32
Returnslengthbits 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- ifrightBitnumis out of bounds- See Also:
-
put32
Putslengthbits of givendatainto 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- ifrightBitnumis out of bounds- See Also:
-
copy32
Copieslengthbits at positionsrcLowBitnumto positiondstLowBitnumand 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- ifbitnumis out of bounds- See Also:
-
get
Returntrueif the bit at positionbitnumis set, otherwisefalse.- Parameters:
bitnum- bit number, restricted to [0..size()-1].- Throws:
IndexOutOfBoundsException- ifbitnumis out of bounds
-
put
Set or clear the bit at positionbitnumaccording tobitand return the previous value.- Parameters:
bitnum- bit number, restricted to [0..size()-1].- Throws:
IndexOutOfBoundsException- ifbitnumis out of bounds
-
set
Set the bit at positionbitnumaccording tobit.- Parameters:
bitnum- bit number, restricted to [0..size()-1].- Throws:
IndexOutOfBoundsException- ifbitnumis out of bounds
-
clear
Clear the bit at positionbitnumaccording tobit.- Parameters:
bitnum- bit number, restricted to [0..size()-1].- Throws:
IndexOutOfBoundsException- ifbitnumis out of bounds
-
copy
Copies the bit at positionsrcBitnumto positiondstBitnumand returningtrueif 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- ifbitnumis out of bounds
-
bitCount
int bitCount()Returns the number of one bits within this bitfield.Utilizes {#link
Bitfield.Util.bitCount(int)}.
-