Class Bits

java.lang.Object
com.android.dx.util.Bits

public final class Bits extends Object
Utilities for treating int[]s as bit sets.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    anyInRange(int[] bits, int start, int end)
    Returns whether any bits are set to true in the specified range.
    static int
    bitCount(int[] bits)
    Gets the number of bits set to true in the given bit set.
    static void
    clear(int[] bits, int idx)
    Sets the given bit to false.
    static int
    findFirst(int[] bits, int idx)
    Finds the lowest-order bit set at or after the given index in the given bit set.
    static int
    findFirst(int value, int idx)
    Finds the lowest-order bit set at or after the given index in the given int.
    static boolean
    get(int[] bits, int idx)
    Gets the value of the bit at the given index.
    static int
    getMax(int[] bits)
    Gets the maximum index (exclusive) for the given bit set.
    static boolean
    isEmpty(int[] bits)
    Returns whether or not the given bit set is empty, that is, whether no bit is set to true.
    static int[]
    makeBitSet(int max)
    Constructs a bit set to contain bits up to the given index (exclusive).
    static void
    or(int[] a, int[] b)
    Ors bit array b into bit array a.
    static void
    set(int[] bits, int idx)
    Sets the given bit to true.
    static void
    set(int[] bits, int idx, boolean value)
    Sets the given bit to the given value.
    static String
    toHuman(int[] bits)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • makeBitSet

      public static int[] makeBitSet(int max)
      Constructs a bit set to contain bits up to the given index (exclusive).
      Parameters:
      max - >= 0; the maximum bit index (exclusive)
      Returns:
      non-null; an appropriately-constructed instance
    • getMax

      public static int getMax(int[] bits)
      Gets the maximum index (exclusive) for the given bit set.
      Parameters:
      bits - non-null; bit set in question
      Returns:
      >= 0; the maximum index (exclusive) that may be set
    • get

      public static boolean get(int[] bits, int idx)
      Gets the value of the bit at the given index.
      Parameters:
      bits - non-null; bit set to operate on
      idx - >= 0, < getMax(set); which bit
      Returns:
      the value of the indicated bit
    • set

      public static void set(int[] bits, int idx, boolean value)
      Sets the given bit to the given value.
      Parameters:
      bits - non-null; bit set to operate on
      idx - >= 0, < getMax(set); which bit
      value - the new value for the bit
    • set

      public static void set(int[] bits, int idx)
      Sets the given bit to true.
      Parameters:
      bits - non-null; bit set to operate on
      idx - >= 0, < getMax(set); which bit
    • clear

      public static void clear(int[] bits, int idx)
      Sets the given bit to false.
      Parameters:
      bits - non-null; bit set to operate on
      idx - >= 0, < getMax(set); which bit
    • isEmpty

      public static boolean isEmpty(int[] bits)
      Returns whether or not the given bit set is empty, that is, whether no bit is set to true.
      Parameters:
      bits - non-null; bit set to operate on
      Returns:
      true iff all bits are false
    • bitCount

      public static int bitCount(int[] bits)
      Gets the number of bits set to true in the given bit set.
      Parameters:
      bits - non-null; bit set to operate on
      Returns:
      >= 0; the bit count (aka population count) of the set
    • anyInRange

      public static boolean anyInRange(int[] bits, int start, int end)
      Returns whether any bits are set to true in the specified range.
      Parameters:
      bits - non-null; bit set to operate on
      start - >= 0; index of the first bit in the range (inclusive)
      end - >= 0; index of the last bit in the range (exclusive)
      Returns:
      true if any bit is set to true in the indicated range
    • findFirst

      public static int findFirst(int[] bits, int idx)
      Finds the lowest-order bit set at or after the given index in the given bit set.
      Parameters:
      bits - non-null; bit set to operate on
      idx - >= 0; minimum index to return
      Returns:
      >= -1; lowest-order bit set at or after idx, or -1 if there is no appropriate bit index to return
    • findFirst

      public static int findFirst(int value, int idx)
      Finds the lowest-order bit set at or after the given index in the given int.
      Parameters:
      value - the value in question
      idx - 0..31 the minimum bit index to return
      Returns:
      >= -1; lowest-order bit set at or after idx, or -1 if there is no appropriate bit index to return
    • or

      public static void or(int[] a, int[] b)
      Ors bit array b into bit array a. a.length must be greater than or equal to b.length.
      Parameters:
      a - non-null; int array to be ored with other argument. This argument is modified.
      b - non-null; int array to be ored into a. This argument is not modified.
    • toHuman

      public static String toHuman(int[] bits)