public static int compress ( int [ ] in , int currentPos , int inlength , int out [ ] , int tmpoutpos ) { int origtmpoutpos = tmpoutpos ; int finalpos = currentPos + inlength ; outer : while ( currentPos < finalpos ) { mainloop : for ( int selector = 0 ; selector < 8 ; selector ++ ) { int res = 0 ; int compressedNum = codeNum [ selector ] ; if ( finalpos <= currentPos + compressedNum - 1 ) compressedNum = finalpos - currentPos ; int b = bitLength [ selector ] ; int max = 1 << b ; int i = 0 ; for ( ; i < compressedNum ; i ++ ) { if ( Util . smallerorequalthan ( max , in [ currentPos + i ] ) ) continue mainloop ; res = ( res << b ) + in [ currentPos + i ] ; } if ( compressedNum != codeNum [ selector ] ) res <<= ( codeNum [ selector ] - compressedNum ) * b ; res |= selector << 28 ; out [ tmpoutpos ++ ] = res ; currentPos += compressedNum ; continue outer ; } final int selector = 8 ; if ( in [ currentPos ] >= 1 << bitLength [ selector ] ) throw new RuntimeException ( "Too big a number" ) ; out [ tmpoutpos ++ ] = in [ currentPos ++ ] | ( selector << 28 ) ; } return tmpoutpos - origtmpoutpos ; }
Compress an integer array using Simple9