Fix ZSTD_adjustCParams_internal() to handle dictionary logic

Pass in the `ZSTD_cParamMode_e` to select how we define our cparams.
Based on the mode we either take the `dictSize` into account or we set
it to `0`. See the documentation for `ZSTD_cParamMode_e`.

Some of the modes currently share the same behavior. But they have
distinct modes because they are drastically different cases. E.g.
compression + reprocessing the dictionary and creating a cdict.

Additionally, when downsizing the hashLog and chainLog take the
(adjusted) dictionary size into account, since the size of the
dictionary gets added onto the window size.

Adds a simple test to ensure that we aren't downsizing too far.
This commit is contained in:
Nick Terrell
2020-10-12 12:50:04 -07:00
parent fadaab8c7c
commit d5c688e8ae
4 changed files with 155 additions and 41 deletions
+13
View File
@@ -372,6 +372,19 @@ static int basicUnitTests(U32 const seed, double compressibility)
DISPLAYLEVEL(3, "%u (OK) \n", vn);
}
DISPLAYLEVEL(3, "test%3u : ZSTD_adjustCParams : ", testNb++);
{
ZSTD_compressionParameters params;
memset(&params, 0, sizeof(params));
params.windowLog = 10;
params.hashLog = 19;
params.chainLog = 19;
params = ZSTD_adjustCParams(params, 1000, 100000);
if (params.hashLog != 18) goto _output_error;
if (params.chainLog != 17) goto _output_error;
}
DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3u : compress %u bytes : ", testNb++, (unsigned)CNBuffSize);
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
if (cctx==NULL) goto _output_error;