public final class HugeBitSet
extends java.lang.Object
Note that the maximum size of a HugeBitSet is 2**32 - 1 bits.
Constructor and Description |
---|
HugeBitSet()
Create a HugeBitSet with no preallocated blocks.
|
HugeBitSet(int prealloc)
Create a HugeBitSet with memory allocated for up to the specific bit number,
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all the bits in the HugeBitSet.
|
boolean |
clear(int index)
Clear the specified bit in the HugeBitSet.
|
boolean |
get(int index)
Test if the specified bit is set in the HugeBitSet.
|
boolean |
isSet(int index)
Test if the specified bit is set in the HugeBitSet.
|
boolean |
isSet(long index)
Test if the specified bit is set in the HugeBitSet.
|
void |
justSet(int index)
Set the specified bit in the HugeBitSet without returning the former state.
|
void |
justSet(long index)
Set the specified bit in the HugeBitSet without returning the former state.
|
int |
length()
Get the maximum number of bits currently allocated in this HugeBitSet.
|
int |
nextClearBit(int index)
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index. |
int |
nextSetBit(int index)
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. |
void |
preallocate(int numBits)
Ensure that enough storage has been allocated in the HugeBitSet to hold at least the
specified range of bits.
|
int |
previousClearBit(int index)
Returns the index of the first bit that is set to
false
that occurs on or prior the specified starting index. |
int |
previousSetBit(int index)
Returns the index of the first bit that is set to
true
that occurs on or before the specified starting index. |
boolean |
set(int index)
Set the specified bit in the HugeBitSet.
|
boolean |
setIfNot(int index)
Set the specified bit in the HugeBitSet and indicate whether this was a change.
|
java.lang.String |
toString()
Generate a String describing this HugeBitSet.
|
public HugeBitSet()
public HugeBitSet(int prealloc)
prealloc
- highest bit number to preallocate forpublic boolean set(int index)
index
- zero-based int index of the bit to setpublic void justSet(int index)
index
- zero-based int index of the bit to setpublic void justSet(long index)
index
- zero-based long index of the bit to setpublic boolean setIfNot(int index)
index
- zero-based int index of the bit to setpublic boolean clear(int index)
index
- zero-based int index of the bit to setpublic void clear()
public void preallocate(int numBits)
numBits
- highest bit number for which storage should be allocated when this method returnspublic boolean get(int index)
index
- zero-based index of bit to testpublic boolean isSet(int index)
index
- zero-based index of bit to testpublic boolean isSet(long index)
index
- zero-based index of bit to testpublic java.lang.String toString()
toString
in class java.lang.Object
public int length()
public int nextSetBit(int index)
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 in a BitSet
,
use the following loop:
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
// operate on index i here
}
index
- the index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if the specified index is negative.public int nextClearBit(int index)
false
that occurs on or after the specified starting index. If no such
bit exists then -1 is returned.
To iterate over the false
bits in a BitSet
,
use the following loop:
for (int i = bs.nextClearBit(0); i >= 0; i = bs.nextClearBit(i+1)) {
// operate on index i here
}
index
- the index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if the specified index is negative.public int previousSetBit(int index)
true
that occurs on or before the specified starting index. If no such
bit exists then -1 is returned.
To iterate over the true
bits in a BitSet
,
use the following loop:
for (int i = bs.previousSetBit(Integer.MAX_VALUE); i >= 0; i = bs.previousSetBit(i-1)) {
// operate on index i here
}
index
- the index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if the specified index is negative.public int previousClearBit(int index)
false
that occurs on or prior the specified starting index. If no such
bit exists then -1 is returned.
To iterate over the false
bits in a BitSet
,
use the following loop:
for (int i = bs.previousClearBit(Integer.MAX_VALUE); i >= 0; i = bs.previousClearBit(i+1)) {
// operate on index i here
}
index
- the index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if the specified index is negative.