public final class Bits
extends java.lang.Object
int[]s as bit sets.| Modifier and Type | Method and 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 java.lang.String |
toHuman(int[] bits) |
public static int[] makeBitSet(int max)
max - >= 0; the maximum bit index (exclusive)non-null; an appropriately-constructed instancepublic static int getMax(int[] bits)
bits - non-null; bit set in question>= 0; the maximum index (exclusive) that may be setpublic static boolean get(int[] bits,
int idx)
bits - non-null; bit set to operate onidx - >= 0, < getMax(set); which bitpublic static void set(int[] bits,
int idx,
boolean value)
bits - non-null; bit set to operate onidx - >= 0, < getMax(set); which bitvalue - the new value for the bitpublic static void set(int[] bits,
int idx)
true.bits - non-null; bit set to operate onidx - >= 0, < getMax(set); which bitpublic static void clear(int[] bits,
int idx)
false.bits - non-null; bit set to operate onidx - >= 0, < getMax(set); which bitpublic static boolean isEmpty(int[] bits)
true.bits - non-null; bit set to operate ontrue iff all bits are falsepublic static int bitCount(int[] bits)
true in the given bit set.bits - non-null; bit set to operate on>= 0; the bit count (aka population count) of the setpublic static boolean anyInRange(int[] bits,
int start,
int end)
true in the
specified range.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)true if any bit is set to true in
the indicated rangepublic static int findFirst(int[] bits,
int idx)
bits - non-null; bit set to operate onidx - >= 0; minimum index to return>= -1; lowest-order bit set at or after idx,
or -1 if there is no appropriate bit index to returnpublic static int findFirst(int value,
int idx)
int.value - the value in questionidx - 0..31 the minimum bit index to return>= -1; lowest-order bit set at or after idx,
or -1 if there is no appropriate bit index to returnpublic static void or(int[] a,
int[] b)
b into bit array a.
a.length must be greater than or equal to
b.length.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.public static java.lang.String toHuman(int[] bits)
Copyright © 2020. All Rights Reserved.