mirror of
https://github.com/facebook/zstd.git
synced 2024-12-18 12:40:09 +08:00
Add CCtx Param Controlling Dict Attachment Behavior
This commit is contained in:
parent
e30f13bde0
commit
01bb1c1016
@ -275,6 +275,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
|
||||
case ZSTD_p_ldmMinMatch:
|
||||
case ZSTD_p_ldmBucketSizeLog:
|
||||
case ZSTD_p_ldmHashEveryLog:
|
||||
case ZSTD_p_forceAttachDict:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -319,6 +320,9 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
||||
* default : 0 when using a CDict, 1 when using a Prefix */
|
||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||
|
||||
case ZSTD_p_forceAttachDict:
|
||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||
|
||||
case ZSTD_p_nbWorkers:
|
||||
if ((value>0) && cctx->staticSize) {
|
||||
return ERROR(parameter_unsupported); /* MT not compatible with static alloc */
|
||||
@ -424,6 +428,12 @@ size_t ZSTD_CCtxParam_setParameter(
|
||||
CCtxParams->forceWindow = (value > 0);
|
||||
return CCtxParams->forceWindow;
|
||||
|
||||
case ZSTD_p_forceAttachDict :
|
||||
CCtxParams->attachDictPref = value ?
|
||||
(value > 0 ? ZSTD_dictForceAttach : ZSTD_dictForceCopy) :
|
||||
ZSTD_dictDefaultAttach;
|
||||
return CCtxParams->attachDictPref;
|
||||
|
||||
case ZSTD_p_nbWorkers :
|
||||
#ifndef ZSTD_MULTITHREAD
|
||||
if (value>0) return ERROR(parameter_unsupported);
|
||||
@ -527,6 +537,9 @@ size_t ZSTD_CCtxParam_getParameter(
|
||||
case ZSTD_p_forceMaxWindow :
|
||||
*value = CCtxParams->forceWindow;
|
||||
break;
|
||||
case ZSTD_p_forceAttachDict :
|
||||
*value = CCtxParams->attachDictPref;
|
||||
break;
|
||||
case ZSTD_p_nbWorkers :
|
||||
#ifndef ZSTD_MULTITHREAD
|
||||
assert(CCtxParams->nbWorkers == 0);
|
||||
@ -1242,7 +1255,9 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
|
||||
256 KB /* ZSTD_btultra */
|
||||
};
|
||||
const int attachDict = ( pledgedSrcSize <= attachDictSizeCutoffs[cdict->cParams.strategy]
|
||||
|| pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN )
|
||||
|| pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN
|
||||
|| params.attachDictPref == ZSTD_dictForceAttach )
|
||||
&& params.attachDictPref != ZSTD_dictForceCopy
|
||||
&& !params.forceWindow /* dictMatchState isn't correctly
|
||||
* handled in _enforceMaxDist */
|
||||
&& cdict->cParams.strategy <= ZSTD_btlazy2
|
||||
|
@ -48,6 +48,12 @@ extern "C" {
|
||||
typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZSTD_compressionStage_e;
|
||||
typedef enum { zcss_init=0, zcss_load, zcss_flush } ZSTD_cStreamStage;
|
||||
|
||||
typedef enum {
|
||||
ZSTD_dictDefaultAttach = 0,
|
||||
ZSTD_dictForceAttach = 1,
|
||||
ZSTD_dictForceCopy = -1,
|
||||
} ZSTD_dictAttachPref_e;
|
||||
|
||||
typedef struct ZSTD_prefixDict_s {
|
||||
const void* dict;
|
||||
size_t dictSize;
|
||||
@ -186,6 +192,8 @@ struct ZSTD_CCtx_params_s {
|
||||
int forceWindow; /* force back-references to respect limit of
|
||||
* 1<<wLog, even for dictionary */
|
||||
|
||||
ZSTD_dictAttachPref_e attachDictPref;
|
||||
|
||||
/* Multithreading: used to pass parameters to mtctx */
|
||||
unsigned nbWorkers;
|
||||
unsigned jobSize;
|
||||
|
22
lib/zstd.h
22
lib/zstd.h
@ -1059,6 +1059,28 @@ typedef enum {
|
||||
|
||||
ZSTD_p_forceMaxWindow=1100, /* Force back-reference distances to remain < windowSize,
|
||||
* even when referencing into Dictionary content (default:0) */
|
||||
ZSTD_p_forceAttachDict, /* ZSTD supports usage of a CDict in-place
|
||||
* (avoiding having to copy the compression tables
|
||||
* from the CDict into the working context). Using
|
||||
* a CDict in this way saves an initial setup step,
|
||||
* but comes at the cost of more work per byte of
|
||||
* input. ZSTD has a simple internal heuristic that
|
||||
* guesses which strategy will be faster. You can
|
||||
* use this flag to override that guess.
|
||||
*
|
||||
* Note that the by-reference, in-place strategy is
|
||||
* only used when reusing a compression context
|
||||
* with compatible compression parameters. (If
|
||||
* incompatible / uninitialized, the working
|
||||
* context needs to be cleared anyways, which is
|
||||
* about as expensive as overwriting it with the
|
||||
* dictionary context, so there's no savings in
|
||||
* using the CDict by-ref.)
|
||||
*
|
||||
* Values greater than 0 force attaching the dict.
|
||||
* Values less than 0 force copying the dict.
|
||||
* 0 selects the default heuristic-guided behavior.
|
||||
*/
|
||||
|
||||
} ZSTD_cParameter;
|
||||
|
||||
|
@ -71,6 +71,7 @@ void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, uint32_t *state)
|
||||
setRand(cctx, ZSTD_p_contentSizeFlag, 0, 1, state);
|
||||
setRand(cctx, ZSTD_p_checksumFlag, 0, 1, state);
|
||||
setRand(cctx, ZSTD_p_dictIDFlag, 0, 1, state);
|
||||
setRand(cctx, ZSTD_p_forceAttachDict, -2, 2, state);
|
||||
/* Select long distance matchig parameters */
|
||||
setRand(cctx, ZSTD_p_enableLongDistanceMatching, 0, 1, state);
|
||||
setRand(cctx, ZSTD_p_ldmHashLog, ZSTD_HASHLOG_MIN, 16, state);
|
||||
|
Loading…
Reference in New Issue
Block a user