Package com.android.dx.util
Class Bits
java.lang.Object
com.android.dx.util.Bits
Utilities for treating
int[]
s as bit sets.-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
anyInRange
(int[] bits, int start, int end) Returns whether any bits are set totrue
in the specified range.static int
bitCount
(int[] bits) Gets the number of bits set totrue
in the given bit set.static void
clear
(int[] bits, int idx) Sets the given bit tofalse
.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 givenint
.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 totrue
.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 arrayb
into bit arraya
.static void
set
(int[] bits, int idx) Sets the given bit totrue
.static void
set
(int[] bits, int idx, boolean value) Sets the given bit to the given value.static String
toHuman
(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:
true
iff all bits arefalse
-
bitCount
public static int bitCount(int[] bits) Gets the number of bits set totrue
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 totrue
in 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:
true
if any bit is set totrue
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 onidx
->= 0;
minimum index to return- Returns:
>= -1;
lowest-order bit set at or afteridx
, 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 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-1
if there is no appropriate bit index to return
-
or
public static void or(int[] a, int[] b) Ors bit arrayb
into bit arraya
.a.length
must 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
-