Package com.oracle.truffle.api.utilities
Class FinalBitSet
java.lang.Object
com.oracle.truffle.api.utilities.FinalBitSet
Readonly bitset designed for partial evaluation. The implementation is partially reused from
BitSet
. Since:
 20.0
 See Also:

Field Summary

Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of bits set totrue
in thisBitSet
.boolean
Compares this object against the specified object.boolean
get
(int bitIndex) Returns the value of the bit with the specified index.int
hashCode()
Returns the hash code value for this bit set.boolean
isEmpty()
Returns true if thisFinalBitSet
contains no bits that are set totrue
.int
length()
Returns the "logical size" of thisFinalBitSet
: the index of the highest set bit in theFinalBitSet
plus one.int
nextClearBit
(int fromIndex) Returns the index of the first bit that is set tofalse
that occurs on or after the specified starting index.int
nextSetBit
(int fromIndex) Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index.int
size()
Returns the number of bits of space actually in use by thisFinalBitSet
to represent bit values.long[]
Returns a new long array containing all the bits in this bit set.toString()
Returns a string representation of this bit set.static FinalBitSet
valueOf
(long[] longs) Returns a new bit set containing all the bits in the given long array.static FinalBitSet
Returns a new final bit set from a JavaBitSet
instance.

Field Details

EMPTY
An empty bit set of size 0. Since:
 20.0


Method Details

toLongArray
public long[] toLongArray()Returns a new long array containing all the bits in this bit set. This method is designed for partial evaluation.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 littleendian representation of all the bits in this bit set
 Since:
 20.0

get
public boolean get(int bitIndex) Returns the value of the bit with the specified index. The value istrue
if the bit with the indexbitIndex
is currently set in thisFinalBitSet
; otherwise, the result isfalse
. This method is designed for partial evaluation and is guaranteed to fold if the receiver and the bitIndex parameter are constant. Parameters:
bitIndex
 the bit index Returns:
 the value of the bit with the specified index
 Throws:
IndexOutOfBoundsException
 if the specified index is negative Since:
 20.0

length
public int length()Returns the "logical size" of thisFinalBitSet
: the index of the highest set bit in theFinalBitSet
plus one. Returns zero if theFinalBitSet
contains no set bits. This method is designed for partial evaluation and is guaranteed to fold if the receiver is constant. Returns:
 the logical size of this
FinalBitSet
 Since:
 20.0

isEmpty
public boolean isEmpty()Returns true if thisFinalBitSet
contains no bits that are set totrue
. This method is designed for partial evaluation and is guaranteed to fold if the receiver is constant. Returns:
 boolean indicating whether this
FinalBitSet
is empty  Since:
 20.0

equals
Compares this object against the specified object. The result istrue
if and only if the argument is notnull
and is aFinalBitSet
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. 
hashCode
public int hashCode()Returns the hash code value for this bit set. The hash code depends only on which bits are set within thisFinalBitSet
.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); }

size
public int size()Returns the number of bits of space actually in use by thisFinalBitSet
to represent bit values. The maximum element in the set is the size  1st element. This method is designed for partial evaluation and is guaranteed to fold if the receiver is constant. Returns:
 the number of bits currently in this bit set
 Since:
 20.0

cardinality
public int cardinality()Returns the number of bits set totrue
in thisBitSet
. Returns:
 the number of bits set to
true
in thisBitSet
 Since:
 20.0

nextSetBit
public int nextSetBit(int fromIndex) Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index. If no such bit exists then1
is returned.To iterate over the
true
bits in aFinalBitSet
, 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 } }
 Parameters:
fromIndex
 the index to start checking from (inclusive) Returns:
 the index of the next set bit, or
1
if there is no such bit  Throws:
IndexOutOfBoundsException
 if the specified index is negative Since:
 20.0

nextClearBit
public int nextClearBit(int fromIndex) Returns the index of the first bit that is set tofalse
that occurs on or after the specified starting index. Parameters:
fromIndex
 the index to start checking from (inclusive) Returns:
 the index of the next clear bit
 Throws:
IndexOutOfBoundsException
 if the specified index is negative Since:
 20.0

toString
Returns a string representation of this bit set. For every index for which thisBitSet
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. 
valueOf
Returns a new bit set containing all the bits in the given long array.More precisely,
FinalBitSet.valueOf(longs).get(n) == ((longs[n/64] & (1L<<(n%64))) != 0)
for alln < 64 * longs.length
. Parameters:
longs
 a long array containing a littleendian representation of a sequence of bits to be used as the initial bits of the new bit set Returns:
 a
FinalBitSet
containing all the bits in the long array  Since:
 20.0

valueOf
Returns a new final bit set from a JavaBitSet
instance. The original bit set will be copied. Since:
 20.0
