public static final int s16Compress(int[] out, int outOffset, int[] in,
                int inOffset, int n, int blockSize) {
                int numIdx = 0, j = 0, num = 0, bits = 0;
                try {
                        for (numIdx = 0; numIdx < S16_NUMSIZE; numIdx++) {
                                out[outOffset] = numIdx << S16_BITSSIZE;
                                num = (S16_NUM[numIdx] < n) ? S16_NUM[numIdx]
                                        : n;

                                for (j = 0, bits = 0; (j < num)
                                        && in[inOffset + j] < (1 << S16_BITS[numIdx][j]);) {
                                        out[outOffset] |= (in[inOffset + j] << bits);
                                        bits += S16_BITS[numIdx][j];
                                        j++;
                                }

                                if (j == num) {
                                        return num;
                                }
                        }
                } catch (Exception e) {
                        System.out.println("s16Compress: " + "numIdx:" + numIdx
                                + ",j:" + j + ",num:" + num + ",bits: " + bits);
                        e.printStackTrace();
                }

                return -1;
        }
public static final int s16Compress ( int [ ] out , int outOffset , int [ ] in , int inOffset , int n , int blockSize ) { int numIdx = 0 , j = 0 , num = 0 , bits = 0 ; try { for ( numIdx = 0 ; numIdx < S16_NUMSIZE ; numIdx ++ ) { out [ outOffset ] = numIdx << S16_BITSSIZE ; num = ( S16_NUM [ numIdx ] < n ) ? S16_NUM [ numIdx ] : n ; for ( j = 0 , bits = 0 ; ( j < num ) && in [ inOffset + j ] < ( 1 << S16_BITS [ numIdx ] [ j ] ) ; ) { out [ outOffset ] |= ( in [ inOffset + j ] << bits ) ; bits += S16_BITS [ numIdx ] [ j ] ; j ++ ; } if ( j == num ) { return num ; } } } catch ( Exception e ) { System . out . println ( "s16Compress: " + "numIdx:" + numIdx + ",j:" + j + ",num:" + num + ",bits: " + bits ) ; e . printStackTrace ( ) ; } return - 1 ; }
Compress an integer array using Simple16

@param out
the compressed output
@param outOffset
the offset of the output in the number of integers
@param in
the integer input array
@param inOffset
the offset of the input in the number of integers
@param n
the number of elements to be compressed
@param blockSize block size
@return the number of compressed integers