|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.unimi.dsi.bits.Fast
public final class Fast
All-purpose optimised bit-fiddling static-method container class.
This class contains static optimised utility methods that are used by all classes manipulating bits. They include:
log2(double)
, ceilLog2(int)
, etc.;
Field Summary | |
---|---|
static int[] |
BYTELSB
Precomputed least significant bits for bytes (-1 for 0 ). |
static int[] |
BYTEMSB
Precomputed most significant bits for bytes (-1 for 0 ). |
static long |
INCR_STEP_8
|
static long |
MSBS_STEP_8
|
static long |
ONES_STEP_4
|
static long |
ONES_STEP_8
|
Method Summary | |
---|---|
static int |
approximateLog2(double x)
Computes an approximate integer base-2 logarithm of the argument. |
static int |
ceilLog2(int x)
Computes the ceiling of the base-two logarithm of the argument. |
static int |
ceilLog2(long x)
Computes the ceiling of the base-two logarithm of the argument. |
static int |
count(long x)
Returns the number of bits set to one in a long. |
static int |
int2nat(int x)
Maps integers bijectively into natural numbers. |
static long |
int2nat(long x)
Maps longs bijectively into long natural numbers. |
static int |
leastSignificantBit(long x)
Computes the least significant bit of a long integer. |
static int |
length(int x)
Returns the number of bits that are necessary to encode the argument. |
static int |
length(long x)
Returns the number of bits that are necessary to encode the argument. |
static double |
log2(double x)
Returns the base-two logarithm of the argument. |
static void |
main(String[] a)
|
static int |
mostSignificantBit(int x)
Returns the most significant bit of an integer. |
static int |
mostSignificantBit(long x)
Returns the most significant bit of a long. |
static int |
nat2int(int x)
Maps natural numbers bijectively into integers. |
static long |
nat2int(long x)
Maps long natural numbers bijectively into longs. |
static double |
pow2(int exponent)
Quickly raises 2 to the argument. |
static long |
reverseBytes(long l)
Reverses the bytes of the a long integer. |
static int |
select(long x,
int rank)
Returns the position of a bit of given rank. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long ONES_STEP_4
public static final long ONES_STEP_8
public static final long MSBS_STEP_8
public static final long INCR_STEP_8
public static final int[] BYTELSB
public static final int[] BYTEMSB
Method Detail |
---|
public static int int2nat(int x)
This method will map a negative integer x to -2x-1 and
a nonnegative integer x to 2x. It can be used to save
integers in the range [Integer.MIN_VALUE
/2..Integer.MAX_VALUE
/2]
(i.e., [-230..230-1])
using the standard coding methods (which all work on natural numbers). Note
that no range checks are performed.
The inverse of the above map is computed by nat2int(int)
.
x
- an integer.
nat2int(int)
public static int nat2int(int x)
This method computes the inverse of int2nat(int)
.
x
- a natural number.
int2nat(int)
public static long int2nat(long x)
This method will map a negative long x to -2x-1 and
a nonnegative long x to 2x. It can be used to save
longs in the range [Long.MIN_VALUE
/2..Long.MAX_VALUE
/2]
(i.e., [-262..262-1])
using the standard coding methods (which all work on natural numbers). Note
that no range checks are performed.
The inverse of the above map is computed by nat2int(long)
.
x
- a long.
int2nat(int)
public static long nat2int(long x)
This method computes the inverse of int2nat(long)
.
x
- a long natural number.
nat2int(int)
public static double log2(double x)
x
- a double.
x
.public static int ceilLog2(int x)
This method relies on mostSignificantBit(int)
, and thus is pretty fast.
x
- an integer.
x
is zero.public static int ceilLog2(long x)
This method relies on mostSignificantBit(long)
, and thus is pretty fast.
x
- an integer.
x
is zero.public static int approximateLog2(double x)
This method relies on Double.doubleToRawLongBits(double)
, and thus is very
fast if the former is intrinsified by the JVM.
x
- a double.
public static double pow2(int exponent)
exponent
- an integer exponent between -62 ad 62.
exponent
.public static int length(int x)
x
- an integer.
x
.public static int length(long x)
x
- a long.
x
.public static int count(long x)
This method implements a classical broadword algorithm.
x
- a long.
x
.public static int select(long x, int rank)
This method implements a new broadword algorithm.
x
- a long.rank
- a rank (smaller than 128).
x
of the bit of rank k
ones; if no such
bit exists, returns 72.public static int mostSignificantBit(long x)
This method implements Gerth Brodal's broadword algorithm. On 64-bit architectures it is an order of magnitude faster than standard bit-fiddling techniques.
x
- a long.
x
, of x
is nonzero; −1, otherwise.public static int mostSignificantBit(int x)
x
- an integer.
x
, of x
is nonzero; −1, otherwise.mostSignificantBit(long)
public static int leastSignificantBit(long x)
x
- a long integer.
public static long reverseBytes(long l)
l
- a long integer.
l
: the first byte is the last byte of l
, and so on.public static void main(String[] a)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |