|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.xinapse.util.BitSet
public class BitSet
A class representing an array of binary (1-bit) values in a more compact way than does a boolean[]. It is based on the standard class java.util.BitSet, but the number of bits that can be stored is fixed at instantiation. This implementation is NOT synchronized against concurrent access from multiple threads. Specifically, if one thread is reading from a BitSet while another thread is simultaneously modifying it, the results are undefined.
| Constructor Summary | |
|---|---|
BitSet(int nbits)
Create a new empty bit set, with a given size. |
|
| Method Summary | |
|---|---|
void |
and(BitSet bs)
Performs the logical AND operation on this bit set and the given BitSet. |
void |
andNot(BitSet bs)
Performs the logical AND operation on this bit set and the complement of the given BitSet. |
int |
cardinality()
Returns the number of bits set to true. |
void |
clear()
Sets all bits in the set to false. |
void |
clear(int bitIndex)
Removes the integer bitIndex from this set. |
void |
clear(int from,
int to)
Sets the bits between from (inclusive) and to (exclusive) to false. |
BitSet |
clone()
Create a clone of this bit set, that is an instance of the same class and contains the same elements. |
boolean |
equals(java.lang.Object obj)
Returns true if the obj is a bit set that contains exactly the same elements as this bit set, otherwise false. |
void |
flip()
Sets all bits to the opposite value. |
void |
flip(int bitIndex)
Sets the bit at the index to the opposite value. |
void |
flip(int from,
int to)
Sets a range of bits to the opposite value. |
boolean |
get(int bitIndex)
Returns true if the integer bitIndex is in this bit set, otherwise false. |
BitSet |
get(int from,
int to)
Returns a new BitSet composed of a range of bits from this one. |
int |
hashCode()
Returns a hash code value for this bit set. |
boolean |
intersects(BitSet bs)
Returns true if the specified BitSet and this one share at least one common true bit. |
boolean |
isEmpty()
Returns true if this set contains no true bits. |
int |
nextClearBit(int from)
Returns the index of the next false bit, from the specified bit (inclusive). |
int |
nextSetBit(int from)
Returns the index of the next true bit, from the specified bit (inclusive). |
void |
or(BitSet bs)
Performs the logical OR operation on this bit set and the given BitSet. |
void |
set()
Sets all bits in the set to true. |
void |
set(int bitIndex)
Add the integer bitIndex to this set. |
void |
set(int bitIndex,
boolean value)
Sets the bit at the given index to the specified value. |
void |
set(int from,
int to)
Sets the bits between from (inclusive) and to (exclusive) to true. |
void |
set(int from,
int to,
boolean value)
Sets the bits between from (inclusive) and to (exclusive) to the specified value. |
int |
size()
Returns the number of bits that can be stored by this bit set. |
java.lang.String |
toString()
Returns the string representation of this bit set. |
void |
xor(BitSet bs)
Performs the logical XOR operation on this bit set and the given BitSet. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BitSet(int nbits)
nbits - the size of the bit set.
java.lang.NegativeArraySizeException - if nbits < 0.| Method Detail |
|---|
public void and(BitSet bs)
bs - the second bit set.
java.lang.NullPointerException - if set is null.public void andNot(BitSet bs)
bs - the second bit set.
java.lang.NullPointerException - if set is null.public int cardinality()
public void clear()
public void set()
public void clear(int bitIndex)
bitIndex - a non-negative integer.
java.lang.IndexOutOfBoundsException - if bitIndex < 0 or if bitIndex >= nbits.
public void clear(int from,
int to)
from - the start range (inclusive).to - the end range (exclusive).
java.lang.IndexOutOfBoundsException - if from < 0 || from > to || to > nbits.public BitSet clone()
clone in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object to compare to.
public void flip(int bitIndex)
bitIndex - the index of the bit.
java.lang.IndexOutOfBoundsException - if bitIndex is negative or if bitIndex >= nbits.public void flip()
public void flip(int from,
int to)
from - the low index (inclusive).to - the high index (exclusive).
java.lang.IndexOutOfBoundsException - if from > to || from < 0 || to > nbits.public boolean get(int bitIndex)
bitIndex - a non-negative integer.
java.lang.IndexOutOfBoundsException - if the bitIndex is negative or if bitIndex >= nbits.
public BitSet get(int from,
int to)
from - the low index (inclusive).to - the high index (exclusive).
java.lang.IndexOutOfBoundsException - if from > to || from < 0 || to >= nbits.public int hashCode()
public int hashCode()
{
long h = 1234;
for (int i = bits.length-1; i >= 0; i--)
{
h ^= bits[i] * (i + 1);
}
return (int)((h >> 32) ^ h);
}
Note that the hash code values changes, if the set is changed.
hashCode in class java.lang.Objectpublic boolean intersects(BitSet bs)
bs - the set to check for intersection.
java.lang.NullPointerException - if set is null.public boolean isEmpty()
public int nextClearBit(int from)
from - the start location.
java.lang.IndexOutOfBoundsException - if from is negative or if from is >= nbits.public int nextSetBit(int from)
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1))
{
// operate on i here
}
from - the start location.
java.lang.IndexOutOfBoundsException - if from is negative.public void or(BitSet bs)
bs - the second bit set.
java.lang.NullPointerException - if bs is null.
java.lang.IndexOutOfBoundsException - if nbits for bs is greater than nbits for this
BitSet.public void set(int bitIndex)
bitIndex - a non-negative integer.
java.lang.IndexOutOfBoundsException - if bitIndex is negative or >=nbits.
public void set(int bitIndex,
boolean value)
bitIndex - the position to set.value - the value to set it to.
java.lang.IndexOutOfBoundsException - if bitIndex is negative or if bitIndex is >= nbits.
public void set(int from,
int to)
from - the start range (inclusive).to - the end range (exclusive).
java.lang.IndexOutOfBoundsException - if from < 0 || from > to || to > nbits.
public void set(int from,
int to,
boolean value)
from - the start range (inclusive).to - the end range (exclusive).value - the value to set it to.
java.lang.IndexOutOfBoundsException - if from < 0 || from > to || to >= nbits.public int size()
public java.lang.String toString()
toString in class java.lang.Objectpublic void xor(BitSet bs)
bs - the second bit set.
java.lang.NullPointerException - if bs is null.
java.lang.IndexOutOfBoundsException - if nbits for bs is greater than nbits for this
BitSet.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||