Class Bits
java.lang.Object
com.android.dx.util.Bits
Utilities for treating
int[]s as bit sets.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleananyInRange(int[] bits, int start, int end) Returns whether any bits are set totruein the specified range.static intbitCount(int[] bits) Gets the number of bits set totruein the given bit set.static voidclear(int[] bits, int idx) Sets the given bit tofalse.static intfindFirst(int[] bits, int idx) Finds the lowest-order bit set at or after the given index in the given bit set.static intfindFirst(int value, int idx) Finds the lowest-order bit set at or after the given index in the givenint.static booleanget(int[] bits, int idx) Gets the value of the bit at the given index.static intgetMax(int[] bits) Gets the maximum index (exclusive) for the given bit set.static booleanisEmpty(int[] bits) Returns whether or not the given bit set is empty, that is, whether no bit is set totrue.static int[]makeBitSet(int max) Constructs a bit set to contain bits up to the given index (exclusive).static voidor(int[] a, int[] b) Ors bit arraybinto bit arraya.static voidset(int[] bits, int idx) Sets the given bit totrue.static voidset(int[] bits, int idx, boolean value) Sets the given bit to the given value.static StringtoHuman(int[] bits)
-
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 onidx->= 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 onidx->= 0, < getMax(set);which bitvalue- the new value for the bit
-
set
public static void set(int[] bits, int idx) Sets the given bit totrue.- Parameters:
bits-non-null;bit set to operate onidx->= 0, < getMax(set);which bit
-
clear
public static void clear(int[] bits, int idx) Sets the given bit tofalse.- Parameters:
bits-non-null;bit set to operate onidx->= 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 totrue.- Parameters:
bits-non-null;bit set to operate on- Returns:
trueiff all bits arefalse
-
bitCount
public static int bitCount(int[] bits) Gets the number of bits set totruein 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 totruein the specified range.- Parameters:
bits-non-null;bit set to operate onstart->= 0;index of the first bit in the range (inclusive)end->= 0;index of the last bit in the range (exclusive)- Returns:
trueif any bit is set totruein 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 onidx->= 0;minimum index to return- Returns:
>= -1;lowest-order bit set at or afteridx, or-1if 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 givenint.- Parameters:
value- the value in questionidx- 0..31 the minimum bit index to return- Returns:
>= -1;lowest-order bit set at or afteridx, or-1if there is no appropriate bit index to return
-
or
public static void or(int[] a, int[] b) Ors bit arraybinto bit arraya.a.lengthmust be greater than or equal tob.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 intoa. This argument is not modified.
-
toHuman
-