
public final class BitsUtil extends Object
C return a copy, methods with
 I modify in-place.| Modifier and Type | Field and Description | 
|---|---|
private static long | 
LONG_ALL_BITS
Long with all bits set 
 | 
private static int | 
LONG_LOG2_MASK
Masking for long shifts. 
 | 
private static int | 
LONG_LOG2_SIZE
Shift factor for a long: 2^6 == 64 == Long.SIZE 
 | 
| Constructor and Description | 
|---|
BitsUtil()  | 
| Modifier and Type | Method and Description | 
|---|---|
static long[] | 
andI(long[] v,
    long[] o)
AND o onto v inplace, i.e. v &= o 
 | 
static long[] | 
andI(long[] v,
    long[] o,
    int off)
AND o onto v inplace, i.e. v &= (o << off) 
 | 
static int | 
capacity(long[] v)
Capacity of the vector v. 
 | 
static int | 
cardinality(long v)
Compute the cardinality (number of set bits) 
 | 
static long | 
cardinality(long[] v)
Compute the cardinality (number of set bits)
 
 Low-endian layout for the array. 
 | 
static long | 
clearC(long v,
      int off)
Clear bit number "off" in v. 
 | 
static long[] | 
clearI(long[] v,
      int off)
Clear bit number "off" in v. 
 | 
static int | 
compare(long[] x,
       long[] y)
Compare two bitsets. 
 | 
static long[] | 
copy(long[] v)
Copy a bitset 
 | 
static long[] | 
copy(long[] v,
    int mincap)
Copy a bitset. 
 | 
static long[] | 
copy(long[] v,
    int mincap,
    int shift)
Copy a bitset. 
 | 
static long | 
cycleLeftC(long v,
          int shift,
          int len)
Rotate a long to the left, cyclic with length len 
 | 
static long[] | 
cycleLeftI(long[] v,
          int shift,
          int len)
Cycle a bitstring to the right. 
 | 
static long | 
cycleRightC(long v,
           int shift,
           int len)
Rotate a long to the right, cyclic with length len 
 | 
static long[] | 
cycleRightI(long[] v,
           int shift,
           int len)
Cycle a bitstring to the right. 
 | 
static long | 
flipC(long v,
     int off)
Invert bit number "off" in v. 
 | 
static long[] | 
flipI(long[] v,
     int off)
Invert bit number "off" in v. 
 | 
static boolean | 
get(long[] v,
   int off)
Set bit number "off" in v. 
 | 
static boolean | 
get(long v,
   int off)
Set bit number "off" in v. 
 | 
static long | 
grayC(long v)
Compute corresponding gray code as v XOR (v >>> 1) 
 | 
static long[] | 
grayI(long[] v)
Compute corresponding gray code as v XOR (v >>> 1) 
 | 
static long[] | 
invertI(long[] v)
Invert v inplace. 
 | 
static long | 
invgrayC(long v)
Compute the inverted gray code, v XOR (v >>> 1) XOR (v >>> 2) ... 
 | 
static long[] | 
invgrayI(long[] v)
Compute the inverted gray code, v XOR (v >>> 1) XOR (v >>> 2) ... 
 | 
static boolean | 
isZero(long[] v)
Test for the bitstring to be all-zero. 
 | 
static int | 
magnitude(int v)
The magnitude is the position of the highest bit set 
 | 
static int | 
magnitude(long v)
The magnitude is the position of the highest bit set 
 | 
static int | 
magnitude(long[] v)
The magnitude is the position of the highest bit set 
 | 
static long[] | 
make(int bits,
    long init)
Allocate a new long[]. 
 | 
static int | 
nextClearBit(long[] v,
            int start)
Find the next clear bit. 
 | 
static int | 
nextSetBit(long[] v,
          int start)
Find the next set bit. 
 | 
static int | 
numberOfLeadingZeros(int v)
Find the number of leading zeros; 32 if all zero
 
 Note: this the same as  
Integer.numberOfLeadingZeros(int). | 
static int | 
numberOfLeadingZeros(long v)
Find the number of leading zeros; 64 if all zero
 
 Note: this the same as  
Long.numberOfLeadingZeros(long). | 
static int | 
numberOfLeadingZeros(long[] v)
Find the number of leading zeros. 
 | 
