diff options
author | Sven Gothel <[email protected]> | 2015-08-02 01:12:21 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-08-02 01:12:21 +0200 |
commit | 047e9adaf2a5f51f7acfa194a744c99b6bfadaea (patch) | |
tree | c701ab77a9387cdec1a61c51b9ed289d5aa755e2 /src/java/jogamp/common/util/Int32Bitfield.java | |
parent | 805800e9b02acf54a6cc5a04ce94c9b465c42f43 (diff) |
Bitfield: Refine API method names, add clearField(boolean), fix put32(..) and bitCount(), add unit test (passed)
Diffstat (limited to 'src/java/jogamp/common/util/Int32Bitfield.java')
-rw-r--r-- | src/java/jogamp/common/util/Int32Bitfield.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/java/jogamp/common/util/Int32Bitfield.java b/src/java/jogamp/common/util/Int32Bitfield.java index 6119a00..9bf2117 100644 --- a/src/java/jogamp/common/util/Int32Bitfield.java +++ b/src/java/jogamp/common/util/Int32Bitfield.java @@ -45,10 +45,19 @@ public class Int32Bitfield implements Bitfield { } @Override - public int getStorageBitSize() { + public int size() { return UNIT_SIZE; } + @Override + public final void clearField(final boolean bit) { + if( bit ) { + storage = Bitfield.UNSIGNED_INT_MAX_VALUE; + } else { + storage = 0; + } + } + private static final void check(final int size, final int bitnum) throws IndexOutOfBoundsException { if( 0 > bitnum || bitnum >= size ) { throw new IndexOutOfBoundsException("Bitnum should be within [0.."+(size-1)+"], but is "+bitnum); @@ -64,11 +73,11 @@ public class Int32Bitfield implements Bitfield { final int left = 32 - lowBitnum; // remaining bits of first chunk if( 32 == left ) { // fast path - final int m = ( 1 << length ) - 1; + final int m = Util.getBitMask(length); // mask of chunk return m & storage; } else { // slow path - final int l = Math.min(length, left); // length of first chunk + final int l = Math.min(length, left); // length of first chunk < 32 final int m = ( 1 << l ) - 1; // mask of first chunk return m & ( storage >>> lowBitnum ); } @@ -82,12 +91,12 @@ public class Int32Bitfield implements Bitfield { final int left = 32 - lowBitnum; // remaining bits of first chunk storage if( 32 == left ) { // fast path - final int m = ( 1 << length ) - 1; // mask of chunk + final int m = Util.getBitMask(length); // mask of chunk storage = ( ( ~m ) & storage ) // keep non-written storage bits | ( m & data ); // overwrite storage w/ used data bits } else { // slow path - final int l = Math.min(length, left); // length of first chunk + final int l = Math.min(length, left); // length of first chunk < 32 final int m = ( 1 << l ) - 1; // mask of first chunk storage = ( ( ~( m << lowBitnum ) ) & storage ) // keep non-written storage bits | ( ( m & data ) << lowBitnum ); // overwrite storage w/ used data bits @@ -144,7 +153,7 @@ public class Int32Bitfield implements Bitfield { } @Override - public int getBitCount() { - return Bitfield.Util.getBitCount(storage); + public int bitCount() { + return Bitfield.Util.bitCount(storage); } } |