|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.unimi.dsi.mg4j.util.Fast
All-purpose optimised static-method container class.
This class contains static optimised utility methods that are used by all MG4J classes.
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 double |
GOLOMB_ADD
|
protected static double |
GOLOMB_GAUSSIAN
|
static double |
GOLOMB_MULT
|
static double[] |
GOLOMB_STEP
|
static int |
GOLOMB_STEP_LENGTH
|
static double |
GOLOMB_THRESHOLD
|
Method Summary | |
static String |
format(double d)
Formats a number. |
static String |
format(long l)
Formats a number. |
static int |
gaussianGolombModulus(double sigma)
Computes the Golomb modulus for (positive and negative) integers normally distributed with given standard deviation using the formula ⌈ 2 sqrt( 2 / π ) ln(2) σ ⌉. |
static int |
golombModulus(double p)
Computes the Golomb modulus for a given frequency using the formula GOLOMB_ADD + GOLOMB_MULT / p
if p is smaller than GOLOMB_THRESHOLD ,
scanning GOLOMB_STEP otherwise. |
static int |
int2nat(int x)
Maps integers bijectively into natural numbers. |
static int |
leastSignificantBit(int x)
Computes the least significant bit of an integer. |
static int |
leastSignificantBit(long x)
Computes the least significant bit of a long integer. |
static int[] |
loadInts(String filename)
Loads a list of integers from a data-input file stream. |
static int[] |
loadInts(String filename,
ProgressMeter pm)
Loads a list of integers from a data-input file stream. |
static Object |
loadObject(String filename)
Loads an object from a given file. |
static int |
mostSignificantBit(int x)
Computes the most significant bit of an integer. |
static int |
mostSignificantBit(long x)
Computes the most significant bit of a long integer. |
static int |
nat2int(int x)
Maps natural numbers bijectively into integers. |
static int |
parseIntSize(CharSequence s)
Parses a size specified using units (e.g., K, Ki, M, Mi,…), ensuring that the results fits an integer. |
static long |
parseSize(CharSequence s)
Parses a size specified using units (e.g., K, Ki, M, Mi,…). |
static void |
storeObject(Object o,
String filename)
Stores an object in a given file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final double[] GOLOMB_STEP
public static final int GOLOMB_STEP_LENGTH
public static final double GOLOMB_THRESHOLD
public static final double GOLOMB_ADD
public static final double GOLOMB_MULT
protected static final double GOLOMB_GAUSSIAN
public static final int[] BYTELSB
public static final int[] BYTEMSB
Method Detail |
public static int mostSignificantBit(int x)
x
- an integer.
public static int mostSignificantBit(long x)
x
- a long integer.
public static int leastSignificantBit(int x)
x
- an integer.
public static int leastSignificantBit(long x)
x
- a long integer.
public static int golombModulus(double p)
GOLOMB_ADD
+ GOLOMB_MULT
/ p
if p
is smaller than GOLOMB_THRESHOLD
,
scanning GOLOMB_STEP
otherwise. This gives results that are
extremely close to ⌈ log( 2 - p
) / log( 1 - p
) ⌉,
but order of magnitudes more quickly.
p
- the frequency divided by the overall number of documents.
public static int gaussianGolombModulus(double sigma)
The resulting Golomb modulus is near to optimal for coding such
integers after they have been passed through int2nat(int)
. Note,
however, that Golomb coding is not optimal for a normal distribution.
sigma
- the standard deviation.
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 arbitrary integers using the standard coding methods (which all work on natural numbers).
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 String format(double d)
This method formats a double separating thousands and printing just two fractional digits.
d
- a number.
public static String format(long l)
This method formats a double separating thousands and printing just two fractional digits.
l
- a number.
public static long parseSize(CharSequence s)
s
- a size specified as above.
IllegalArgumentException
- if number is negative or unit is not
among the abovementioned ones.public static int parseIntSize(CharSequence s)
s
- a size specified as above.
IllegalArgumentException
- parseSize(CharSequence)
would, or if
the resulting size exceeds Integer.MAX_VALUE
.parseSize(CharSequence)
public static void storeObject(Object o, String filename) throws FileNotFoundException, IOException
o
- an object.filename
- a filename.
FileNotFoundException
IOException
public static Object loadObject(String filename) throws IOException, ClassNotFoundException
filename
- a filename.
IOException
ClassNotFoundException
public static int[] loadInts(String filename) throws IOException
This method considers the given filename as a list of integers saved
in DataOutput
format.
filename
- a filename.
DataInput
.
IOException
public static int[] loadInts(String filename, ProgressMeter pm) throws IOException
This method considers the given filename as a list of integers saved
in DataOutput
format.
filename
- a filename.pm
- a progress meter, or null
.
DataInput
.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |