ComponentAce.Compression.Libs.ZLib.Deflate.deflateSetDictionary C# (CSharp) Method

deflateSetDictionary() private method

Sets deflate dictionary
private deflateSetDictionary ( ZStream strm, byte dictionary, int dictLength ) : int
strm ZStream
dictionary byte
dictLength int
return int
        internal int deflateSetDictionary(ZStream strm, byte[] dictionary, int dictLength)
        {
            int length = dictLength;
            int index = 0;

            if (dictionary == null || status != DeflateState.INIT_STATE)
                return (int)ZLibResultCode.Z_STREAM_ERROR;

            strm.adler = Adler32.GetAdler32Checksum(strm.adler, dictionary, 0, dictLength);

            if (length < MIN_MATCH)
                return (int)ZLibResultCode.Z_OK;
            if (length > w_size - MIN_LOOKAHEAD)
            {
                length = w_size - MIN_LOOKAHEAD;
                index = dictLength - length; // use the tail of the dictionary
            }
            Array.Copy(dictionary, index, window, 0, length);
            strstart = length;
            block_start = length;

            // Insert all strings in the hash table (except for the last two bytes).
            // s->lookahead stays null, so s->ins_h will be recomputed at the next
            // call of fill_window.

            ins_h = window[0] & 0xff;
            ins_h = (((ins_h) << hash_shift) ^ (window[1] & 0xff)) & hash_mask;

            for (int n = 0; n <= length - MIN_MATCH; n++)
            {
                ins_h = (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
                prev[n & w_mask] = head[ins_h];
                head[ins_h] = (short)n;
            }
            return (int)ZLibResultCode.Z_OK;
        }