public class BitSet extends Object implements Cloneable, Iterable<Integer>, Externalizable
This is an optimized version of Java's BitSet. In many cases, it can be used as a drop-in replacement.
It differs from the basic Java BitSet class in the following ways:
for(int bs: myBitset)
.Constructor and Description |
---|
BitSet(int sizeInBits)
Construct a bitset with the specified number of bits (initially all
false).
|
Modifier and Type | Method and Description |
---|---|
void |
and(BitSet bs)
Compute bitwise AND.
|
int |
andcardinality(BitSet bs)
Compute cardinality of bitwise AND.
|
void |
andNot(BitSet bs)
Compute bitwise AND NOT.
|
int |
andNotcardinality(BitSet bs)
Compute cardinality of bitwise AND NOT.
|
int |
cardinality()
Compute the number of bits set to 1
|
void |
clear()
Reset all bits to false.
|
BitSet |
clone() |
boolean |
empty()
Check whether a bitset contains a set bit.
|
boolean |
equals(Object o) |
boolean |
get(int i) |
int |
hashCode() |
boolean |
intersects(BitSet bs)
Checks whether two bitsets intersect.
|
IntIterator |
intIterator()
Iterate over the set bits
|
Iterator<Integer> |
iterator() |
int |
nextSetBit(int i)
Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) {
operate on index i here }
|
int |
nextUnsetBit(int i)
Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1))
{ operate on index i here }
|
void |
or(BitSet bs)
Compute bitwise OR.
|
int |
orcardinality(BitSet bs)
Compute cardinality of bitwise OR.
|
void |
readExternal(ObjectInput in) |
void |
resize(int sizeInBits)
Resize the bitset
|
void |
set(int i)
Set to true
|
void |
set(int i,
boolean b) |
int |
size()
Query the size
|
void |
trim()
Recovers wasted memory
|
void |
unset(int i)
Set to false
|
IntIterator |
unsetIntIterator()
Iterate over the unset bits
|
void |
writeExternal(ObjectOutput out) |
void |
xor(BitSet bs)
Compute bitwise XOR.
|
int |
xorcardinality(BitSet bs)
Compute cardinality of bitwise XOR.
|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public BitSet(int sizeInBits)
sizeInBits
- the size in bitspublic void and(BitSet bs)
bs
- other bitsetpublic int andcardinality(BitSet bs)
bs
- other bitsetpublic void andNot(BitSet bs)
bs
- other bitsetpublic int andNotcardinality(BitSet bs)
bs
- other bitsetpublic int cardinality()
public void clear()
public BitSet clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public boolean empty()
public boolean get(int i)
i
- indexpublic IntIterator intIterator()
public boolean intersects(BitSet bs)
bs
- other bitsetpublic int nextSetBit(int i)
i
- current set bitpublic int nextUnsetBit(int i)
i
- current unset bitpublic void or(BitSet bs)
bs
- other bitsetpublic int orcardinality(BitSet bs)
bs
- other bitsetpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public void resize(int sizeInBits)
sizeInBits
- new number of bitspublic void set(int i)
i
- index of the bitpublic void set(int i, boolean b)
i
- indexb
- value of the bitpublic int size()
public void trim()
public void unset(int i)
i
- index of the bitpublic IntIterator unsetIntIterator()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void xor(BitSet bs)
bs
- other bitsetpublic int xorcardinality(BitSet bs)
bs
- other bitsetCopyright © 2014. All Rights Reserved.