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.Object
A class for compressing and decompressingdouble
s. 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 interface
DoubleCodec.CompressionInfo
-
Field Summary
Fields Modifier and Type Field Description protected static int
EXP_BIAS
Bias used in representing adouble
exponent.protected static long
EXP_BIT_MASK
Bit mask to isolate the exponent field of adouble
.protected static int
SIGNIFICAND_BITS
The number of physical bits in the significand of adouble
number.protected static long
SIGNIFICANT_BIT_MASK
Bit mask to isolate the significand field of adouble
.protected static int
SUPER_NORMAL_EXPONENT
Exponent in representing aNaN
orInfinity
value.
-
Constructor Summary
Constructors Constructor Description DoubleCodec()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compressDouble(double value, byte[] out)
Compress a singledouble
.abstract int
compressDouble(long doubleBits, byte[] out, int outPos)
Compress the double from its bit representation and write result into out.int
compressDoubles(double[] data, int length, byte[] out)
Compress manydouble
s in one call.abstract int
compressedSize(byte[] data, int pos)
Return the number of bytes used to compress the current value.double
decompressDouble(byte[] data, int pos)
Decompress a single double from the given byte array and return it.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.double[]
decompressDoubles(byte[] data, int length)
Decompress maydouble
s in one call.abstract DoubleCodec.CompressionInfo
describeCompressedValue(byte[] data, int pos, double originalInput)
Return debug info about how the current value is compressed.abstract java.lang.String
describeCompression(int type)
Return some string description on how the data is compressed.protected static byte
getSign(long bits)
Get the sign bit of a bit representation of adouble
.protected static long
getSignificand(long bits)
Get the significand of a bit representation of adouble
.protected static int
getUnbiasedExponent(long bits)
Get the unbiased exponent of a bit representation of adouble
.int
supportedSignificandWith()
-
-
-
Field Detail
-
SIGNIFICAND_BITS
protected static final int SIGNIFICAND_BITS
The number of physical bits in the significand of adouble
number.- See Also:
- Constant Field Values
-
EXP_BIAS
protected static final int EXP_BIAS
Bias used in representing adouble
exponent.- See Also:
- Constant Field Values
-
SUPER_NORMAL_EXPONENT
protected static final int SUPER_NORMAL_EXPONENT
Exponent in representing aNaN
orInfinity
value.- 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 manydouble
s in one call.- Parameters:
data
- the input data to compress.length
- how many value to compress, reading fromdata
starting 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
- ifout
is 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
- ifout
is too small.
-
decompressDoubles
public double[] decompressDoubles(byte[] data, int length)
Decompress maydouble
s 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
- ifdata
did 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 fromdata
at this position.out
- output value, the result should be written usingMutableDouble.doubleValue()
.- Returns:
- the new value of
pos
after 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 fromdata
at 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 fromdata
at this position.- Returns:
- the number of bytes that the compressed value at
pos
is.
-
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 fromdata
at 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
.
-
-