static int | 
numberOfLeadingZerosSigned(int v)
Find the number of leading zeros; -1 if all zero
 
 Note: this has different semantics to  
Long.numberOfLeadingZeros(long)
 when the number is 0. | 
static int | 
numberOfLeadingZerosSigned(long v)
Find the number of leading zeros; -1 if all zero
 
 Note: this has different semantics to  
Long.numberOfLeadingZeros(long)
 when the number is 0. | 
static int | 
numberOfLeadingZerosSigned(long[] v)
Find the number of leading zeros. 
 | 
static int | 
numberOfTrailingZeros(int v)
Find the number of trailing zeros. 
 | 
static int | 
numberOfTrailingZeros(long v)
Find the number of trailing zeros. 
 | 
static int | 
numberOfTrailingZeros(long[] v)
Find the number of trailing zeros. 
 | 
static int | 
numberOfTrailingZerosSigned(long v)
Find the number of trailing zeros. 
 | 
static int | 
numberOfTrailingZerosSigned(long[] v)
Find the number of trailing zeros. 
 | 
static long[] | 
ones(int bits)
Create a vector initialized with "bits" ones. 
 | 
static long[] | 
orI(long[] v,
   long[] o)
OR o onto v inplace, i.e. v |= o 
 | 
static long[] | 
orI(long[] v,
   long[] o,
   int off)
OR o onto v inplace, i.e. v |= (o << off)
 
 Note: Bits that are shifted outside of the size of v are discarded. 
 | 
static int | 
previousClearBit(long[] v,
                int start)
Find the previous clear bit. 
 | 
static int | 
previousSetBit(long[] v,
              int start)
Find the previous set bit. 
 | 
static long | 
setC(long v,
    int off)
Set bit number "off" in v. 
 | 
static long[] | 
setI(long[] v,
    int off)
Set bit number "off" in v. 
 | 
static long[] | 
shiftLeftI(long[] v,
          int off)
Shift a long[] bitset inplace. 
 | 
static long[] | 
shiftRightI(long[] v,
           int off)
Shift a long[] bitset inplace. 
 | 
static String | 
toString(long v)
Convert bitset to a string consisting of "0" and "1", in high-endian order. 
 | 
static String | 
toString(long[] v)
Convert bitset to a string consisting of "0" and "1", in high-endian order. 
 | 
static String | 
toString(long[] v,
        int minw)
Convert bitset to a string consisting of "0" and "1", in high-endian order. 
 | 
static long[] | 
truncateI(long[] v,
         int len)
Truncate a bit string to the given length (setting any higher bit to 0). 
 | 
static long[] | 
xorI(long[] v,
    long[] o)
XOR o onto v inplace, i.e. v ^= o 
 | 
static long[] | 
xorI(long[] v,
    long[] o,
    int off)
XOR o onto v inplace, i.e. v ^= (o << off) 
 | 
static long[] | 
zero(int bits)
Allocate a new long[]. 
 | 
static long[] | 
zeroI(long[] v)
Zero the given set
 
 Low-endian layout for the array. 
 | 
private static final int LONG_LOG2_SIZE
private static final int LONG_LOG2_MASK
private static final long LONG_ALL_BITS
public static long[] zero(int bits)
bits - Number of bits in storagepublic static long[] make(int bits,
          long init)
bits - Number of bits in storageinit - Initial value (of at most the size of a long, remaining bits
        will be 0)public static long[] ones(int bits)
bits - Sizepublic static long[] copy(long[] v)
v - Array to copypublic static long[] copy(long[] v,
          int mincap)
v - Array to copymincap - Target minimum capacitypublic static long[] copy(long[] v,
          int mincap,
          int shift)
v - Array to copymincap - Target minimum capacityshift - Number of bits to shift leftpublic static long grayC(long v)
v - Valuepublic static long[] grayI(long[] v)
v - Valuepublic static long invgrayC(long v)
v - Valuepublic static long[] invgrayI(long[] v)
v - Valuepublic static boolean isZero(long[] v)
v - Bitstringpublic static int cardinality(long v)
v - Valuepublic static long cardinality(long[] v)
v - Valuepublic static long flipC(long v,
         int off)
v - Bufferoff - Offset to flippublic static long[] flipI(long[] v,
           int off)
