public final class BitUtil extends Object
Modifier and Type | Method and Description |
---|---|
static int |
countBits(long[] bits,
int numLongs)
Counts all bits set in the provided longs.
|
static int |
countBitsUpTo(long[] bits,
int numLongs,
int bitIndex)
Counts the bits set up to the given bit zero-based index, exclusive.
|
static long |
deinterleave(long b)
Extract just the even-bits value as a long from the bit-interleaved value
|
static long |
flipFlop(long b)
flip flops odd with even bits
|
static long |
interleave(int even,
int odd)
Interleaves the first 32 bits of each long value
Adapted from: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
|
static boolean |
isBitSet(long[] bits,
int numLongs,
int bitIndex)
Returns whether the bit at given zero-based index is set.
|
static int |
nextBitSet(long[] bits,
int numLongs,
int bitIndex)
Returns the index of the next bit set following the given bit zero-based index.
|
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 |
previousBitSet(long[] bits,
int numLongs,
int bitIndex)
Returns the index of the previous bit set preceding the given bit zero-based index.
|
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.
|
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(int even, int odd)
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)
.public static boolean isBitSet(long[] bits, int numLongs, int bitIndex)
bits
- The bits stored in an array of long for efficiency.numLongs
- The number of longs in bits
to consider.bitIndex
- The bit zero-based index. It must be greater than or equal to 0,
and strictly less than numLongs * Long.SIZE
.public static int countBits(long[] bits, int numLongs)
bits
- The bits stored in an array of long for efficiency.numLongs
- The number of longs in bits
to consider.public static int countBitsUpTo(long[] bits, int numLongs, int bitIndex)
bits
- The bits stored in an array of long for efficiency.numLongs
- The number of longs in bits
to consider.bitIndex
- The bit zero-based index, exclusive. It must be greater than or equal to 0,
and less than or equal to numLongs * Long.SIZE
.public static int nextBitSet(long[] bits, int numLongs, int bitIndex)
bits
- The bits stored in an array of long for efficiency.numLongs
- The number of longs in bits
to consider.bitIndex
- The bit zero-based index. It must be greater than or equal to -1,
and strictly less than numLongs * Long.SIZE
.bitIndex
;
or -1 if none.public static int previousBitSet(long[] bits, int numLongs, int bitIndex)
bits
- The bits stored in an array of long for efficiency.numLongs
- The number of longs in bits
to consider.bitIndex
- The bit zero-based index. It must be greater than or equal to 0,
and less than or equal to numLongs * Long.SIZE
.bitIndex
;
or -1 if none.Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.