public final class BitUtil extends Object
Modifier and Type | Method and Description |
---|---|
static int |
bitCount(byte b)
Deprecated.
Use
Integer.bitCount(int) instead. |
static int |
bitList(byte b)
Deprecated.
do not use.
|
static long |
deinterleave(long b)
Deinterleaves long value back to two concatenated 32bit values
|
static long |
flipFlop(long b)
flip flops odd with even bits
|
static long |
interleave(long v1,
long v2)
Interleaves the first 32 bits of each long value
Adapted from: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
|
static int |
nextHighestPowerOfTwo(int v)
returns the next highest power of two, or the current value if it's already a power of two or zero
|
static long |
nextHighestPowerOfTwo(long v)
returns the next highest power of two, or the current value if it's already a power of two or zero
|
static long |
pop_andnot(long[] arr1,
long[] arr2,
int wordOffset,
int numWords)
Returns the popcount or cardinality of
A & ~B . |
static long |
pop_array(long[] arr,
int wordOffset,
int numWords)
Returns the number of set bits in an array of longs.
|
static long |
pop_intersect(long[] arr1,
long[] arr2,
int wordOffset,
int numWords)
Returns the popcount or cardinality of the two sets after an intersection.
|
static long |
pop_union(long[] arr1,
long[] arr2,
int wordOffset,
int numWords)
Returns the popcount or cardinality of the union of two sets.
|
static long |
pop_xor(long[] arr1,
long[] arr2,
int wordOffset,
int numWords)
Returns the popcount or cardinality of A ^ B
Neither array is modified.
|
static int |
zigZagDecode(int i)
Decode an int previously encoded with
zigZagEncode(int) . |
static long |
zigZagDecode(long l)
Decode a long previously encoded with
zigZagEncode(long) . |
static int |
zigZagEncode(int i)
Same as
zigZagEncode(long) but on integers. |
static long |
zigZagEncode(long l)
Zig-zag
encode the provided long.
|
@Deprecated public static int bitCount(byte b)
Integer.bitCount(int)
instead.@Deprecated public static int bitList(byte b)
(i >>> (4 * n)) & 0x0F
is the offset of the n-th set bit of
the given byte plus one, or 0 if there are n or less bits set in the given
byte. For example bitList(12)
returns 0x43:0x43 & 0x0F
is 3, meaning the the first bit set is at offset 3-1 = 2,(0x43 >>> 4) & 0x0F
is 4, meaning there is a second bit set at offset 4-1=3,(0x43 >>> 8) & 0x0F
is 0, meaning there is no more bit set in this byte.public static long pop_array(long[] arr, int wordOffset, int numWords)
public static long pop_intersect(long[] arr1, long[] arr2, int wordOffset, int numWords)
public static long pop_union(long[] arr1, long[] arr2, int wordOffset, int numWords)
public static long pop_andnot(long[] arr1, long[] arr2, int wordOffset, int numWords)
A & ~B
.
Neither array is modified.public static long pop_xor(long[] arr1, long[] arr2, int wordOffset, int numWords)
public static int nextHighestPowerOfTwo(int v)
public static long nextHighestPowerOfTwo(long v)
public static long interleave(long v1, long v2)
public static long deinterleave(long b)
public static final long flipFlop(long b)
public static int zigZagEncode(int i)
zigZagEncode(long)
but on integers.public static long zigZagEncode(long l)
public static int zigZagDecode(int i)
zigZagEncode(int)
.public static long zigZagDecode(long l)
zigZagEncode(long)
.Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.