Class BitSets

java.lang.Object
org.apache.calcite.util.BitSets

public final class BitSets extends Object
Utility functions for BitSet.
  • Method Details

    • contains

      public static boolean contains(BitSet set0, BitSet set1)
      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 bitmap
      set1 - Bitmap to be checked
      Returns:
      Whether all bits in set1 are set in set0
    • contains

      public static boolean contains(BitSet set0, ImmutableBitSet set1)
      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 bitmap
      set1 - Bitmap to be checked
      Returns:
      Whether all bits in set1 are set in set0
    • toIter

      public static Iterable<Integer> toIter(BitSet bitSet)
      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

      public static Iterable<Integer> toIter(ImmutableBitSet bitSet)
    • toList

      public static List<Integer> toList(BitSet bitSet)
      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

      public static int[] toArray(BitSet bitSet)
      Converts a BitSet to an array.
      Parameters:
      bitSet - Bit set
      Returns:
      Array of set bits
    • of

      public static BitSet of(int... bits)
      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

      public static BitSet of(Integer[] bits)
      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

      public static BitSet of(Iterable<? extends Number> bits)
      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

      public static BitSet of(ImmutableIntList bits)
      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

      public static BitSet range(int fromIndex, int toIndex)
      Creates a bitset with bits from fromIndex (inclusive) to specified toIndex (exclusive) set to true.

      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

      public static BitSet range(int toIndex)
      Creates a BitSet with bits between 0 and toIndex set.
    • setAll

      public static void setAll(BitSet bitSet, Iterable<? extends Number> list)
      Sets all bits in a given BitSet corresponding to integers from a list.
    • union

      public static BitSet union(BitSet set0, BitSet... sets)
      Returns a BitSet that is the union of the given BitSets. Does not modify any of the inputs.
    • previousClearBit

      public static int previousClearBit(BitSet bitSet, int fromIndex)
      Returns the previous clear bit.

      Has same behavior as BitSet.previousClearBit(int), but that method does not exist before 1.7.

    • closure

      public static SortedMap<Integer,BitSet> closure(SortedMap<Integer,BitSet> equivalence)
      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

      public static void populate(BitSet bitSet, Iterable<? extends Number> list)
      Populates a BitSet from an iterable, such as a list of integer.
    • populate

      public static void populate(BitSet bitSet, ImmutableIntList list)
      Populates a BitSet from an ImmutableIntList.