Unlike java., 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.
The index range for a bitset can easily exceed positive int range in Java
(0x7fffffff), so many methods in this class accept or return a long. There are
adapter methods that return views compatible with LongLookupContainer and IntLookupContainer interfaces.
asIntLookupContainer(), asLongLookupContainer()
| Modifier and Type | Field and Description |
|---|---|
| public long[] | bits
Internal representation of bits in this bit set. |
| private static final long | DEFAULT_NUM_BITS
The initial default number of bits. |
| public int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | BitSet(long[]
underlying bits buffer bits, int the number of elements in the array that contain set bits numWords)Constructs an BitSet from an existing long[]. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public static long | Returns: Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))". Neither set is modified.The first set a, BitSet The second set b)
|
| public IntLookupContainer | Returns: The view of this bitset asIntLookupContainer.Returns a view over this bitset data compatible with |
| public LongLookupContainer | Returns: The view of this bitset asLongLookupContainer.Returns a view over this bitset data compatible with |
| public static int | |
| public long | |
| public long | |
| public void | |
| public void | clear(long
the index to clear index)clears a bit, allowing access beyond the current set size without changing the size. |
| public void | |
| public void | clear(long
lower index startIndex, long one-past the last bit to clear endIndex)Clears a range of bits. |
| public Object | |
| public void | ensureCapacity(long
The number of bits to expand to numBits)Ensure that the long[] is big enough to hold numBits, expanding it if necessary. |
| public void | ensureCapacityWords(int
The size to expand to (64-bit long words) numWords)Expand the long[] with the size given as a number of words (64 bit longs). |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
| protected int | |
| public void | |
| public void | flip(long
lower index startIndex, long one-past the last bit to flip endIndex)Flips a range of bits, expanding the set size if necessary |
| public boolean | Returns: previous state of the indexthe index to flip index)flips a bit and returns the resulting bit value. |
| public boolean | Returns: previous state of the indexthe index to flip index)flips a bit and returns the resulting bit value. |
| public boolean | |
| public boolean | |
| public boolean | Returns: previous state of the indexthe index to set index)Sets a bit and returns the previous value. |
| public boolean | Returns: previous state of the indexthe index to set index)Sets a bit and returns the previous value. |
| public static int | |
| public static long[] | |
| public int | |
| public void | |
| public static long | Returns: Returns the popcount or cardinality of the intersection of the two sets. Neither set is modified.The first set a, BitSet The second set b)
|
| public boolean | |
| public boolean | |
| public BitSetIterator | Returns: Returns an iterator over all set bits of this bitset. The iterator should be faster than using a loop aroundnextSetBit(int).
|
| public long | Returns: Returns the "logical size" of thisBitSet: the index of the highest set bit in
the BitSet plus one.
|
| public static BitSet | Returns: New instance.Static constructor-like method similar to other (generic) collections. |
| public int | Returns: Returns the index of the first set bit starting at the index specified. -1 is returned if there are no more set bits.The index to start scanning from, inclusive. index)
|
| public long | Returns: Returns the index of the first set bit starting at the index specified. -1 is returned if there are no more set bits.The index to start scanning from, inclusive. index)
|
| public void | |
| public void | |
| public void | |
| public void | set(long
lower index startIndex, long one-past the last bit to set endIndex)Sets a range of bits, expanding the set size if necessary |
| public long | Returns: Returns the current capacity of this set. Included for compatibility. This is not equal tocardinality.
|
| public String | |
| public void | |
| public void | |
| public static long | Returns: Returns the popcount or cardinality of the union of the two sets. Neither set is modified.The first set a, BitSet The second set b)
|
| public void | |
| public static long |
| bits | back to summary |
|---|---|
| public long[] bits Internal representation of bits in this bit set. | |
| DEFAULT_NUM_BITS | back to summary |
|---|---|
| private static final long DEFAULT_NUM_BITS The initial default number of bits. | |
| wlen | back to summary |
|---|---|
| public int wlen The number of words (longs) used in the | |
| BitSet | back to summary |
|---|---|
| public BitSet() Constructs a bit set with the default capacity. | |
| BitSet | back to summary |
|---|---|
| public BitSet(long numBits) Constructs an BitSet large enough to hold numBits.
| |
| BitSet | back to summary |
|---|---|
| public BitSet(long[] bits, int numWords) Constructs an BitSet 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.
| |
| and | back to summary |
|---|---|
| public void and(BitSet other) | |
| andNot | back to summary |
|---|---|
| public void andNot(BitSet other) | |
| andNotCount | back to summary |
|---|---|
| public static long andNotCount(BitSet a, BitSet b) | |
| asIntLookupContainer | back to summary |
|---|---|
| public IntLookupContainer asIntLookupContainer() Returns a view over this bitset data compatible with Methods of the returned
| |
| asLongLookupContainer | back to summary |
|---|---|
| public LongLookupContainer asLongLookupContainer() Returns a view over this bitset data compatible with
| |
| bits2words | back to summary |
|---|---|
| public static int bits2words(long numBits) | |
| capacity | back to summary |
|---|---|
public long capacity()
| |
| cardinality | back to summary |
|---|---|
public long cardinality()
| |
| clear | back to summary |
|---|---|
| public void clear() Clears all bits. | |
| clear | back to summary |
|---|---|
| public void clear(long index) clears a bit, allowing access beyond the current set size without changing the size.
| |
| clear | back to summary |
|---|---|
| public void clear(int startIndex, int endIndex) Clears a range of bits. Clearing past the end does not change the size of the set.
| |
| clear | back to summary |
|---|---|
| public void clear(long startIndex, long endIndex) Clears a range of bits. Clearing past the end does not change the size of the set.
| |
| clone | back to summary |
|---|---|
| public Object 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 | |
| ensureCapacity | back to summary |
|---|---|
| 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.
| |
| ensureCapacityWords | back to summary |
|---|---|
| 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.
| |
| 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. | |
| expandingWordNum | back to summary |
|---|---|
| protected int expandingWordNum(long index) | |
| flip | back to summary |
|---|---|
| public void flip(long index) Flips a bit, expanding the set size if necessary.
| |
| flip | back to summary |
|---|---|
| public void flip(long startIndex, long endIndex) Flips a range of bits, expanding the set size if necessary
| |
| flipAndGet | back to summary |
|---|---|
| public boolean flipAndGet(int index) flips a bit and returns the resulting bit value. The index should be less than the BitSet size.
| |
| flipAndGet | back to summary |
|---|---|
| public boolean flipAndGet(long index) flips a bit and returns the resulting bit value. The index should be less than the BitSet size.
| |
| get | back to summary |
|---|---|
public boolean get(int index)
| |
| get | back to summary |
|---|---|
public boolean get(long index)
| |
| getAndSet | back to summary |
|---|---|
| public boolean getAndSet(int index) Sets a bit and returns the previous value. The index should be less than the BitSet size.
| |
| getAndSet | back to summary |
|---|---|
| public boolean getAndSet(long index) Sets a bit and returns the previous value. The index should be less than the BitSet size.
| |
| getNextSize | back to summary |
|---|---|
| public static int getNextSize(int targetSize) | |
| grow | back to summary |
|---|---|
| public static long[] grow(long[] array, int minSize) | |
| 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
| |
| intersect | back to summary |
|---|---|
| public void intersect(BitSet other) this = this AND other
| |
| intersectionCount | back to summary |
|---|---|
| public static long intersectionCount(BitSet a, BitSet b) | |
| intersects | back to summary |
|---|---|
public boolean intersects(BitSet other)
| |
| isEmpty | back to summary |
|---|---|
public boolean isEmpty()
| |
| iterator | back to summary |
|---|---|
public BitSetIterator iterator()
| |
| length | back to summary |
|---|---|
public long length()
| |
| newInstance | back to summary |
|---|---|
| public static BitSet newInstance() Static constructor-like method similar to other (generic) collections.
| |
| nextSetBit | back to summary |
|---|---|
public int nextSetBit(int index)
| |
| nextSetBit | back to summary |
|---|---|
public long nextSetBit(long index)
| |
| or | back to summary |
|---|---|
| public void or(BitSet other) | |
| remove | back to summary |
|---|---|
| public void remove(BitSet other) Remove all elements set in other: this = this AND_NOT other
| |
| set | back to summary |
|---|---|
| public void set(long index) Sets a bit, expanding the set size if necessary.
| |
| set | back to summary |
|---|---|
| public void set(long startIndex, long endIndex) Sets a range of bits, expanding the set size if necessary
| |
| size | back to summary |
|---|---|
public long 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- | |
| trimTrailingZeros | back to summary |
|---|---|
| public void trimTrailingZeros() Lowers | |
| union | back to summary |
|---|---|
| public void union(BitSet other) this = this OR other
| |
| unionCount | back to summary |
|---|---|
| public static long unionCount(BitSet a, BitSet b) | |
| xor | back to summary |
|---|---|
| public void xor(BitSet other) this = this XOR other
| |
| xorCount | back to summary |
|---|---|
| public static long xorCount(BitSet a, BitSet b) | |