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_32_BITS
Masking 32 bit
|
private static long |
LONG_63_BITS
Long, with 63 bits set
|
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
|
private static int[] |
POW5_INT
Precomputed powers of 5 for pow5, pow10 on the bit representation.
|
static HashingStrategy<long[]> |
TROVE_HASH_STRATEGY
Hashing strategy to use with Trove.
|
Constructor and Description |
---|
BitsUtil() |
Modifier and Type | Method and Description |
---|---|
static long[] |
andCMax(long[] v,
long[] o)
AND o onto v in a copy, i.e. v & o
The resulting array will have the shorter length of the two.
|
static long[] |
andCMin(long[] v,
long[] o)
AND o onto v in a copy, i.e. v & o
The resulting array will have the shorter length of the two.
|
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 int |
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 boolean |
equal(long[] x,
long[] y)
Test two bitsets for equality
|
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 int |
hammingDistance(long[] x,
long[] y)
Compute the Hamming distance (Size of symmetric difference), i.e.
|
static int |
hammingDistance(long b1,
long b2)
Compute the Hamming distance (Size of symmetric difference), i.e.
|
static int |
hashCode(long x)
Compute a hash code for the given bitset.
|
static int |
hashCode(long[] x)
Compute a hash code for the given bitset.
|
static boolean |
intersect(long[] x,
long[] y)
Test whether two Bitsets intersect.
|
static boolean |
intersect(long x,
long y)
Test whether two Bitsets intersect.
|
static int |
intersectionSize(long[] x,
long[] y)
Compute the intersection size of two Bitsets.
|
static int |
intersectionSize(long x,
long y)
Compute the intersection size of two Bitsets.
|
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 double |
lpow10(long m,
int n)
Compute
m * Math.pow(10,e) on the bit representation, for
assembling a floating point decimal value. |
static double |
lpow2(long m,
int n)
Compute
m * pow(2., n) using bit operations. |
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 long[] |
nandI(long[] v,
long[] o)
NOTAND o onto v inplace, i.e. v &= ~o
|
static int |
nextClearBit(long[] v,
int start)
Find the next clear bit.
|
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 |
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 void |
onesI(long[] v,
int bits)
Fill 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 |
previousClearBit(long v,
int start)
Find the previous clear bit.
|
static int |
previousSetBit(long[] v,
int start)
Find the previous set 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[] |
setI(long[] v,
long[] o)
Put o onto v inplace, i.e. v = o
|
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 String |
toString(long[] v,
String sep,
int offset)
Convert the bitset into a decimal representation, e.g.
|
static String |
toStringLow(long v)
Convert bitset to a string consisting of "0" and "1", in low-endian order.
|
static String |
toStringLow(long[] v)
Convert bitset to a string consisting of "0" and "1", in low-endian order.
|
static String |
toStringLow(long[] v,
int minw)
Convert bitset to a string consisting of "0" and "1", in low-endian order.
|
static long[] |
truncateI(long[] v,
int len)
Truncate a bit string to the given length (setting any higher bit to 0).
|
static int |
unionSize(long[] x,
long[] y)
Compute the union size of two Bitsets.
|
static int |
unionSize(long x,
long y)
Compute the union size of two Bitsets.
|
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
private static final long LONG_63_BITS
private static final long LONG_32_BITS
private static final int[] POW5_INT
public static final HashingStrategy<long[]> TROVE_HASH_STRATEGY
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 int 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[] setI(long[] v, long[] o)
v
- Primary objecto
- data to initialize to.public 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 void onesI(long[] v, int bits)
v
- Vector to fill.bits
- Sizepublic 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[] andCMin(long[] v, long[] o)
v
- Primary objecto
- data to andpublic static long[] andCMax(long[] v, long[] o)
v
- Primary objecto
- data to andpublic static long[] nandI(long[] v, long[] o)
v
- Primary objecto
- data to andpublic 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 String toStringLow(long[] v)
v
- Value to processpublic static String toStringLow(long[] v, int minw)
v
- Value to processminw
- Minimum widthpublic static String toStringLow(long v)
v
- Value to processpublic static String toString(long[] v, String sep, int offset)
v
- Valuesep
- Value separatoroffset
- Counting offset (usually, 0 or 1)public 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 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 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 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 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 boolean intersect(long x, long y)
x
- First bitsety
- Second bitsettrue
when the bitsets intersect.public static boolean intersect(long[] x, long[] y)
x
- First bitsety
- Second bitsettrue
when the bitsets intersect.public static int intersectionSize(long x, long y)
x
- First bitsety
- Second bitsetpublic static int intersectionSize(long[] x, long[] y)
x
- First bitsety
- Second bitsetpublic static int unionSize(long x, long y)
x
- First bitsety
- Second bitsetpublic static int unionSize(long[] x, long[] y)
x
- First bitsety
- Second bitsetpublic static int hammingDistance(long b1, long b2)
cardinality(a ^ b)
.b1
- First vectorb2
- Second vectorpublic static int hammingDistance(long[] x, long[] y)
cardinality(a ^ b)
.x
- First vectory
- Second vectorpublic static int capacity(long[] v)
v
- Vector vpublic static boolean equal(long[] x, long[] y)
x
- First bitsety
- Second bitsettrue
when the bitsets are equalpublic static int compare(long[] x, long[] y)
x
- First bitsety
- Second bitsetpublic static int hashCode(long x)
x
- Bitset bitsetpublic static int hashCode(long[] x)
x
- Bitset bitsetpublic static double lpow2(long m, int n)
m * pow(2., n)
using bit operations.m
- Mantissan
- Exponentpublic static double lpow10(long m, int n)
m * Math.pow(10,e)
on the bit representation, for
assembling a floating point decimal value.m
- Mantissen
- Exponent to base 10.Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.