public static void WriteMatch(int matchLen, int matchPos, OutputBuffer output)
        {
            Debug.Assert(matchLen >= FastEncoderWindow.MinMatch && matchLen <= FastEncoderWindow.MaxMatch,
                         "Illegal currentMatch length!");

            // Get the code information for a match code
            var codeInfo =
                FastEncoderStatics.FastEncoderLiteralCodeInfo[
                    (FastEncoderStatics.NumChars + 1 - FastEncoderWindow.MinMatch) + matchLen];
            var codeLen = (int)codeInfo & 31;

            Debug.Assert(codeLen != 0, "Invalid Match Length!");
            if (codeLen <= 16)
            {
                output.WriteBits(codeLen, codeInfo >> 5);
            }
            else
            {
                output.WriteBits(16, (codeInfo >> 5) & 65535);
                output.WriteBits(codeLen - 16, codeInfo >> (5 + 16));
            }

            // Get the code information for a distance code
            codeInfo = FastEncoderStatics.FastEncoderDistanceCodeInfo[FastEncoderStatics.GetSlot(matchPos)];
            output.WriteBits((int)(codeInfo & 15), codeInfo >> 8);
            var extraBits = (int)(codeInfo >> 4) & 15;

            if (extraBits != 0)
            {
                output.WriteBits(extraBits, (uint)matchPos & FastEncoderStatics.BitMask[extraBits]);
            }
        }
        // Calculate the huffman code for each character based on the code length for each character.
        // This algorithm is described in standard RFC 1951
        private uint[] CalculateHuffmanCode()
        {
            var bitLengthCount = new uint[17];

            foreach (var codeLength in _codeLengthArray)
            {
                bitLengthCount[codeLength]++;
            }
            bitLengthCount[0] = 0;  // clear count for length 0

            var  nextCode = new uint[17];
            uint tempCode = 0;

            for (var bits = 1; bits <= 16; bits++)
            {
                tempCode       = (tempCode + bitLengthCount[bits - 1]) << 1;
                nextCode[bits] = tempCode;
            }

            var code = new uint[MaxLiteralTreeElements];

            for (var i = 0; i < _codeLengthArray.Length; i++)
            {
                int len = _codeLengthArray[i];
                if (len <= 0)
                {
                    continue;
                }

                code[i] = FastEncoderStatics.BitReverse(nextCode[len], len);
                nextCode[len]++;
            }
            return(code);
        }