Merge pull request #1550 from terrelln/cparams-cdict
[libzstd] Allow compression parameters to be set with a cdict
This commit is contained in:
@@ -450,11 +450,12 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
|
|
||||||
switch(param)
|
switch(param)
|
||||||
{
|
{
|
||||||
case ZSTD_c_compressionLevel:
|
case ZSTD_c_nbWorkers:
|
||||||
RETURN_ERROR_IF(cctx->cdict, stage_wrong,
|
RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported,
|
||||||
"compression level is configured in cdict");
|
"MT not compatible with static alloc");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ZSTD_c_compressionLevel:
|
||||||
case ZSTD_c_windowLog:
|
case ZSTD_c_windowLog:
|
||||||
case ZSTD_c_hashLog:
|
case ZSTD_c_hashLog:
|
||||||
case ZSTD_c_chainLog:
|
case ZSTD_c_chainLog:
|
||||||
@@ -462,20 +463,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
case ZSTD_c_minMatch:
|
case ZSTD_c_minMatch:
|
||||||
case ZSTD_c_targetLength:
|
case ZSTD_c_targetLength:
|
||||||
case ZSTD_c_strategy:
|
case ZSTD_c_strategy:
|
||||||
RETURN_ERROR_IF(cctx->cdict, stage_wrong,
|
|
||||||
"cparams are configured in cdict");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZSTD_c_nbWorkers:
|
|
||||||
RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported,
|
|
||||||
"MT not compatible with static alloc");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZSTD_c_ldmHashRateLog:
|
case ZSTD_c_ldmHashRateLog:
|
||||||
RETURN_ERROR_IF(cctx->cdict, stage_wrong,
|
|
||||||
"LDM hash rate log is configured in cdict");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZSTD_c_format:
|
case ZSTD_c_format:
|
||||||
case ZSTD_c_contentSizeFlag:
|
case ZSTD_c_contentSizeFlag:
|
||||||
case ZSTD_c_checksumFlag:
|
case ZSTD_c_checksumFlag:
|
||||||
|
|||||||
+7
-2
@@ -503,7 +503,10 @@ typedef enum { ZSTD_fast=1,
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
||||||
/* compression parameters */
|
/* compression parameters
|
||||||
|
* Note: When compressing with a ZSTD_CDict these parameters are superseded
|
||||||
|
* by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
|
||||||
|
* for more info (superseded-by-cdict). */
|
||||||
ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
|
ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
|
||||||
* Default level is ZSTD_CLEVEL_DEFAULT==3.
|
* Default level is ZSTD_CLEVEL_DEFAULT==3.
|
||||||
* Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
|
* Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
|
||||||
@@ -705,7 +708,9 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s
|
|||||||
/*! ZSTD_CCtx_refCDict() :
|
/*! ZSTD_CCtx_refCDict() :
|
||||||
* Reference a prepared dictionary, to be used for all next compressed frames.
|
* Reference a prepared dictionary, to be used for all next compressed frames.
|
||||||
* Note that compression parameters are enforced from within CDict,
|
* Note that compression parameters are enforced from within CDict,
|
||||||
* and supercede any compression parameter previously set within CCtx.
|
* and supersede any compression parameter previously set within CCtx.
|
||||||
|
* The parameters ignored are labled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
|
||||||
|
* The ignored parameters will be used again if the CCtx is returned to no-dictionary mode.
|
||||||
* The dictionary will remain valid for future compressed frames using same CCtx.
|
* The dictionary will remain valid for future compressed frames using same CCtx.
|
||||||
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
||||||
* Special : Referencing a NULL CDict means "return to no-dictionary mode".
|
* Special : Referencing a NULL CDict means "return to no-dictionary mode".
|
||||||
|
|||||||
@@ -1294,6 +1294,17 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3i : ZSTD_CCtx_refCDict() then set parameters : ", testNb++);
|
||||||
|
{ ZSTD_CDict* const cdict = ZSTD_createCDict(CNBuffer, dictSize, 1);
|
||||||
|
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 1) );
|
||||||
|
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 12 ));
|
||||||
|
CHECK_Z( ZSTD_CCtx_refCDict(cctx, cdict) );
|
||||||
|
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 1) );
|
||||||
|
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 12 ));
|
||||||
|
ZSTD_freeCDict(cdict);
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : Dictionary with non-default repcodes : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : Dictionary with non-default repcodes : ", testNb++);
|
||||||
{ U32 u; for (u=0; u<nbSamples; u++) samplesSizes[u] = sampleUnitSize; }
|
{ U32 u; for (u=0; u<nbSamples; u++) samplesSizes[u] = sampleUnitSize; }
|
||||||
dictSize = ZDICT_trainFromBuffer(dictBuffer, dictSize,
|
dictSize = ZDICT_trainFromBuffer(dictBuffer, dictSize,
|
||||||
|
|||||||
@@ -1930,16 +1930,6 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest,
|
|||||||
} else {
|
} else {
|
||||||
CHECK_Z( ZSTD_CCtx_loadDictionary_byReference(zc, dict, dictSize) );
|
CHECK_Z( ZSTD_CCtx_loadDictionary_byReference(zc, dict, dictSize) );
|
||||||
}
|
}
|
||||||
if (dict && dictSize) {
|
|
||||||
/* test that compression parameters are rejected (correctly) after loading a non-NULL dictionary */
|
|
||||||
if (opaqueAPI) {
|
|
||||||
size_t const setError = ZSTD_CCtx_setParametersUsingCCtxParams(zc, cctxParams);
|
|
||||||
CHECK(!ZSTD_isError(setError), "ZSTD_CCtx_setParametersUsingCCtxParams should have failed");
|
|
||||||
} else {
|
|
||||||
size_t const setError = ZSTD_CCtx_setParameter(zc, ZSTD_c_windowLog, cParams.windowLog-1);
|
|
||||||
CHECK(!ZSTD_isError(setError), "ZSTD_CCtx_setParameter should have failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CHECK_Z( ZSTD_CCtx_refPrefix(zc, dict, dictSize) );
|
CHECK_Z( ZSTD_CCtx_refPrefix(zc, dict, dictSize) );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user