Class DeltaBinaryEncoder

  • Direct Known Subclasses:
    DeltaBinaryEncoder.IntDeltaEncoder, DeltaBinaryEncoder.LongDeltaEncoder

    public abstract class DeltaBinaryEncoder
    extends Encoder
    DeltaBinaryEncoder is a encoder for compressing data in type of integer and long. We adapt a hypothesis that contiguous data points have similar values. Thus the difference value of two adjacent points is smaller than those two point values. One integer in java takes 32-bits. If a positive number is less than 2^m, the bits of this integer which index from m to 31 are all 0. Given an array which length is n, if all values in input data array are all positive and less than 2^m, we need actually m*n, but not 32*n bits to store the array.

    DeltaBinaryEncoder calculates difference between two adjacent points and record the minimum of those difference values firstly. Then it saves two_diff value that difference minus minimum of them, to make sure all two_diff values are positive. Then it statistics the longest bit length m it takes for each two_diff value, which means the bit length that maximum two_diff value takes. Only the low m bits are saved into result byte array for all two_diff values.

    • Field Detail

      • out

        protected java.io.ByteArrayOutputStream out
      • blockSize

        protected int blockSize
      • encodingBlockBuffer

        protected byte[] encodingBlockBuffer
      • writeIndex

        protected int writeIndex
      • writeWidth

        protected int writeWidth
    • Constructor Detail

      • DeltaBinaryEncoder

        protected DeltaBinaryEncoder​(int size)
        constructor of DeltaBinaryEncoder.
        Parameters:
        size - - the number how many numbers to be packed into a block.
    • Method Detail

      • writeHeader

        protected abstract void writeHeader()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeValueToBytes

        protected abstract void writeValueToBytes​(int i)
      • calcTwoDiff

        protected abstract void calcTwoDiff​(int i)
      • reset

        protected abstract void reset()
      • calculateBitWidthsForDeltaBlockBuffer

        protected abstract int calculateBitWidthsForDeltaBlockBuffer()
      • flush

        public void flush​(java.io.ByteArrayOutputStream out)
        calling this method to flush all values which haven't encoded to result byte array.
        Specified by:
        flush in class Encoder
        Parameters:
        out - - ByteArrayOutputStream