v - Bufferoff - Offset to flippublic static long setC(long v,
        int off)
v - Bufferoff - Offset to setpublic static long[] setI(long[] v,
          int off)
v - Bufferoff - Offset to setpublic static long clearC(long v,
          int off)
v - Bufferoff - Offset to clearpublic static long[] clearI(long[] v,
            int off)
v - Bufferoff - Offset to clearpublic static boolean get(long v,
          int off)
v - Bufferoff - Offset to setpublic static boolean get(long[] v,
          int off)
v - Bufferoff - Offset to setpublic static long[] zeroI(long[] v)
v - existing setpublic static long[] xorI(long[] v,
          long[] o)
v - Primary objecto - data to xorpublic static long[] xorI(long[] v,
          long[] o,
          int off)
v - Primary objecto - data to oroff - Offsetpublic static long[] orI(long[] v,
         long[] o)
v - Primary objecto - data to orpublic static long[] orI(long[] v,
         long[] o,
         int off)
v - Primary objecto - data to oroff - Offsetpublic static long[] andI(long[] v,
          long[] o)
v - Primary objecto - data to andpublic static long[] andI(long[] v,
          long[] o,
          int off)
v - Primary objecto - data to oroff - Offsetpublic static long[] invertI(long[] v)
v - Object to invertpublic static long[] shiftRightI(long[] v,
                 int off)
v - existing bitsetoff - Offset to shift bypublic static long[] shiftLeftI(long[] v,
                int off)
v - existing bitsetoff - Offset to shift bypublic static long cycleRightC(long v,
               int shift,
               int len)
v - Bitsshift - Shift valuelen - Lengthpublic static long[] cycleRightI(long[] v,
                 int shift,
                 int len)
v - Bit stringshift - Number of steps to cyclelen - Lengthpublic static long[] truncateI(long[] v,
               int len)
v - String to processlen - Length (in bits) to truncate topublic static long cycleLeftC(long v,
              int shift,
              int len)
v - Bitsshift - Shift valuelen - Lengthpublic static long[] cycleLeftI(long[] v,
                int shift,
                int len)
v - Bit stringshift - Number of steps to cyclelen - Lengthpublic static String toString(long[] v)
v - Value to processpublic static String toString(long[] v, int minw)
v - Value to processminw - Minimum widthpublic static String toString(long v)
v - Value to processpublic static int numberOfTrailingZerosSigned(long[] v)
v - Bitsetpublic static int numberOfTrailingZeros(long[] v)
v - Bitsetpublic static int numberOfTrailingZerosSigned(long v)
Long.numberOfLeadingZeros(long)
 when the number is 0.v - Longpublic static int numberOfTrailingZeros(long v)
Long.numberOfTrailingZeros(long)v - Longpublic static int numberOfTrailingZeros(int v)
Long.numberOfTrailingZeros(long)v - Longpublic static int numberOfLeadingZerosSigned(long[] v)
v - Bitsetpublic static int numberOfLeadingZeros(long[] v)
v - Bitsetpublic static int numberOfLeadingZerosSigned(long v)
Long.numberOfLeadingZeros(long)
 when the number is 0.v - Bitsetpublic static int numberOfLeadingZerosSigned(int v)
Long.numberOfLeadingZeros(long)
 when the number is 0.v - Bitsetpublic static int numberOfLeadingZeros(long v)
Long.numberOfLeadingZeros(long).v - Bitsetpublic static int numberOfLeadingZeros(int v)
Integer.numberOfLeadingZeros(int).v - Bitsetpublic static int previousSetBit(long[] v,
                 int start)
v - Values to processstart - Start position (inclusive)public static int previousClearBit(long[] v,
                   int start)
v - Values to processstart - Start position (inclusive)public static int nextSetBit(long[] v,
             int start)
v - Value to processstart - Start position (inclusive)public static int nextClearBit(long[] v,
               int start)
v - Value to processstart - Start position (inclusive)public static int magnitude(long[] v)
v - Vector vpublic static int magnitude(long v)
v - Vector vpublic static int magnitude(int v)
v - Vector vpublic static int capacity(long[] v)
v - Vector vpublic static int compare(long[] x,
          long[] y)
x - First bitsety - Second bitset