如何修改 zlib MIN_MATCH 值?

How can I modify zlib MIN_MATCH value?

我正在使用来自 http://zlib.net/
的 zlib 1.2.8 源代码 代码中,最小匹配值'MIN_MATCH'为'3'(在zutil.h)

现在我想将该值从 3 修改为 4,所以我修改了 zutil.h

并且deflate.c

中有一个代码
    /* Initialize the hash value now that we have some input: */
    if (s->lookahead + s->insert >= MIN_MATCH) {
        uInt str = s->strstart - s->insert;
        s->ins_h = s->window[str];
        UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
        Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
        while (s->insert) {
            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
            s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
            s->head[s->ins_h] = (Pos)str;
            str++;
            s->insert--;
            if (s->lookahead + s->insert < MIN_MATCH)
                break;
        }
    }

            s->strstart += s->match_length;
            s->match_length = 0;
            s->ins_h = s->window[s->strstart];
            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#if MIN_MATCH != 3
            Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
            /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
             * matter since it will be recomputed at next deflate call.
             */

所以我修改了下面的代码

    /* Initialize the hash value now that we have some input: */
    if (s->lookahead + s->insert >= MIN_MATCH) {
        uInt str = s->strstart - s->insert;
        s->ins_h = s->window[str];
        UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
        //Call UPDATE_HASH() MIN_MATCH-3 more times
        UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#endif
        while (s->insert) {
            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
            s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
            s->head[s->ins_h] = (Pos)str;
            str++;
            s->insert--;
            if (s->lookahead + s->insert < MIN_MATCH)
                break;
        }
    }

            s->strstart += s->match_length;
            s->match_length = 0;
            s->ins_h = s->window[s->strstart];
            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#if MIN_MATCH != 3
            //Call UPDATE_HASH() MIN_MATCH-3 more times
            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#endif
            /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
             * matter since it will be recomputed at next deflate call.
             */

(我把UPDATE_HASH()函数放在'if MIN_MATCH != 3'行下面)

然后我用 The Canterbury Corpus 基准文件 运行 编译 'minigzip' 测试程序

压缩工作没有错误,但解压缩不工作 'incorrect data check' 错误消息

我该如何修改代码? 有人知道吗?

谢谢

3 的 MIN_MATCH 已深入代码,因此关于重复更新的一条评论并不代表所有需要的更改。您必须阅读并理解所使用的算法,进行大量更改,然后对它们进行广泛测试以确保您做对了。

如果您要做的只是发出文字而不是匹配 3,那么您可以将 if (s->match_length >= MIN_MATCH) 更改为 if (s->match_length >= 4)