public class OpenBitSet implements BitSet
An "open" BitSet implementation that allows direct access to the array of words storing the bits.
Unlike java.util.bitset, the fact that bits are packed into an array of longs is part of the interface. This allows efficient implementation of other algorithms by someone other than the author. It also allows one to efficiently implement alternate serialization or interchange formats. < code>OpenBitSet is faster than java.util.BitSet in most operations and *much* faster at calculating cardinality of sets and results of set operations. It can also handle sets of larger cardinality (up to 64 * 2**32-1) The goals of OpenBitSet are the fastest implementation possible, and maximum code reuse. Extra safety and encapsulation may always be built on top, but if that's built in, the cost can never be removed (and hence people re-implement their own version in order to get better performance). If you want a "safe", totally encapsulated (and slower and limited) BitSet class, use java.util.BitSet. Performance Results Test system: Pentium 4, Sun Java 1.5_06 -server -Xbatch -Xmx64M
BitSet size = 1,000,000
Results are java.util.BitSet time divided by OpenBitSet time. cardinality intersect_count union nextSetBit get iterator 50% full 3.36 3.96 1.44 1.46 1.99 1.58 1% full 3.31 3.90 1.04 0.99
Test system: AMD Opteron, 64 bit linux, Sun Java 1.5_06 -server -Xbatch -Xmx64M
BitSet size = 1,000,000
Results are java.util.BitSet time divided by OpenBitSet time. cardinality intersect_count union nextSetBit get iterator 50% full 2.50 3.50 1.00 1.03 1.12 1.25 1% full 2.51 3.49 1.00 1.02
public OpenBitSet(long numBits)
Constructs an OpenBitSet large enough to hold numBits.
numBits - public OpenBitSet()
public OpenBitSet(kotlin.Array[] bits,
int numWords)
Constructs an OpenBitSet from an existing long[].
The first 64 bits are in long[0], with bit index 0 at the least significant bit, and bit index 63 at the most significant. Given a bit index, the word containing it is long[index/64], and it is at bit number index%64 within that word.
numWords are the number of elements in the array that contain set bits (non-zero longs). numWords should be <= bits.length, and any existing words in the array at position >= numWords should be zero.
public OpenBitSet(kotlin.Array[] bits)
public OpenBitSet(BitSet cloneOBS)
public long capacity()
Returns the current capacity in bits (1 greater than the index of the last bit)
public long size()
Returns the current capacity of this set. Included for compatibility. This is *not* equal to net.maizegenetics.util.OpenBitSet$cardinality()
public boolean isEmpty()
Returns true if there are no set bits
public kotlin.Array[] getBits()
Expert: returns the long[] storing the bits
public long getBits(int index)
public void setBits(kotlin.Array[] bits)
Expert: sets a new long[] to use as the bit storage
public void setLong(int wordNum,
long bits)
Expert: sets specified word with given bits.
wordNum - word indexbits - bitspublic int getNumWords()
Expert: gets the number of longs in the array that are in use
public void setNumWords(int nWords)
Expert: sets the number of longs in the array that are in use
public boolean get(int index)
Returns true or false for the specified bit index.
public boolean fastGet(int index)
Returns true or false for the specified bit index. The index should be less than the OpenBitSet size
public boolean get(long index)
Returns true or false for the specified bit index
public boolean fastGet(long index)
Returns true or false for the specified bit index. The index should be less than the OpenBitSet size.
public int getBit(int index)
returns 1 if the bit is set, 0 if not. The index should be less than the OpenBitSet size
public void set(long index)
sets a bit, expanding the set size if necessary
public void fastSet(int index)
Sets the bit at the specified index. The index should be less than the OpenBitSet size.
public void fastSet(long index)
Sets the bit at the specified index. The index should be less than the OpenBitSet size.
public void set(long startIndex,
long endIndex)
Sets a range of bits, expanding the set size if necessary
startIndex - lower indexendIndex - one-past the last bit to setprotected int expandingWordNum(long index)
public void fastClear(int index)
clears a bit. The index should be less than the OpenBitSet size.
public void fastClear(long index)
clears a bit. The index should be less than the OpenBitSet size.
public void clear(long index)
clears a bit, allowing access beyond the current set size without changing the size.
public void clear(int startIndex,
int endIndex)
Clears a range of bits. Clearing past the end does not change the size of the set.
startIndex - lower indexendIndex - one-past the last bit to clearpublic void clear(long startIndex,
long endIndex)
Clears a range of bits. Clearing past the end does not change the size of the set.
startIndex - lower indexendIndex - one-past the last bit to clearpublic boolean getAndSet(int index)
Sets a bit and returns the previous value. The index should be less than the OpenBitSet size.
public boolean getAndClear(int index)
public boolean getAndSet(long index)
Sets a bit and returns the previous value. The index should be less than the OpenBitSet size.
public void fastFlip(int index)
flips a bit. The index should be less than the OpenBitSet size.
public void fastFlip(long index)
flips a bit. The index should be less than the OpenBitSet size.
public void flip(long index)
flips a bit, expanding the set size if necessary
public boolean flipAndGet(int index)
flips a bit and returns the resulting bit value. The index should be less than the OpenBitSet size.
public boolean flipAndGet(long index)
flips a bit and returns the resulting bit value. The index should be less than the OpenBitSet size.
public void flip(long startIndex,
long endIndex)
Flips a range of bits, expanding the set size if necessary
startIndex - lower indexendIndex - one-past the last bit to flippublic long cardinality()
public long cardinality(int index)
public static long intersectionCount(BitSet a, BitSet b)
Returns the popcount or cardinality of the intersection of the two sets. Neither set is modified.
public static long unionCount(BitSet a, BitSet b)
Returns the popcount or cardinality of the union of the two sets. Neither set is modified.
public static long andNotCount(BitSet a, BitSet b)
Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))". Neither set is modified.
public static long xorCount(BitSet a, BitSet b)
Returns the popcount or cardinality of the exclusive-or of the two sets. Neither set is modified.
public int nextSetBit(int index)
Returns the index of the first set bit starting at the index specified. -1 is returned if there are no more set bits.
public long nextSetBit(long index)
Returns the index of the first set bit starting at the index specified. -1 is returned if there are no more set bits.
public int previousSetBit(int index)
public long previousSetBit(long index)
public java.lang.Object clone()
public void intersect(BitSet other)
this = this AND other
public void union(BitSet other)
this = this OR other
public void remove(BitSet other)
Remove all elements set in other. this = this AND_NOT other
public void xor(BitSet other)
this = this XOR other
public void notXor(BitSet other)
this = not(this XOR other)
public void not()
this = not(this)
public void and(BitSet other)
see intersect
other - public void or(BitSet other)
see union
public void andNot(BitSet other)
see andNot
public boolean intersects(BitSet other)
returns true if the sets have any elements in common
public void ensureCapacityWords(int numWords)
Expand the long[] with the size given as a number of words (64 bit longs). getNumWords() is unchanged by this call.
public void ensureCapacity(long numBits)
Ensure that the long[] is big enough to hold numBits, expanding it if necessary. getNumWords() is unchanged by this call.
public void trimTrailingZeros()
Lowers numWords, the number of words in use, by checking for trailing zero words.
public int indexOfNthSetBit(int n)
public kotlin.Array[] getIndicesOfSetBits()
public boolean equals(java.lang.Object o)
returns true if both sets have the same bits set
public int hashCode()
public kotlin.Array[] getBits(int startWord,
int endWord)