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() |
BitSet(int sizeInBits)
Construct a bitset with the specified number of bits (initially all
false).
|
| Modifier and Type | Method and Description |
|---|---|
void |
and(com.googlecode.javaewah.datastructure.WordArray bs)
Compute bitwise AND.
|
int |
andcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
Compute cardinality of bitwise AND.
|
void |
andNot(com.googlecode.javaewah.datastructure.WordArray bs)
Compute bitwise AND NOT.
|
int |
andNotcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
Compute cardinality of bitwise AND NOT.
|
static BitSet |
bitmapOf(int... setBits)
Return a bitmap with the bit set to true at the given positions.
|
int |
cardinality()
Compute the number of bits set to 1
|
void |
clear()
Reset all bits to false.
|
void |
clear(int index)
Set the bit to false.
|
void |
clear(int start,
int end)
Set the bits in the range of indexes to false.
|
BitSet |
clone() |
void |
deserialize(DataInput in)
Deserialize.
|
boolean |
empty()
Check whether a bitset contains a set bit.
|
boolean |
equals(Object o) |
void |
flip(int i)
Flip the bit.
|
void |
flip(int start,
int end)
Flip the bits in the range of indexes.
|
boolean |
get(int i)
Get the value of the bit.
|
int |
getNumberOfWords()
Get the total number of words contained in this data structure.
|
long |
getWord(int index)
Get the word at the given index
|
int |
hashCode() |
boolean |
intersects(com.googlecode.javaewah.datastructure.WordArray 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(com.googlecode.javaewah.datastructure.WordArray bs)
Compute bitwise OR.
|
int |
orcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
Compute cardinality of bitwise OR.
|
void |
readExternal(ObjectInput in) |
void |
resize(int sizeInBits)
Resize the bitset
|
void |
serialize(DataOutput out)
Serialize.
|
void |
set(int i)
Set to true.
|
void |
set(int i,
boolean b)
Set to some value.
|
void |
set(int start,
int end)
Set the bits in the range of indexes true.
|
void |
set(int start,
int end,
boolean v)
Set the bits in the range of indexes to the specified Boolean value.
|
int |
size()
Query the size
|
String |
toString() |
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(com.googlecode.javaewah.datastructure.WordArray bs)
Compute bitwise XOR.
|
int |
xorcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
Compute cardinality of bitwise XOR.
|
finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic BitSet(int sizeInBits)
sizeInBits - the size in bitspublic BitSet()
public void and(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int andcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic void andNot(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int andNotcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int cardinality()
public void clear()
public void clear(int index)
unset(int)index - location of the bitpublic void clear(int start,
int end)
start - location of the first bit to set to zeroend - location of the last bit to set to zero (not included)public boolean empty()
public void flip(int i)
i - index of the bitpublic void flip(int start,
int end)
start - location of the first bitend - location of the last bit (not included)public boolean get(int i)
i - indexpublic IntIterator intIterator()
public boolean intersects(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int nextSetBit(int i)
i - current set bitpublic int nextUnsetBit(int i)
i - current unset bitpublic void or(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int orcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic 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 void set(int start,
int end)
start - location of the first bitend - location of the last bit (not included)public void set(int start,
int end,
boolean v)
start - location of the first bitend - location of the last bit (not included)v - Boolean valuepublic 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 ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void serialize(DataOutput out) throws IOException
out - the DataOutput streamIOException - Signals that an I/O exception has occurred.public void deserialize(DataInput in) throws IOException
in - the DataInput streamIOException - Signals that an I/O exception has occurred.public void xor(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int xorcardinality(com.googlecode.javaewah.datastructure.WordArray bs)
bs - other bitsetpublic int getNumberOfWords()
public long getWord(int index)
index - the indexpublic static BitSet bitmapOf(int... setBits)
setBits - list of set bit positionsCopyright © 2015. All Rights Reserved.