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).| Modifier and Type | Field and Description |
|---|---|
| pack-priv long[] | |
| pack-priv static final long |
| Access | Constructor and Description |
|---|---|
| public | BitSet(final int
the size in bits sizeInBits)Construct a bitset with the specified number of bits (initially all false). |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public int | |
| public void | |
| public int | Returns: cardinalityother bitset bs)Compute cardinality of bitwise AND NOT. |
| public static BitSet | Returns: the bitmaplist of set bit positions setBits)Return a bitmap with the bit set to true at the given positions. |
| public int | |
| public void | |
| public void | |
| public void | clear(int
location of the first bit to set to zero start, int location of the last bit to set to zero (not included) end)Set the bits in the range of indexes to false. |
| public BitSet | |
| public void | |
| public boolean | |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
| public void | |
| public void | flip(int
location of the first bit start, int location of the last bit (not included) end)Flip the bits in the range of indexes. |
| public boolean | |
| public int | getNumberOfWords()
Implements com. Get the total number of words contained in this data structure. |
| public long | getWord(int
the index index)Implements com. Get the word at the given index |
| public int | |
| public boolean | Returns: true if they have a non-empty intersection (result of AND)other bitset bs)Checks whether two bitsets intersect. |
| public IntIterator | |
| public Iterator | |
| public int | Returns: next set bit or -1current set bit i)Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here } |
| public int | Returns: next unset bit or -1current unset bit i)Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here } |
| public void | |
| public int | |
| public void | readExternal(ObjectInput
the stream to read data from in order to restore the object in)Implements java. The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | set(int
location of the first bit start, int location of the last bit (not included) end)Set the bits in the range of indexes true. |
| public void | set(int
location of the first bit start, int location of the last bit (not included) end, boolean Boolean value v)Set the bits in the range of indexes to the specified Boolean value. |
| public int | |
| public String | |
| public void | |
| public void | |
| public IntIterator | |
| public void | writeExternal(ObjectOutput
the stream to write the object to out)Implements java. The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays. |
| public void | |
| public int |
| data | back to summary |
|---|---|
| pack-priv long[] data | |
| serialVersionUID | back to summary |
|---|---|
| pack-priv static final long serialVersionUID | |
| BitSet | back to summary |
|---|---|
| public BitSet(final int sizeInBits) Construct a bitset with the specified number of bits (initially all false). The number of bits is rounded up to the nearest multiple of 64.
| |
| BitSet | back to summary |
|---|---|
| public BitSet() | |
| and | back to summary |
|---|---|
| public void and(WordArray bs) Compute bitwise AND.
| |
| andcardinality | back to summary |
|---|---|
| public int andcardinality(WordArray bs) Compute cardinality of bitwise AND. The current bitmap is modified. Consider calling trim() to recover wasted memory afterward.
| |
| andNot | back to summary |
|---|---|
| public void andNot(WordArray bs) Compute bitwise AND NOT. The current bitmap is modified. Consider calling trim() to recover wasted memory afterward.
| |
| andNotcardinality | back to summary |
|---|---|
| public int andNotcardinality(WordArray bs) Compute cardinality of bitwise AND NOT.
| |
| bitmapOf | back to summary |
|---|---|
| public static BitSet bitmapOf(int... setBits) Return a bitmap with the bit set to true at the given positions. (This is a convenience method.)
| |
| cardinality | back to summary |
|---|---|
| public int cardinality() Compute the number of bits set to 1
| |
| clear | back to summary |
|---|---|
| public void clear() Reset all bits to false. This might be wasteful: a better approach is to create a new empty bitmap. | |
| clear | back to summary |
|---|---|
| public void clear(int index) Set the bit to false.
See
| |
| clear | back to summary |
|---|---|
| public void clear(int start, int end) Set the bits in the range of indexes to false. This might throw an exception if size() is insufficient, consider calling resize().
| |
| clone | back to summary |
|---|---|
| public BitSet clone() Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by | |
| deserialize | back to summary |
|---|---|
| public void deserialize(DataInput in) throws IOException Deserialize.
| |
| empty | back to summary |
|---|---|
| public boolean empty() Check whether a bitset contains a set bit.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| flip | back to summary |
|---|---|
| public void flip(final int i) Flip the bit. This might throw an exception if size() is insufficient, consider calling resize().
| |
| flip | back to summary |
|---|---|
| public void flip(int start, int end) Flip the bits in the range of indexes. This might throw an exception if size() is insufficient, consider calling resize().
| |
| get | back to summary |
|---|---|
| public boolean get(final int i) Get the value of the bit. This might throw an exception if size() is insufficient, consider calling resize().
| |
| getNumberOfWords | back to summary |
|---|---|
| public int getNumberOfWords() Implements com. Doc from com. Get the total number of words contained in this data structure.
| |
| getWord | back to summary |
|---|---|
| public long getWord(int index) Implements com. Doc from com. Get the word at the given index
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| intersects | back to summary |
|---|---|
| public boolean intersects(WordArray bs) Checks whether two bitsets intersect.
| |
| intIterator | back to summary |
|---|---|
| public IntIterator intIterator() Iterate over the set bits
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over elements of type | |
| nextSetBit | back to summary |
|---|---|
| public int nextSetBit(final int i) Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }
| |
| nextUnsetBit | back to summary |
|---|---|
| public int nextUnsetBit(final int i) Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }
| |
| or | back to summary |
|---|---|
| public void or(WordArray bs) Compute bitwise OR. The current bitmap is modified. Consider calling trim() to recover wasted memory afterward.
| |
| orcardinality | back to summary |
|---|---|
| public int orcardinality(WordArray bs) Compute cardinality of bitwise OR. BitSets are not modified.
| |
| readExternal | back to summary |
|---|---|
| public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException Implements java. Doc from java. The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.
| |
| removeWord | back to summary |
|---|---|
| public void removeWord(int i) Remove a word.
| |
| resize | back to summary |
|---|---|
| public void resize(int sizeInBits) Resize the bitset
| |
| serialize | back to summary |
|---|---|
| public void serialize(DataOutput out) throws IOException Serialize. The current bitmap is not modified.
| |
| set | back to summary |
|---|---|
| public void set(final int i) Set to true. This might throw an exception if size() is insufficient, consider calling resize().
| |
| set | back to summary |
|---|---|
| public void set(final int i, final boolean b) Set to some value. This might throw an exception if size() is insufficient, consider calling resize().
| |
| set | back to summary |
|---|---|
| public void set(int start, int end) Set the bits in the range of indexes true. This might throw an exception if size() is insufficient, consider calling resize().
| |
| set | back to summary |
|---|---|
| public void set(int start, int end, boolean v) Set the bits in the range of indexes to the specified Boolean value. This might throw an exception if size() is insufficient, consider calling resize().
| |
| size | back to summary |
|---|---|
| public int size() Query the size
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| trim | back to summary |
|---|---|
| public void trim() Recovers wasted memory | |
| unset | back to summary |
|---|---|
| public void unset(final int i) Set to false
| |
| unsetIntIterator | back to summary |
|---|---|
| public IntIterator unsetIntIterator() Iterate over the unset bits
| |
| writeExternal | back to summary |
|---|---|
| public void writeExternal(ObjectOutput out) throws IOException Implements java. Doc from java. The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
| |
| xor | back to summary |
|---|---|
| public void xor(WordArray bs) Compute bitwise XOR. The current bitmap is modified. Consider calling trim() to recover wasted memory afterward.
| |
| xorcardinality | back to summary |
|---|---|
| public int xorcardinality(WordArray bs) Compute cardinality of bitwise XOR. BitSets are not modified.
| |