aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/jogamp')
-rw-r--r--src/java/jogamp/common/util/Int32ArrayBitfield.java39
-rw-r--r--src/java/jogamp/common/util/Int32Bitfield.java23
-rw-r--r--src/java/jogamp/common/util/SyncedBitfield.java13
3 files changed, 51 insertions, 24 deletions
diff --git a/src/java/jogamp/common/util/Int32ArrayBitfield.java b/src/java/jogamp/common/util/Int32ArrayBitfield.java
index dd18b3d..3dcb9ae 100644
--- a/src/java/jogamp/common/util/Int32ArrayBitfield.java
+++ b/src/java/jogamp/common/util/Int32ArrayBitfield.java
@@ -44,16 +44,29 @@ public class Int32ArrayBitfield implements Bitfield {
* @param storageBitSize
*/
public Int32ArrayBitfield(final int storageBitSize) {
- final int units = Math.max(1, ( storageBitSize + 7 ) >>> UNIT_SHIFT);
- this.storage = new int[units];
+ final int units = Math.max(1, ( storageBitSize + 31 ) >>> UNIT_SHIFT);
+ this.storage = new int[units]; // initialized w/ default '0'
this.bitSize = units << UNIT_SHIFT;
}
@Override
- public int getStorageBitSize() {
+ public int size() {
return bitSize;
}
+ @Override
+ public final void clearField(final boolean bit) {
+ final int v;
+ if( bit ) {
+ v = Bitfield.UNSIGNED_INT_MAX_VALUE;
+ } else {
+ v = 0;
+ }
+ for(int i=storage.length-1; i>=0; i--) {
+ storage[i] = v;
+ }
+ }
+
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);
@@ -70,14 +83,14 @@ public class Int32ArrayBitfield implements Bitfield {
final int left = 32 - ( lowBitnum - ( u << UNIT_SHIFT ) ); // remaining bits of first chunk storage
if( 32 == left ) {
// fast path
- final int m = ( 1 << length ) - 1;
+ final int m = Util.getBitMask(length); // mask of chunk
return m & storage[u];
} 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
final int d = m & ( storage[u] >>> lowBitnum );
- final int l2 = length - l; // length of last chunk
+ final int l2 = length - l; // length of last chunk < 32
if( l2 > 0 ) {
final int m2 = ( 1 << l2 ) - 1; // mask of last chunk
return d | ( ( m2 & storage[u+1] ) << l );
@@ -96,20 +109,20 @@ public class Int32ArrayBitfield implements Bitfield {
final int left = 32 - ( lowBitnum - ( u << UNIT_SHIFT ) ); // 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[u] = ( ( ~m ) & storage[u] ) // 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[u] = ( ( ~( m << lowBitnum ) ) & storage[u] ) // keep non-written storage bits
| ( ( m & data ) << lowBitnum ); // overwrite storage w/ used data bits
- final int l2 = length - l; // length of last chunk
+ final int l2 = length - l; // length of last chunk < 32
if( l2 > 0 ) {
final int m2 = ( 1 << l2 ) - 1; // mask of last chunk
- storage[u] = ( ( ~m2 ) & storage[u+1] ) // keep non-written storage bits
- | ( m2 & ( data >>> l ) ); // overwrite storage w/ used data bits
+ storage[u+1] = ( ( ~m2 ) & storage[u+1] ) // keep non-written storage bits
+ | ( m2 & ( data >>> l ) ); // overwrite storage w/ used data bits
}
}
}
@@ -180,10 +193,10 @@ public class Int32ArrayBitfield implements Bitfield {
}
@Override
- public int getBitCount() {
+ public int bitCount() {
int c = 0;
for(int i = storage.length-1; i>=0; i--) {
- c += Bitfield.Util.getBitCount(storage[i]);
+ c += Bitfield.Util.bitCount(storage[i]);
}
return c;
}
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);
}
}
diff --git a/src/java/jogamp/common/util/SyncedBitfield.java b/src/java/jogamp/common/util/SyncedBitfield.java
index 783fb91..488be12 100644
--- a/src/java/jogamp/common/util/SyncedBitfield.java
+++ b/src/java/jogamp/common/util/SyncedBitfield.java
@@ -40,8 +40,13 @@ public class SyncedBitfield implements Bitfield {
}
@Override
- public final synchronized int getStorageBitSize() {
- return impl.getStorageBitSize();
+ public final synchronized int size() {
+ return impl.size();
+ }
+
+ @Override
+ public final void clearField(final boolean bit) {
+ impl.clearField(bit);
}
@Override
@@ -85,7 +90,7 @@ public class SyncedBitfield implements Bitfield {
}
@Override
- public final synchronized int getBitCount() {
- return impl.getBitCount();
+ public final synchronized int bitCount() {
+ return impl.bitCount();
}
} \ No newline at end of file