public class ConcurrentBitSet extends 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 is based on "Lock-free Dynamically Resizable Arrays" by Dechev, Pirkelbauer, Bjarne Stroustrup. http://www.stroustrup.com/lock-free-vector.pdf
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 |
equals(Object obj)
Compares this object against the specified object.
|
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 |
hashCode()
Returns the hash code value for this bit set.
|
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(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
|
long[] |
toLongArray() |
String |
toString()
Returns a string representation of this bit set.
|
static ConcurrentBitSet |
valueOf(long[] values) |
void |
writeTo(File file) |
public boolean flip(int bitIndex)
bitIndex - the index of the bit to flipIndexOutOfBoundsException - if the specified index is negativepublic boolean set(int bitIndex)
true.bitIndex - a bit indexIndexOutOfBoundsException - if the specified index is negativepublic void set(int bitIndex,
boolean value)
bitIndex - a bit indexvalue - a boolean value to setIndexOutOfBoundsException - if the specified index is negativepublic boolean clear(int bitIndex)
false.bitIndex - the index of the bit to be clearedIndexOutOfBoundsException - 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 indexIndexOutOfBoundsException - 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 bitIndexOutOfBoundsException - 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)IndexOutOfBoundsException - if the specified index is negativepublic int hashCode()
The hash code is defined to be the result of the following calculation:
public int hashCode() {
long h = 1234;
for (int i = words.length; --i >= 0; )
h ^= words[i] * (i + 1);
return (int)((h >> 32) ^ h);
}
Note that the hash code changes if the set of bits is altered.public int size()
public boolean equals(Object obj)
true if and only if the argument is
not null and is a ConcurrentBitSet object that has
exactly the same set of bits set to true as this bit
set. That is, for every nonnegative int index k,
((ConcurrentBitSet)obj).get(k) == this.get(k)must be true. The current sizes of the two bit sets are not compared.
public String toString()
@NonNull public long[] toLongArray()
public void writeTo(@NonNull
File file)
throws IOException
IOException@NonNull public static ConcurrentBitSet readFrom(@NonNull File file) throws IOException
IOException@NonNull public static ConcurrentBitSet valueOf(@NonNull long[] values)
Copyright © 2017–2018 NukkitX. All rights reserved.