Package org.apache.lucene.util
Class BitUtil
- java.lang.Object
-
- org.apache.lucene.util.BitUtil
-
public final class BitUtil extends java.lang.Object
A variety of high efficiency bit twiddling routines.
-
-
Field Summary
Fields Modifier and Type Field Description private static long
MAGIC0
private static long
MAGIC1
private static long
MAGIC2
private static long
MAGIC3
private static long
MAGIC4
private static long
MAGIC5
private static long
MAGIC6
private static long
SHIFT0
private static long
SHIFT1
private static long
SHIFT2
private static long
SHIFT3
private static long
SHIFT4
-
Constructor Summary
Constructors Modifier Constructor Description private
BitUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
deinterleave(long b)
Extract just the even-bits value as a long from the bit-interleaved valuestatic long
flipFlop(long b)
flip flops odd with even bitsstatic long
interleave(int even, int odd)
Interleaves the first 32 bits of each long value Adapted from: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMNstatic int
nextHighestPowerOfTwo(int v)
returns the next highest power of two, or the current value if it's already a power of two or zerostatic long
nextHighestPowerOfTwo(long v)
returns the next highest power of two, or the current value if it's already a power of two or zerostatic long
pop_andnot(long[] arr1, long[] arr2, int wordOffset, int numWords)
Returns the popcount or cardinality ofA & ~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 withzigZagEncode(int)
.static long
zigZagDecode(long l)
Decode a long previously encoded withzigZagEncode(long)
.static int
zigZagEncode(int i)
Same aszigZagEncode(long)
but on integers.static long
zigZagEncode(long l)
Zig-zag encode the provided long.
-
-
-
Field Detail
-
MAGIC0
private static final long MAGIC0
- See Also:
- Constant Field Values
-
MAGIC1
private static final long MAGIC1
- See Also:
- Constant Field Values
-
MAGIC2
private static final long MAGIC2
- See Also:
- Constant Field Values
-
MAGIC3
private static final long MAGIC3
- See Also:
- Constant Field Values
-
MAGIC4
private static final long MAGIC4
- See Also:
- Constant Field Values
-
MAGIC5
private static final long MAGIC5
- See Also:
- Constant Field Values
-
MAGIC6
private static final long MAGIC6
- See Also:
- Constant Field Values
-
SHIFT0
private static final long SHIFT0
- See Also:
- Constant Field Values
-
SHIFT1
private static final long SHIFT1
- See Also:
- Constant Field Values
-
SHIFT2
private static final long SHIFT2
- See Also:
- Constant Field Values
-
SHIFT3
private static final long SHIFT3
- See Also:
- Constant Field Values
-
SHIFT4
private static final long SHIFT4
- See Also:
- Constant Field Values
-
-
Method Detail
-
pop_array
public static long pop_array(long[] arr, int wordOffset, int numWords)
Returns the number of set bits in an array of longs.
-
pop_intersect
public static long pop_intersect(long[] arr1, long[] arr2, int wordOffset, int numWords)
Returns the popcount or cardinality of the two sets after an intersection. Neither array is modified.
-
pop_union
public static long pop_union(long[] arr1, long[] arr2, int wordOffset, int numWords)
Returns the popcount or cardinality of the union of two sets. Neither array is modified.
-
pop_andnot
public static long pop_andnot(long[] arr1, long[] arr2, int wordOffset, int numWords)
Returns the popcount or cardinality ofA & ~B
. Neither array is modified.
-
pop_xor
public static long pop_xor(long[] arr1, long[] arr2, int wordOffset, int numWords)
Returns the popcount or cardinality of A ^ B Neither array is modified.
-
nextHighestPowerOfTwo
public 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
-
nextHighestPowerOfTwo
public 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
-
interleave
public 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
-
deinterleave
public static long deinterleave(long b)
Extract just the even-bits value as a long from the bit-interleaved value
-
flipFlop
public static long flipFlop(long b)
flip flops odd with even bits
-
zigZagEncode
public static int zigZagEncode(int i)
Same aszigZagEncode(long)
but on integers.
-
zigZagEncode
public static long zigZagEncode(long l)
Zig-zag encode the provided long. Assuming the input is a signed long whose absolute value can be stored on n bits, the returned value will be an unsigned long that can be stored on n+1 bits.
-
zigZagDecode
public static int zigZagDecode(int i)
Decode an int previously encoded withzigZagEncode(int)
.
-
zigZagDecode
public static long zigZagDecode(long l)
Decode a long previously encoded withzigZagEncode(long)
.
-
-