Package org.apache.calcite.util
Class BitSets
java.lang.Object
org.apache.calcite.util.BitSets
Utility functions for
BitSet
.-
Method Summary
Modifier and TypeMethodDescriptionComputes the closure of a map from integers to bits.static boolean
Returns true if all bits set in the second parameter are also set in the first.static boolean
contains
(BitSet set0, ImmutableBitSet set1) Returns true if all bits set in the second parameter are also set in the first.static BitSet
of
(int... bits) Creates a bitset with given bits set.static BitSet
Creates a BitSet with given bits set.static BitSet
Creates a BitSet with given bits set.static BitSet
of
(ImmutableIntList bits) Creates a BitSet with given bits set.static void
Populates aBitSet
from an iterable, such as a list of integer.static void
populate
(BitSet bitSet, ImmutableIntList list) Populates aBitSet
from anImmutableIntList
.static int
previousClearBit
(BitSet bitSet, int fromIndex) Returns the previous clear bit.static BitSet
range
(int toIndex) Creates a BitSet with bits between 0 andtoIndex
set.static BitSet
range
(int fromIndex, int toIndex) Creates a bitset with bits fromfromIndex
(inclusive) to specifiedtoIndex
(exclusive) set totrue
.static void
Sets all bits in a given BitSet corresponding to integers from a list.static int[]
Converts a BitSet to an array.Returns an iterable over the bits in a bitmap that are set to '1'.toIter
(ImmutableBitSet bitSet) Converts a bitset to a list.static BitSet
Returns a BitSet that is the union of the given BitSets.
-
Method Details
-
contains
Returns true if all bits set in the second parameter are also set in the first. In other words, whether x is a super-set of y.- Parameters:
set0
- Containing bitmapset1
- Bitmap to be checked- Returns:
- Whether all bits in set1 are set in set0
-
contains
Returns true if all bits set in the second parameter are also set in the first. In other words, whether x is a super-set of y.- Parameters:
set0
- Containing bitmapset1
- Bitmap to be checked- Returns:
- Whether all bits in set1 are set in set0
-
toIter
Returns an iterable over the bits in a bitmap that are set to '1'.This allows you to iterate over a bit set using a 'foreach' construct. For instance:
BitSet bitSet;
for (int i : Util.toIter(bitSet)) {
print(i);
}- Parameters:
bitSet
- Bit set- Returns:
- Iterable
-
toIter
-
toList
Converts a bitset to a list.The list is mutable, and future changes to the list do not affect the contents of the bit set.
- Parameters:
bitSet
- Bit set- Returns:
- List of set bits
-
toArray
Converts a BitSet to an array.- Parameters:
bitSet
- Bit set- Returns:
- Array of set bits
-
of
Creates a bitset with given bits set.For example,
of(0, 3)
returns a bit set with bits {0, 3} set.- Parameters:
bits
- Array of bits to set- Returns:
- Bit set
-
of
Creates a BitSet with given bits set.For example,
of(new Integer[] {0, 3})
returns a bit set with bits {0, 3} set.- Parameters:
bits
- Array of bits to set- Returns:
- Bit set
-
of
Creates a BitSet with given bits set.For example,
of(Arrays.asList(0, 3))
returns a bit set with bits {0, 3} set.- Parameters:
bits
- Collection of bits to set- Returns:
- Bit set
-
of
Creates a BitSet with given bits set.For example,
of(ImmutableIntList.of(0, 3))
returns a bit set with bits {0, 3} set.- Parameters:
bits
- Collection of bits to set- Returns:
- Bit set
-
range
Creates a bitset with bits fromfromIndex
(inclusive) to specifiedtoIndex
(exclusive) set totrue
.For example,
range(0, 3)
returns a bit set with bits {0, 1, 2} set.- Parameters:
fromIndex
- Index of the first bit to be set.toIndex
- Index after the last bit to be set.- Returns:
- Bit set
-
range
Creates a BitSet with bits between 0 andtoIndex
set. -
setAll
Sets all bits in a given BitSet corresponding to integers from a list. -
union
Returns a BitSet that is the union of the given BitSets. Does not modify any of the inputs. -
previousClearBit
Returns the previous clear bit.Has same behavior as
BitSet.previousClearBit(int)
, but that method does not exist before 1.7. -
closure
Computes the closure of a map from integers to bits.The input must have an entry for each position.
Does not modify the input map or its bit sets.
-
populate
Populates aBitSet
from an iterable, such as a list of integer. -
populate
Populates aBitSet
from anImmutableIntList
.
-