class BitSetFX extends AbstractSet[Integer] with SortedSet[Integer] with Cloneable with Serializable
This class implements a vector of bits that grows as needed. Each component of the bit set has a boolean
value. The bits of a BitSet
are indexed by nonnegative integers. Individual indexed bits can be examined,
set, or cleared. One BitSet
may be used to modify the contents of another BitSet
through logical AND,
logical inclusive OR, and logical exclusive OR operations.
By default, all bits in the set initially have the value false
.
Every bit set has a current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set relates to logical length of a bit set and is defined independently of implementation.
Unless otherwise noted, passing a null parameter to any of the methods in a BitSet
will result in a
NullPointerException
.
A BitSet
is not safe for multithreaded use without external synchronization.
- Since
JDK1.0
- Alphabetic
- By Inheritance
- BitSetFX
- Serializable
- Cloneable
- SortedSet
- AbstractSet
- Set
- AbstractCollection
- Collection
- Iterable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new BitSetFX(c: Collection[_ <: Integer])
- new BitSetFX(b: BitSetFX)
-
new
BitSetFX(nbits: Int)
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range
0
throughnbits-1
.Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range
0
throughnbits-1
. All bits are initiallyfalse
.- nbits
the initial size of the bit set
- Exceptions thrown
NegativeArraySizeException
if the specified initial size is negative
- new BitSetFX()
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
add(e: Integer): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
def
addAll(c: Collection[_ <: Integer]): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
- def addRange(start: Int, end: Int): Unit
- def and(sets: Collection[BitSetFX]): Unit
- def and(sets: <repeated...>[BitSetFX]): Unit
-
def
and(set: BitSetFX): Unit
Performs a logical AND of this target bit set with the argument bit set.
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value
true
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument also had the valuetrue
.- set
a bit set
-
def
andNot(set: BitSetFX): Unit
Clears all of the bits in this
BitSet
whose corresponding bit is set in the specifiedBitSet
.Clears all of the bits in this
BitSet
whose corresponding bit is set in the specifiedBitSet
.- set
the
BitSet
with which to mask thisBitSet
- Since
1.2
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
cardinality(): Int
Returns the number of bits set to
true
in thisBitSet
.Returns the number of bits set to
true
in thisBitSet
.- returns
the number of bits set to
true
in thisBitSet
- Since
1.4
-
def
clear(): Unit
Sets all of the bits in this BitSet to
false
.Sets all of the bits in this BitSet to
false
.- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
- Since
1.4
-
def
clear(fromIndex: Int, toIndex: Int): Unit
Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) tofalse
.Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) tofalse
.- fromIndex
index of the first bit to be cleared
- toIndex
index after the last bit to be cleared
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
iffromIndex
is negative, ortoIndex
is negative, orfromIndex
is larger thantoIndex
-
def
clear(bitIndex: Int): Unit
Sets the bit specified by the index to
false
.Sets the bit specified by the index to
false
.- bitIndex
the index of the bit to be cleared
- Since
JDK1.0
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
def
clone(): AnyRef
Cloning this
BitSet
produces a newBitSet
that is equal to it.Cloning this
BitSet
produces a newBitSet
that is equal to it. The clone of the bit set is another bit set that has exactly the same bits set totrue
as this bit set.- returns
a clone of this bit set
- Definition Classes
- BitSetFX → AnyRef
- See also
#space()
-
def
comparator(): Comparator[_ >: Integer]
- Definition Classes
- BitSetFX → SortedSet
-
def
contains(o: Any): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
def
containsAll(c: Collection[_]): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(obj: Any): Boolean
Compares this object against the specified object.
Compares this object against the specified object. The result is
true
if and only if the argument is notnull
and is aBitset
object that has exactly the same set of bits set totrue
as this bit set. That is, for every nonnegativeint
indexk
,((BitSet) obj).get(k) == this.get(k)
must be true. The current sizes of the two bit sets are not compared.
- obj
the object to compare with
- returns
true
if the objects are the same;false
otherwise
- Definition Classes
- BitSetFX → AbstractSet → Set → Collection → AnyRef → Any
- See also
#space()
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
first(): Integer
- Definition Classes
- BitSetFX → SortedSet
-
def
flip(fromIndex: Int, toIndex: Int): Unit
Sets each bit from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) to the complement of its current value.Sets each bit from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) to the complement of its current value.- fromIndex
index of the first bit to flip
- toIndex
index after the last bit to flip
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
iffromIndex
is negative, ortoIndex
is negative, orfromIndex
is larger thantoIndex
-
def
flip(bitIndex: Int): Unit
Sets the bit at the specified index to the complement of its current value.
Sets the bit at the specified index to the complement of its current value.
- bitIndex
the index of the bit to flip
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
def
forEach(arg0: Consumer[_ >: Integer]): Unit
- Definition Classes
- Iterable
- def geq(set: BitSetFX): Boolean
-
def
get(fromIndex: Int, toIndex: Int): BitSetFX
Returns a new
BitSet
composed of bits from thisBitSet
fromfromIndex
(inclusive) totoIndex
(exclusive).Returns a new
BitSet
composed of bits from thisBitSet
fromfromIndex
(inclusive) totoIndex
(exclusive).- fromIndex
index of the first bit to include
- toIndex
index after the last bit to include
- returns
a new
BitSet
from a range of thisBitSet
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
iffromIndex
is negative, ortoIndex
is negative, orfromIndex
is larger thantoIndex
-
def
get(bitIndex: Int): Boolean
Returns the value of the bit with the specified index.
Returns the value of the bit with the specified index. The value is
true
if the bit with the indexbitIndex
is currently set in thisBitSet
; otherwise, the result isfalse
.- bitIndex
the bit index
- returns
the value of the bit with the specified index
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
Returns the hash code value for this bit set.
Returns the hash code value for this bit set. The hash code depends only on which bits are set within this
BitSet
.The hash code is defined to be the result of the following calculation:
public int hashCode() { long h = 1234; long[] words = toLongArray(); for (int i = words.length; --i >= 0; ) h ^= words[i] * (i + 1); return (int)((h >> 32) ^ h);
}Note that the hash code changes if the set of bits is altered.
- returns
the hash code value for this bit set
- Definition Classes
- BitSetFX → AbstractSet → Set → Collection → AnyRef → Any
-
def
headSet(toElement: Integer): SortedSet[Integer]
- Definition Classes
- BitSetFX → SortedSet
-
def
intersects(set: BitSetFX): Boolean
Returns true if the specified
BitSet
has any bits set totrue
that are also set totrue
in thisBitSet
.Returns true if the specified
BitSet
has any bits set totrue
that are also set totrue
in thisBitSet
.- set
BitSet
to intersect with- returns
boolean indicating whether this
BitSet
intersects the specifiedBitSet
- Since
1.4
-
def
isEmpty(): Boolean
Returns true if this
BitSet
contains no bits that are set totrue
.Returns true if this
BitSet
contains no bits that are set totrue
.- returns
boolean indicating whether this
BitSet
is empty
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
- Since
1.4
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator(): Iterator[Integer]
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection → Iterable
-
def
last(): Integer
- Definition Classes
- BitSetFX → SortedSet
-
def
length(): Int
Returns the "logical size" of this
BitSet
: the index of the highest set bit in theBitSet
plus one.Returns the "logical size" of this
BitSet
: the index of the highest set bit in theBitSet
plus one. Returns zero if theBitSet
contains no set bits.- returns
the logical size of this
BitSet
- Since
1.2
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nextClearBit(fromIndex: Int): Int
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index.Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index.- fromIndex
the index to start checking from (inclusive)
- returns
the index of the next clear bit
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
def
nextSetBit(fromIndex: Int): Int
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index.Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. If no such bit exists then-1
is returned.To iterate over the
true
bits in aBitSet
, use the following loop:for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { // operate on index i here if (i == Integer.MAX_VALUE) { break; // or (i+1) would overflow
}}- fromIndex
the index to start checking from (inclusive)
- returns
the index of the next set bit, or
-1
if there is no such bit
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
or(set: BitSetFX): Unit
Performs a logical OR of this bit set with the bit set argument.
Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
true
if and only if it either already had the valuetrue
or the corresponding bit in the bit set argument has the valuetrue
.- set
a bit set
-
def
parallelStream(): Stream[Integer]
- Definition Classes
- Collection
-
def
previousClearBit(fromIndex: Int): Int
Returns the index of the nearest bit that is set to
false
that occurs on or before the specified starting index.Returns the index of the nearest bit that is set to
false
that occurs on or before the specified starting index. If no such bit exists, or if-1
is given as the starting index, then-1
is returned.- fromIndex
the index to start checking from (inclusive)
- returns
the index of the previous clear bit, or
-1
if there is no such bit
- Since
1.7
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is less than-1
-
def
previousSetBit(fromIndex: Int): Int
Returns the index of the nearest bit that is set to
true
that occurs on or before the specified starting index.Returns the index of the nearest bit that is set to
true
that occurs on or before the specified starting index. If no such bit exists, or if-1
is given as the starting index, then-1
is returned.To iterate over the
true
bits in aBitSet
, use the following loop:for (int i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) { // operate on index i here
}- fromIndex
the index to start checking from (inclusive)
- returns
the index of the previous set bit, or
-1
if there is no such bit
- Since
1.7
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is less than-1
-
def
remove(o: Any): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
def
removeAll(c: Collection[_]): Boolean
- Definition Classes
- BitSetFX → AbstractSet → Set → AbstractCollection → Collection
-
def
removeIf(arg0: Predicate[_ >: Integer]): Boolean
- Definition Classes
- Collection
-
def
retainAll(c: Collection[_]): Boolean
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
def
set(fromIndex: Int, toIndex: Int, value: Boolean): Unit
Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) to the specified value.Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) to the specified value.- fromIndex
index of the first bit to be set
- toIndex
index after the last bit to be set
- value
value to set the selected bits to
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
iffromIndex
is negative, ortoIndex
is negative, orfromIndex
is larger thantoIndex
-
def
set(fromIndex: Int, toIndex: Int): Unit
Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) totrue
.Sets the bits from the specified
fromIndex
(inclusive) to the specifiedtoIndex
(exclusive) totrue
.- fromIndex
index of the first bit to be set
- toIndex
index after the last bit to be set
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
iffromIndex
is negative, ortoIndex
is negative, orfromIndex
is larger thantoIndex
-
def
set(bitIndex: Int, value: Boolean): Unit
Sets the bit at the specified index to the specified value.
Sets the bit at the specified index to the specified value.
- bitIndex
a bit index
- value
a boolean value to set
- Since
1.4
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
def
set(bitIndex: Int): Unit
Sets the bit at the specified index to
true
.Sets the bit at the specified index to
true
.- bitIndex
a bit index
- Since
JDK1.0
- Exceptions thrown
IndexOutOfBoundsException
if the specified index is negative
-
def
size(): Int
- Definition Classes
- BitSetFX → Set → AbstractCollection → Collection
-
def
space(): Int
Returns the number of bits of space actually in use by this
BitSet
to represent bit values.Returns the number of bits of space actually in use by this
BitSet
to represent bit values. The maximum element in the set is the size - 1st element.- returns
the number of bits currently in this bit set
-
def
spliterator(): Spliterator[Integer]
- Definition Classes
- SortedSet → Set → Collection → Iterable
-
def
stream(): Stream[Integer]
Returns a stream of indices for which this
BitSet
contains a bit in the set state.Returns a stream of indices for which this
BitSet
contains a bit in the set state. The indices are returned in order, from lowest to highest. The size of the stream is the number of bits in the set state, equal to the value returned by the#cardinality()
method.The bit set must remain constant during the execution of the terminal stream operation. Otherwise, the result of the terminal stream operation is undefined.
- returns
a stream of integers representing set indices
- Definition Classes
- BitSetFX → Collection
- Since
1.8
-
def
subSet(fromElement: Integer, toElement: Integer): SortedSet[Integer]
- Definition Classes
- BitSetFX → SortedSet
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tailSet(fromElement: Integer): SortedSet[Integer]
- Definition Classes
- BitSetFX → SortedSet
-
def
toArray[T](arg0: Array[T]): Array[T]
- Definition Classes
- AbstractCollection → Collection
-
def
toArray(): Array[AnyRef]
- Definition Classes
- AbstractCollection → Collection
-
def
toByteArray(): Array[Byte]
Returns a new byte array containing all the bits in this bit set.
Returns a new byte array containing all the bits in this bit set.
More precisely, if
byte[] bytes = s.toByteArray();
thenbytes.length == (s.length()+7)/8
and
s.get(n) == ((bytes[n/8] & (1<<(n%8))) != 0)
for alln < 8 * bytes.length
.- returns
a byte array containing a little-endian representation of all the bits in this bit set
- Since
1.7
-
def
toLongArray(): Array[Long]
Returns a new long array containing all the bits in this bit set.
Returns a new long array containing all the bits in this bit set.
More precisely, if
long[] longs = s.toLongArray();
thenlongs.length == (s.length()+63)/64
and
s.get(n) == ((longs[n/64] & (1L<<(n%64))) != 0)
for alln < 64 * longs.length
.- returns
a long array containing a little-endian representation of all the bits in this bit set
- Since
1.7
-
def
toString(): String
Returns a string representation of this bit set.
Returns a string representation of this bit set. For every index for which this
BitSet
contains a bit in the set state, the decimal representation of that index is included in the result. Such indices are listed in order from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.Example:
BitSet drPepper = new BitSet();
Now
drPepper.toString()
returns "{
}".drPepper.set(2);
Now
drPepper.toString()
returns "{2
}".drPepper.set(4); drPepper.set(10);
Now
drPepper.toString()
returns "{2, 4, 10
}".- returns
a string representation of this bit set
- Definition Classes
- BitSetFX → AbstractCollection → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
xor(set: BitSetFX): Unit
Performs a logical XOR of this bit set with the bit set argument.
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
true
if and only if one of the following statements holds:- The bit initially has the value
true
, and the corresponding bit in the argument has the valuefalse
. - The bit initially has the value
false
, and the corresponding bit in the argument has the valuetrue
.
- set
a bit set
- The bit initially has the value