com.kamikaze.pfordelta
Class PForDelta

java.lang.Object
  extended by com.kamikaze.pfordelta.PForDelta

public class PForDelta
extends Object

Implementation of the optimized PForDelta algorithm for sorted integer arrays. The basic ideas are based on 1. Original algorithm from http://homepages.cwi.nl/~heman/downloads/msthesis.pdf 2. Optimization and variation from http://www2008.org/papers/pdf/p387-zhangA.pdf 3. Further optimization http://www2009.org/proceedings/pdf/p401.pdf As a part of the PForDelta implementation, Simple16 is used to compress exceptions. The original Simple16 algorithm can also be found in the above literatures. This implementation overcomes the problem that Simple16 cannot deal with >2^28 numbers. Author: hao yan [email protected]


Constructor Summary
PForDelta()
           
 
Method Summary
static boolean checkBigNumbers(int[] inputBlock, int bits, int blockSize)
          Check if the block contains big numbers that is greater than ((1<< bits)-1)
static int[] compressOneBlock(int[] inputBlock, int bits, int blockSize)
          The core implementation of compressing a block with blockSize integers using PForDelta with the given parameter b
static int[] compressOneBlockOpt(int[] inBlock, int blockSize)
          Compress one block of blockSize integers using PForDelta with the optimal parameter b
static int decompressBBitSlots(int[] outDecompSlots, int[] inCompBlock, int blockSize, int bits)
          Decompress b-bit slots
static int decompressBlockByS16(int[] outDecompBlock, int[] inCompBlock, int inStartOffsetInBits, int blockSize)
          Decompress a block of blockSize integers using Simple16 algorithm
static int decompressOneBlock(int[] outBlock, int[] inBlock, int blockSize)
          Decompress one block using PForDelta
static int estimateCompressedSize(int[] inputBlock, int bits, int blockSize)
          Estimate the compressed size in ints of a block
static int readBits(int[] in, int inOffset, int bits)
          Read a certain number of bits of an integer into an integer array starting from the given start offset
static void writeBits(int[] out, int val, int outOffset, int bits)
          Write a certain number of bits of an integer into an integer array starting from the given start offset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PForDelta

public PForDelta()
Method Detail

compressOneBlockOpt

public static int[] compressOneBlockOpt(int[] inBlock,
                                        int blockSize)
Compress one block of blockSize integers using PForDelta with the optimal parameter b

Parameters:
inBlock - the block to be compressed
blockSize - the block size
Returns:
the compressed block

decompressOneBlock

public static int decompressOneBlock(int[] outBlock,
                                     int[] inBlock,
                                     int blockSize)
Decompress one block using PForDelta

Parameters:
outBlock - the block that was decompressed
inBlock - the block to be decompressed
blockSize - the number of elements in the decompressed block
Returns:
the compressed size in bits

estimateCompressedSize

public static int estimateCompressedSize(int[] inputBlock,
                                         int bits,
                                         int blockSize)
                                  throws IllegalArgumentException
Estimate the compressed size in ints of a block

Parameters:
inputBlock - the block to be compressed
bits - the value of the parameter b
blockSize - the block size
Returns:
the compressed size in ints
Throws:
IllegalArgumentException

checkBigNumbers

public static boolean checkBigNumbers(int[] inputBlock,
                                      int bits,
                                      int blockSize)
                               throws IllegalArgumentException
Check if the block contains big numbers that is greater than ((1<< bits)-1)

Parameters:
inputBlock - the block to be compressed
bits - the numbers of bits to decide whether a number is a big number
blockSize - the block size
Returns:
true if there is any big numbers in the block
Throws:
IllegalArgumentException

compressOneBlock

public static int[] compressOneBlock(int[] inputBlock,
                                     int bits,
                                     int blockSize)
                              throws IllegalArgumentException
The core implementation of compressing a block with blockSize integers using PForDelta with the given parameter b

Parameters:
inputBlock - the block to be compressed
bits - the the value of the parameter b
blockSize - the block size
Returns:
the compressed block
Throws:
IllegalArgumentException

decompressBBitSlots

public static int decompressBBitSlots(int[] outDecompSlots,
                                      int[] inCompBlock,
                                      int blockSize,
                                      int bits)
Decompress b-bit slots

Parameters:
outDecompSlots - decompressed block which is the output
inCompBlock - the compressed block which is the input
blockSize - the block size
bits - the value of the parameter b
Returns:
the compressed size in bits of the data that has been decompressed

decompressBlockByS16

public static int decompressBlockByS16(int[] outDecompBlock,
                                       int[] inCompBlock,
                                       int inStartOffsetInBits,
                                       int blockSize)
Decompress a block of blockSize integers using Simple16 algorithm

Parameters:
outDecompBlock - the decompressed block which is the output
inCompBlock - the compressed block which is the input
blockSize - the block size
inStartOffsetInBits - the start offset in bits of the compressed block
Returns:
the compressed size in bits of the data that has been decompressed

writeBits

public static final void writeBits(int[] out,
                                   int val,
                                   int outOffset,
                                   int bits)
Write a certain number of bits of an integer into an integer array starting from the given start offset

Parameters:
out - the output array
val - the integer to be written
outOffset - the start offset in bits in the output array
bits - the number of bits to be written (bits>=0)

readBits

public static final int readBits(int[] in,
                                 int inOffset,
                                 int bits)
Read a certain number of bits of an integer into an integer array starting from the given start offset

Parameters:
in - the input array
inOffset - the start offset in bits in the input array
bits - the number of bits to be read, unlike writeBits(), readBits() does not deal with bits==0 and thus bits must > 0. When bits ==0, the calling functions will just skip the entire bits-bit slots without decoding them
Returns:
the bits bits of the input


Copyright © 2013. All Rights Reserved.