NetWrok.HTTP.Zlib.DeflateManager.SetDictionary C# (CSharp) Method

SetDictionary() private method

private SetDictionary ( ZlibCodec strm, byte dictionary ) : int
strm ZlibCodec
dictionary byte
return int
        internal int SetDictionary(ZlibCodec strm, byte[] dictionary)
        {
            int length = dictionary.Length;
            int index = 0;

            if (dictionary == null || status != INIT_STATE)
                throw new ZlibException ("Stream error.");

            strm._Adler32 = Adler.Adler32 (strm._Adler32, dictionary, 0, dictionary.Length);

            if (length < MIN_MATCH)
                return ZlibConstants.Z_OK;
            if (length > w_size - MIN_LOOKAHEAD) {
                length = w_size - MIN_LOOKAHEAD;
                index = dictionary.Length - 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 ZlibConstants.Z_OK;
        }