public class SparseBitSet extends java.lang.Object implements XCloneable, java.io.Serializable
Modications by Philip R. "Pib" Burns to add missing BitSet methods.
Modifier and Type | Class and Description |
---|---|
protected static interface |
SparseBitSet.BinOp |
Modifier and Type | Field and Description |
---|---|
protected static SparseBitSet.BinOp |
AND |
protected static SparseBitSet.BinOp |
ANDNOT |
protected long[] |
bits
Array of bit-blocks; each holding BITS bits.
|
protected static int |
BITS
Number of bits in a block.
|
protected static int |
BITS_M1
BITS-1, using the identity: x % BITS == x & (BITS-1)
|
protected static int |
LG_BITS
log base 2 of BITS, for the identity: x/BITS == x >> LG_BITS
|
protected int[] |
offs
Sorted array of bit-block offsets.
|
protected static SparseBitSet.BinOp |
OR |
protected int |
size
Number of blocks currently in use.
|
protected static SparseBitSet.BinOp |
XOR |
Constructor and Description |
---|
SparseBitSet()
Create an empty set.
|
SparseBitSet(int nbits)
Create an empty set with the specified size.
|
SparseBitSet(SparseBitSet set)
Create an empty set with the same size as the given set.
|
Modifier and Type | Method and Description |
---|---|
void |
and(SparseBitSet otherSet)
Logically AND this bit set with another.
|
void |
andNot(SparseBitSet otherSet)
Logically ANDNOT this bit set with another.
|
protected static void |
binop(SparseBitSet a,
SparseBitSet b,
SparseBitSet.BinOp op) |
protected int |
bsearch(int bnum) |
int |
cardinality()
Return cardinality (# of bits set on) in this bit set.
|
void |
clear()
Clear all bits.
|
void |
clear(int bit)
Clear a bit.
|
void |
clear(int fromIndex,
int toIndex)
Clears a range of bits.
|
java.lang.Object |
clone()
Clone this set.
|
java.util.Enumeration |
elements()
Return an
Enumeration of Integer s
indices of bits set on in this SparseBitSet. |
boolean |
equals(java.lang.Object object)
Compare this set against another.
|
static boolean |
equals(SparseBitSet a,
SparseBitSet b)
Compare two SparseBitSets for equality.
|
void |
flip(int bit)
Flip a bit value.
|
void |
flip(int fromIndex,
int toIndex)
Flips a range of bits.
|
boolean |
get(int bit)
Get bit value.
|
int |
hashCode()
Return hash code for set.
|
protected void |
insert_block(int idx,
int bnum) |
boolean |
intersects(SparseBitSet otherSet)
Check if this set and another share at least one set bit.
|
protected boolean |
isValid()
Check validity.
|
int |
length()
Returns index of highest set bit in this set plus one.
|
protected void |
new_block(int bnum) |
protected void |
new_block(int idx,
int bnum) |
int |
nextClearBit(int fromIndex)
Returns index of first bit set to false that occurs on or after specified starting index.
|
int |
nextSetBit(int fromIndex)
Returns index of first bit set to true that occurs on or after specified starting index.
|
void |
or(SparseBitSet otherSet)
Logically OR this bit set with another.
|
void |
set(int bit)
Set a bit.
|
int |
size()
Return set's size.
|
java.lang.String |
toString()
Converts the SparseBitSet to a String.
|
void |
xor(SparseBitSet otherSet)
Logically XOR this bit set with another.
|
protected int[] offs
protected long[] bits
protected int size
protected static final int LG_BITS
protected static final int BITS
protected static final int BITS_M1
protected static final SparseBitSet.BinOp AND
protected static final SparseBitSet.BinOp OR
protected static final SparseBitSet.BinOp XOR
protected static final SparseBitSet.BinOp ANDNOT
public SparseBitSet()
public SparseBitSet(int nbits)
nbits
- The size of the set.public SparseBitSet(SparseBitSet set)
protected void new_block(int bnum)
protected void new_block(int idx, int bnum)
protected void insert_block(int idx, int bnum)
protected int bsearch(int bnum)
public void set(int bit)
bit
- The bit to set.public void clear(int bit)
bit
- The bit to be cleared.public void clear()
public void clear(int fromIndex, int toIndex)
fromIndex
- Index of first bit to be cleared.toIndex
- Index + 1 of last bit to be cleared.public void flip(int bit)
bit
- Bit to flip.public void flip(int fromIndex, int toIndex)
fromIndex
- Index of first bit to be flipped.toIndex
- Index + 1 of last bit to be flipped.public boolean get(int bit)
bit
- Bit whose value is to be retrieved.public void and(SparseBitSet otherSet)
otherSet
- The other bit set to AND against.public void or(SparseBitSet otherSet)
otherSet
- The other bit set to be ORed against.public void xor(SparseBitSet otherSet)
otherSet
- The other bit set to be XORed against.public void andNot(SparseBitSet otherSet)
otherSet
- The other bit set to be ANDNOTed against.protected static final void binop(SparseBitSet a, SparseBitSet b, SparseBitSet.BinOp op)
public int hashCode()
hashCode
in class java.lang.Object
public int size()
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- The object to compare against.public static boolean equals(SparseBitSet a, SparseBitSet b)
public int cardinality()
public boolean intersects(SparseBitSet otherSet)
otherSet
- The other set to check for intersectionpublic int length()
public int nextSetBit(int fromIndex)
fromIndex
- Index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if specified index
is negative.
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
}
public int nextClearBit(int fromIndex)
fromIndex
- Index to start checking from (inclusive).java.lang.IndexOutOfBoundsException
- if specified index
is negative.
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
}
public java.lang.Object clone()
clone
in interface XCloneable
clone
in class java.lang.Object
public java.util.Enumeration elements()
Enumeration
of Integer
s
indices of bits set on in this SparseBitSet.public java.lang.String toString()
toString
in class java.lang.Object
protected boolean isValid()