1 *java.util.BitSet* *BitSet* This class implements a vector of bits that grows as
4 extends |java.lang.Object|
5 implements |java.lang.Cloneable|
8 |java.util.BitSet_Description|
9 |java.util.BitSet_Fields|
10 |java.util.BitSet_Constructors|
11 |java.util.BitSet_Methods|
13 ================================================================================
15 *java.util.BitSet_Constructors*
16 |java.util.BitSet()|Creates a new bit set.
17 |java.util.BitSet(int)|Creates a bit set whose initial size is large enough to
19 *java.util.BitSet_Methods*
20 |java.util.BitSet.and(BitSet)|Performs a logical AND of this target bit set wit
21 |java.util.BitSet.andNot(BitSet)|Clears all of the bits in this BitSet whose co
22 |java.util.BitSet.cardinality()|Returns the number of bits set to true in this
23 |java.util.BitSet.clear()|Sets all of the bits in this BitSet to false.
24 |java.util.BitSet.clear(int)|Sets the bit specified by the index to false.
25 |java.util.BitSet.clear(int,int)|Sets the bits from the specified fromIndex(inc
26 |java.util.BitSet.clone()|Cloning this BitSet produces a new BitSet that is e
27 |java.util.BitSet.equals(Object)|Compares this object against the specified obj
28 |java.util.BitSet.flip(int)|Sets the bit at the specified index to the compleme
29 |java.util.BitSet.flip(int,int)|Sets each bit from the specified fromIndex(incl
30 |java.util.BitSet.get(int)|Returns the value of the bit with the specified inde
31 |java.util.BitSet.get(int,int)|Returns a new BitSet composed of bits from this
32 |java.util.BitSet.hashCode()|Returns a hash code value for this bit set.
33 |java.util.BitSet.intersects(BitSet)|Returns true if the specified BitSet has a
34 |java.util.BitSet.isEmpty()|Returns true if this BitSet contains no bits that a
35 |java.util.BitSet.length()|Returns the "logical size" of this BitSet: the index
36 |java.util.BitSet.nextClearBit(int)|Returns the index of the first bit that is
37 |java.util.BitSet.nextSetBit(int)|Returns the index of the first bit that is se
38 |java.util.BitSet.or(BitSet)|Performs a logical OR of this bit set with the bit
39 |java.util.BitSet.set(int)|Sets the bit at the specified index to true.
40 |java.util.BitSet.set(int,boolean)|Sets the bit at the specified index to the s
41 |java.util.BitSet.set(int,int)|Sets the bits from the specified fromIndex(inclu
42 |java.util.BitSet.set(int,int,boolean)|Sets the bits from the specified fromInd
43 |java.util.BitSet.size()|Returns the number of bits of space actually in use by
44 |java.util.BitSet.toString()|Returns a string representation of this bit set.
45 |java.util.BitSet.xor(BitSet)|Performs a logical XOR of this bit set with the b
47 *java.util.BitSet_Description*
49 This class implements a vector of bits that grows as needed. Each component of
50 the bit set has a boolean value. The bits of a BitSet are indexed by
51 nonnegative integers. Individual indexed bits can be examined, set, or cleared.
52 One BitSet may be used to modify the contents of another BitSet through logical
53 AND, logical inclusive OR, and logical exclusive OR operations.
55 By default, all bits in the set initially have the value false.
57 Every bit set has a current size, which is the number of bits of space
58 currently in use by the bit set. Note that the size is related to the
59 implementation of a bit set, so it may change with implementation. The length
60 of a bit set relates to logical length of a bit set and is defined
61 independently of implementation.
63 Unless otherwise noted, passing a null parameter to any of the methods in a
64 BitSet will result in a NullPointerException.
66 A BitSet is not safe for multithreaded use without external synchronization.
73 Creates a new bit set. All bits are initially false.
76 *java.util.BitSet(int)*
78 public BitSet(int nbits)
80 Creates a bit set whose initial size is large enough to explicitly represent
81 bits with indices in the range 0 through nbits-1. All bits are initially false.
83 nbits - the initial size of the bit set.
85 *java.util.BitSet.and(BitSet)*
87 public void and(java.util.BitSet set)
89 Performs a logical AND of this target bit set with the argument bit set. This
90 bit set is modified so that each bit in it has the value true if and only if it
91 both initially had the value true and the corresponding bit in the bit set
92 argument also had the value true.
96 *java.util.BitSet.andNot(BitSet)*
98 public void andNot(java.util.BitSet set)
100 Clears all of the bits in this BitSet whose corresponding bit is set in the
103 set - the BitSet with which to mask this BitSet.
105 *java.util.BitSet.cardinality()*
107 public int cardinality()
109 Returns the number of bits set to true in this BitSet.
112 Returns: the number of bits set to true in this BitSet.
113 *java.util.BitSet.clear()*
117 Sets all of the bits in this BitSet to false.
120 *java.util.BitSet.clear(int)*
122 public void clear(int bitIndex)
124 Sets the bit specified by the index to false.
126 bitIndex - the index of the bit to be cleared.
128 *java.util.BitSet.clear(int,int)*
134 Sets the bits from the specified fromIndex(inclusive) to the specified
135 toIndex(exclusive) to false.
137 fromIndex - index of the first bit to be cleared.
138 toIndex - index after the last bit to be cleared.
140 *java.util.BitSet.clone()*
142 public |java.lang.Object| clone()
144 Cloning this BitSet produces a new BitSet that is equal to it. The clone of the
145 bit set is another bit set that has exactly the same bits set to true as this
146 bit set and the same current size. Overrides the clone method of Object.
149 Returns: a clone of this bit set.
150 *java.util.BitSet.equals(Object)*
152 public boolean equals(java.lang.Object obj)
154 Compares this object against the specified object. The result is true if and
155 only if the argument is not null and is a Bitset object that has exactly the
156 same set of bits set to true as this bit set. That is, for every nonnegative
159 ((BitSet)obj).get(k) == this.get(k)
161 must be true. The current sizes of the two bit sets are not compared. Overrides
162 the equals method of Object.
164 obj - the object to compare with.
166 Returns: true if the objects are the same; false otherwise.
167 *java.util.BitSet.flip(int)*
169 public void flip(int bitIndex)
171 Sets the bit at the specified index to the complement of its current value.
173 bitIndex - the index of the bit to flip.
175 *java.util.BitSet.flip(int,int)*
181 Sets each bit from the specified fromIndex(inclusive) to the specified
182 toIndex(exclusive) to the complement of its current value.
184 fromIndex - index of the first bit to flip.
185 toIndex - index after the last bit to flip.
187 *java.util.BitSet.get(int)*
189 public boolean get(int bitIndex)
191 Returns the value of the bit with the specified index. The value is true if the
192 bit with the index bitIndex is currently set in this BitSet; otherwise, the
195 bitIndex - the bit index.
197 Returns: the value of the bit with the specified index.
198 *java.util.BitSet.get(int,int)*
200 public |java.util.BitSet| get(
204 Returns a new BitSet composed of bits from this BitSet from
205 fromIndex(inclusive) to toIndex(exclusive).
207 fromIndex - index of the first bit to include.
208 toIndex - index after the last bit to include.
210 Returns: a new BitSet from a range of this BitSet.
211 *java.util.BitSet.hashCode()*
213 public int hashCode()
215 Returns a hash code value for this bit set. The has code depends only on which
216 bits have been set within this BitSet. The algorithm used to compute it may be
217 described as follows. Suppose the bits in the BitSet were to be stored in an
218 array of long integers called, say, bits, in such a manner that bit k is set in
219 the BitSet (for nonnegative values of k) if and only if the expression
221 ((k>>6) < bits.length) ((bits[k>>6] & (1L << (bit & 0x3F))) != 0)
223 is true. Then the following definition of the hashCode method would be a
224 correct implementation of the actual algorithm:
226 public int hashCode() { long h = 1234; for (int i = bits.length; --i >= 0; ) {
227 h ^= bits[i] * (i + 1); } return (int)((h >> 32) ^ h); }
229 Note that the hash code values change if the set of bits is altered. Overrides
230 the hashCode method of Object.
233 Returns: a hash code value for this bit set.
234 *java.util.BitSet.intersects(BitSet)*
236 public boolean intersects(java.util.BitSet set)
238 Returns true if the specified BitSet has any bits set to true that are also set
239 to true in this BitSet.
241 set - BitSet to intersect with
243 Returns: boolean indicating whether this BitSet intersects the specified BitSet.
244 *java.util.BitSet.isEmpty()*
246 public boolean isEmpty()
248 Returns true if this BitSet contains no bits that are set to true.
251 Returns: boolean indicating whether this BitSet is empty.
252 *java.util.BitSet.length()*
256 Returns the "logical size" of this BitSet: the index of the highest set bit in
257 the BitSet plus one. Returns zero if the BitSet contains no set bits.
260 Returns: the logical size of this BitSet.
261 *java.util.BitSet.nextClearBit(int)*
263 public int nextClearBit(int fromIndex)
265 Returns the index of the first bit that is set to false that occurs on or after
266 the specified starting index.
268 fromIndex - the index to start checking from (inclusive).
270 Returns: the index of the next clear bit.
271 *java.util.BitSet.nextSetBit(int)*
273 public int nextSetBit(int fromIndex)
275 Returns the index of the first bit that is set to true that occurs on or after
276 the specified starting index. If no such bit exists then -1 is returned.
278 To iterate over the true bits in a BitSet, use the following loop:
280 for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { // operate on index i
283 fromIndex - the index to start checking from (inclusive).
285 Returns: the index of the next set bit.
286 *java.util.BitSet.or(BitSet)*
288 public void or(java.util.BitSet set)
290 Performs a logical OR of this bit set with the bit set argument. This bit set
291 is modified so that a bit in it has the value true if and only if it either
292 already had the value true or the corresponding bit in the bit set argument has
297 *java.util.BitSet.set(int)*
299 public void set(int bitIndex)
301 Sets the bit at the specified index to true.
303 bitIndex - a bit index.
305 *java.util.BitSet.set(int,boolean)*
311 Sets the bit at the specified index to the specified value.
313 bitIndex - a bit index.
314 value - a boolean value to set.
316 *java.util.BitSet.set(int,int)*
322 Sets the bits from the specified fromIndex(inclusive) to the specified
323 toIndex(exclusive) to true.
325 fromIndex - index of the first bit to be set.
326 toIndex - index after the last bit to be set.
328 *java.util.BitSet.set(int,int,boolean)*
335 Sets the bits from the specified fromIndex(inclusive) to the specified
336 toIndex(exclusive) to the specified value.
338 fromIndex - index of the first bit to be set.
339 toIndex - index after the last bit to be set
340 value - value to set the selected bits to
342 *java.util.BitSet.size()*
346 Returns the number of bits of space actually in use by this BitSet to represent
347 bit values. The maximum element in the set is the size - 1st element.
350 Returns: the number of bits currently in this bit set.
351 *java.util.BitSet.toString()*
353 public |java.lang.String| toString()
355 Returns a string representation of this bit set. For every index for which this
356 BitSet contains a bit in the set state, the decimal representation of that
357 index is included in the result. Such indices are listed in order from lowest
358 to highest, separated by "," (a comma and a space) and surrounded by braces,
359 resulting in the usual mathematical notation for a set of integers. Overrides
360 the toString method of Object. Example:
362 BitSet drPepper = new BitSet();
364 Now drPepper.toString() returns "{}".
368 Now drPepper.toString() returns "{2}".
370 drPepper.set(4); drPepper.set(10);
372 Now drPepper.toString() returns "{2, 4, 10}".
375 Returns: a string representation of this bit set.
376 *java.util.BitSet.xor(BitSet)*
378 public void xor(java.util.BitSet set)
380 Performs a logical XOR of this bit set with the bit set argument. This bit set
381 is modified so that a bit in it has the value true if and only if one of the
382 following statements holds:
384 The bit initially has the value true, and the corresponding bit in the argument
385 has the value false. The bit initially has the value false, and the
386 corresponding bit in the argument has the value true.