public class ConcurrentBitSet
extends java.lang.Object
java.util.BitSet except for some methods which don't make sense in concurrent environment or those i was too lazy to implement.
Implementation: bits stored packed in array, 32 bits per array element.
When bit change request comes, the array is reallocated as necessary.BitSet| Constructor and Description |
|---|
ConcurrentBitSet() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear method in presense of concurrency complicates everything to no end.
|
boolean |
clear(int bitIndex)
Sets the bit specified by the index to
false. |
boolean |
flip(int bitIndex)
Sets the bit at the specified index to the complement of its
current value.
|
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index.
|
int |
nextClearBit(int fromIndex)
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index. |
int |
nextSetBit(int fromIndex)
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. |
static ConcurrentBitSet |
readFrom(java.io.File file) |
boolean |
set(int bitIndex)
Sets the bit at the specified index to
true. |
void |
set(int bitIndex,
boolean value)
Sets the bit at the specified index to the specified value.
|
int |
size()
Returns the number of bits of space actually in use
|
int [] |
toIntArray() |
java.lang.String |
toString()
Returns a string representation of this bit set.
|
void |
writeTo(java.io.File file) |
public boolean flip(int bitIndex)
bitIndex - the index of the bit to flipjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic boolean set(int bitIndex)
true.bitIndex - a bit indexjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic void set(int bitIndex,
boolean value)
bitIndex - a bit indexvalue - a boolean value to setjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic boolean clear(int bitIndex)
false.bitIndex - the index of the bit to be clearedjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic void clear()
public boolean get(int bitIndex)
true if the bit with the index bitIndex
is currently set; otherwise, the result is false.bitIndex - the bit indexjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic int nextSetBit(int fromIndex)
true
that occurs on or after the specified starting index. If no such
bit exists then -1 is returned.
To iterate over the true bits,
use the following loop:
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
// operate on index i here
}fromIndex - the index to start checking from (inclusive)-1 if there
is no such bitjava.lang.IndexOutOfBoundsException - if the specified index is negativepublic int nextClearBit(int fromIndex)
false
that occurs on or after the specified starting index.fromIndex - the index to start checking from (inclusive)java.lang.IndexOutOfBoundsException - if the specified index is negativepublic int size()
public java.lang.String toString()
toString in class java.lang.Objectpublic int [] toIntArray()
public void writeTo(java.io.File file)
throws java.io.IOException
java.io.IOExceptionpublic static ConcurrentBitSet readFrom(java.io.File file) throws java.io.IOException
java.io.IOException