private static short [ ] makeDecodingTable ( final short [ ] encodingTable , final int numByteValues ) { final short [ ] decodingTable = new short [ 4096 ] ; for ( int byteValue = 0 ; byteValue < numByteValues ; byteValue ++ ) { final int encodingEntry = encodingTable [ byteValue ] & 0xFFFF ; final int codeValue = encodingEntry & 0xfff ; final int codeLength = encodingEntry >> 12 ; final int decodingEntry = ( codeLength << 8 ) | byteValue ; final int garbageLength = 12 - codeLength ; final int numCopies = 1 << garbageLength ; for ( int garbageBits = 0 ; garbageBits < numCopies ; garbageBits ++ ) { final int extendedCodeValue = codeValue | ( garbageBits << codeLength ) ; decodingTable [ extendedCodeValue & 0xfff ] = ( short ) decodingEntry ; } } return ( decodingTable ) ; }
Given an encoding table that maps unsigned bytes to codewords of length at most 12 this builds a size - 4096 decoding table .