Package org.apache.lucene.util
Class BitUtil
java.lang.Object
org.apache.lucene.util.BitUtil
A variety of high efficiency bit twiddling routines and encoders for primitives.
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VarHandle
Deprecated.Better use little endian unless it is needed for backwards compatibility.static final VarHandle
Deprecated.Better use little endian unless it is needed for backwards compatibility.static final VarHandle
Deprecated.Better use little endian unless it is needed for backwards compatibility.static final VarHandle
Deprecated.Better use little endian unless it is needed for backwards compatibility.static final VarHandle
Deprecated.Better use little endian unless it is needed for backwards compatibility.static final VarHandle
AVarHandle
to read/write little endiandouble
from a byte array.static final VarHandle
AVarHandle
to read/write little endianfloat
from a byte array.static final VarHandle
AVarHandle
to read/write little endianint
from a byte array.static final VarHandle
AVarHandle
to read/write little endianlong
from a byte array.static final VarHandle
AVarHandle
to read/write little endianshort
from/to a byte array. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 valuestatic 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 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 Details
-
VH_LE_SHORT
AVarHandle
to read/write little endianshort
from/to a byte array. Shape:short vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, short val)
-
VH_LE_INT
AVarHandle
to read/write little endianint
from a byte array. Shape:int vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, int val)
-
VH_LE_LONG
AVarHandle
to read/write little endianlong
from a byte array. Shape:long vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, long val)
-
VH_LE_FLOAT
AVarHandle
to read/write little endianfloat
from a byte array. Shape:float vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, float val)
-
VH_LE_DOUBLE
AVarHandle
to read/write little endiandouble
from a byte array. Shape:double vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, double val)
-
VH_BE_SHORT
Deprecated.Better use little endian unless it is needed for backwards compatibility.AVarHandle
to read/write big endianshort
from a byte array. Shape:short vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, short val)
-
VH_BE_INT
Deprecated.Better use little endian unless it is needed for backwards compatibility.AVarHandle
to read/write big endianint
from a byte array. Shape:int vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, int val)
-
VH_BE_LONG
Deprecated.Better use little endian unless it is needed for backwards compatibility.AVarHandle
to read/write big endianlong
from a byte array. Shape:long vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, long val)
-
VH_BE_FLOAT
Deprecated.Better use little endian unless it is needed for backwards compatibility.AVarHandle
to read/write big endianfloat
from a byte array. Shape:float vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, float val)
-
VH_BE_DOUBLE
Deprecated.Better use little endian unless it is needed for backwards compatibility.AVarHandle
to read/write big endiandouble
from a byte array. Shape:double vh.get(byte[] arr, int ofs)
andvoid vh.set(byte[] arr, int ofs, double val)
-
-
Method Details
-
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 valueAdapted 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 onn
bits, the returned value will be an unsigned long that can be stored onn+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)
.
-