Package org.neo4j.gds.core.loading
Class DoubleCodec
- java.lang.Object
-
- org.neo4j.gds.core.loading.DoubleCodec
-
- Direct Known Subclasses:
NoopDoubleCodec
public abstract class DoubleCodec extends java.lang.ObjectA class for compressing and decompressingdoubles. There are various methods for compressing either a single double, or multiple ones in one call. Similar methods exist for decompression. The compression itself is identical for all those methods. The difference they provide is in how much reuse of buffer data structures is allowed. Implementors need to implement onlycompressDouble(long,byte[],int)for compressing anddecompressDouble(byte[],int,MutableDouble)for decompressing. The other methods for compression or decompression can be override if a better implementation can be provided. In addition,compressedSize(byte[], int)must provide the number of bytes for a certain compressed value. This is required as many decompressing methods to not offer feedback on how much data they've read. For testing and debug purposes, implementors need to providedescribeCompressedValue(byte[], int, double). The value that is returned fromDoubleCodec.CompressionInfo.compressedType()is used to calldescribeCompression(int)so that one should be implemented accordingly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDoubleCodec.CompressionInfo
-
Field Summary
Fields Modifier and Type Field Description protected static intEXP_BIASBias used in representing adoubleexponent.protected static longEXP_BIT_MASKBit mask to isolate the exponent field of adouble.protected static intSIGNIFICAND_BITSThe number of physical bits in the significand of adoublenumber.protected static longSIGNIFICANT_BIT_MASKBit mask to isolate the significand field of adouble.protected static intSUPER_NORMAL_EXPONENTExponent in representing aNaNorInfinityvalue.
-
Constructor Summary
Constructors Constructor Description DoubleCodec()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intcompressDouble(double value, byte[] out)Compress a singledouble.abstract intcompressDouble(long doubleBits, byte[] out, int outPos)Compress the double from its bit representation and write result into out.intcompressDoubles(double[] data, int length, byte[] out)Compress manydoubles in one call.abstract intcompressedSize(byte[] data, int pos)Return the number of bytes used to compress the current value.doubledecompressDouble(byte[] data, int pos)Decompress a single double from the given byte array and return it.abstract intdecompressDouble(byte[] data, int pos, org.apache.commons.lang3.mutable.MutableDouble out)Decompress a single double from the given byte array and write the result into out.double[]decompressDoubles(byte[] data, int length)Decompress maydoubles in one call.abstract DoubleCodec.CompressionInfodescribeCompressedValue(byte[] data, int pos, double originalInput)Return debug info about how the current value is compressed.abstract java.lang.StringdescribeCompression(int type)Return some string description on how the data is compressed.protected static bytegetSign(long bits)Get the sign bit of a bit representation of adouble.protected static longgetSignificand(long bits)Get the significand of a bit representation of adouble.protected static intgetUnbiasedExponent(long bits)Get the unbiased exponent of a bit representation of adouble.intsupportedSignificandWith()
-
-
-
Field Detail
-
SIGNIFICAND_BITS
protected static final int SIGNIFICAND_BITS
The number of physical bits in the significand of adoublenumber.- See Also:
- Constant Field Values
-
EXP_BIAS
protected static final int EXP_BIAS
Bias used in representing adoubleexponent.- See Also:
- Constant Field Values
-
SUPER_NORMAL_EXPONENT
protected static final int SUPER_NORMAL_EXPONENT
Exponent in representing aNaNorInfinityvalue.- See Also:
- Constant Field Values
-
EXP_BIT_MASK
protected static final long EXP_BIT_MASK
Bit mask to isolate the exponent field of adouble.- See Also:
- Constant Field Values
-
SIGNIFICANT_BIT_MASK
protected static final long SIGNIFICANT_BIT_MASK
Bit mask to isolate the significand field of adouble.- See Also:
- Constant Field Values
-
-
Method Detail
-
getSign
protected static byte getSign(long bits)
Get the sign bit of a bit representation of adouble.
-
getUnbiasedExponent
protected static int getUnbiasedExponent(long bits)
Get the unbiased exponent of a bit representation of adouble.
-
getSignificand
protected static long getSignificand(long bits)
Get the significand of a bit representation of adouble.
-
compressDoubles
public int compressDoubles(double[] data, int length, byte[] out)Compress manydoubles in one call.- Parameters:
data- the input data to compress.length- how many value to compress, reading fromdatastarting at index 0 upto indexlength.out- the output buffer where the compressed values are written to.- Returns:
- the number of bytes written into
out. - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifoutis too small.
-
compressDouble
public int compressDouble(double value, byte[] out)Compress a singledouble.- Parameters:
value- the value to compress.out- the output buffer where the compressed value is written to.- Returns:
- the number of bytes written into
out. Technically, this is the next position to start writing to, but since we write to the beginning of the array, this is equal to the number of bytes written. - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifoutis too small.
-
decompressDoubles
public double[] decompressDoubles(byte[] data, int length)Decompress maydoubles in one call. The data is read from index 0. There is no way to know how many bytes have been read.- Parameters:
data- the compressed data.length- how many values to decompress.- Returns:
- the decompressed values.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- ifdatadid not contain enough data for all values.
-
compressDouble
public abstract int compressDouble(long doubleBits, byte[] out, int outPos)Compress the double from its bit representation and write result into out.- Parameters:
doubleBits- the double value as converted byDouble.doubleToRawLongBits(double).out- the output buffer where the compressed value is written to.outPos- at which position to write the compressed value inout.- Returns:
- the new value of
outPos(NOT the number of bytes written).
-
decompressDouble
public abstract int decompressDouble(byte[] data, int pos, org.apache.commons.lang3.mutable.MutableDouble out)Decompress a single double from the given byte array and write the result into out.- Parameters:
data- the compressed data.pos- start reading fromdataat this position.out- output value, the result should be written usingMutableDouble.doubleValue().- Returns:
- the new value of
posafter reading the compressed value.
-
decompressDouble
public double decompressDouble(byte[] data, int pos)Decompress a single double from the given byte array and return it. There is no way to know how many bytes have been read.- Parameters:
data- the compressed data.pos- start reading fromdataat this position.- Returns:
- the decompressed value.
-
compressedSize
public abstract int compressedSize(byte[] data, int pos)Return the number of bytes used to compress the current value.- Parameters:
data- the compressed data.pos- start reading fromdataat this position.- Returns:
- the number of bytes that the compressed value at
posis.
-
describeCompression
@TestOnly public abstract java.lang.String describeCompression(int type)
Return some string description on how the data is compressed. For debugging or testing.- Parameters:
type- a type identifier.- Returns:
- some string for describing how the data is compressed.
-
describeCompressedValue
@TestOnly public abstract DoubleCodec.CompressionInfo describeCompressedValue(byte[] data, int pos, double originalInput)
Return debug info about how the current value is compressed. For debugging or testing.- Parameters:
data- the compressed data.pos- start reading fromdataat this position.- Returns:
- info object describing the current compressed value.
-
supportedSignificandWith
@TestOnly public int supportedSignificandWith()
- Returns:
- the guaranteed maximum significand width.
If the compression is lossless, this value must equal
SIGNIFICAND_WIDTH.
-
-