3.1.8.1.4.3.1 Encoding the Copy-Offset

Encoding of the copy-offset is shown in the previous figure by the Action A item. The following describes the algorithm for encoding the copy-offset.

 LUTIndex = IndexOfEqualOrSmallerEntry(CopyOffset + 1, CopyOffsetBaseLUT)
 HuffmanIndex = LUTIndex + 257
 OutputBits(HuffCodeLEC[HuffmanIndex], HuffLengthLEC[HuffmanIndex])
  
 ExtraBitsLength = CopyOffsetBitsLUT[LUTIndex]
 ExtraBits = CopyOffset & ((2 ^ ExtraBitsLen) - 1)
 OutputBits(ExtraBits, ExtraBitsLength)

The IndexOfEqualOrSmallerEntry function searches through the specified LUT table and returns the index of the entry that contains a value of equal or lesser value than the first parameter. The OutputBits function outputs the bits specified by the first parameter in the appropriate order (the number of bits to output is given by the second parameter). "^" is the exponentiation operator, and "&" is the bitwise AND operator.