Merge pull request #2337 from terrelln/adjust-params
Fix ZSTD_adjustCParams_internal() to handle dictionary logic
This commit is contained in:
commit
1e47a75abf
@ -64,6 +64,7 @@ size_t ZSTD_compressBound(size_t srcSize) {
|
|||||||
struct ZSTD_CDict_s {
|
struct ZSTD_CDict_s {
|
||||||
const void* dictContent;
|
const void* dictContent;
|
||||||
size_t dictContentSize;
|
size_t dictContentSize;
|
||||||
|
ZSTD_dictContentType_e dictContentType; /* The dictContentType the CDict was created with */
|
||||||
U32* entropyWorkspace; /* entropy workspace of HUF_WORKSPACE_SIZE bytes */
|
U32* entropyWorkspace; /* entropy workspace of HUF_WORKSPACE_SIZE bytes */
|
||||||
ZSTD_cwksp workspace;
|
ZSTD_cwksp workspace;
|
||||||
ZSTD_matchState_t matchState;
|
ZSTD_matchState_t matchState;
|
||||||
@ -877,7 +878,6 @@ ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long lo
|
|||||||
|
|
||||||
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(
|
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(
|
||||||
int const compressionLevel,
|
int const compressionLevel,
|
||||||
unsigned long long srcSizeHint,
|
|
||||||
size_t const dictSize);
|
size_t const dictSize);
|
||||||
static int ZSTD_dedicatedDictSearch_isSupported(
|
static int ZSTD_dedicatedDictSearch_isSupported(
|
||||||
const ZSTD_compressionParameters* cParams);
|
const ZSTD_compressionParameters* cParams);
|
||||||
@ -1063,24 +1063,73 @@ U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
|
|||||||
return hashLog - btScale;
|
return hashLog - btScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** ZSTD_dictAndWindowLog() :
|
||||||
|
* Returns an adjusted window log that is large enough to fit the source and the dictionary.
|
||||||
|
* The zstd format says that the entire dictionary is valid if one byte of the dictionary
|
||||||
|
* is within the window. So the hashLog and chainLog should be large enough to reference both
|
||||||
|
* the dictionary and the window. So we must use this adjusted dictAndWindowLog when downsizing
|
||||||
|
* the hashLog and windowLog.
|
||||||
|
* NOTE: srcSize must not be ZSTD_CONTENTSIZE_UNKNOWN.
|
||||||
|
*/
|
||||||
|
static U32 ZSTD_dictAndWindowLog(U32 windowLog, U64 srcSize, U64 dictSize)
|
||||||
|
{
|
||||||
|
const U64 maxWindowSize = 1ULL << ZSTD_WINDOWLOG_MAX;
|
||||||
|
/* No dictionary ==> No change */
|
||||||
|
if (dictSize == 0) {
|
||||||
|
return windowLog;
|
||||||
|
}
|
||||||
|
assert(windowLog <= ZSTD_WINDOWLOG_MAX);
|
||||||
|
assert(srcSize != ZSTD_CONTENTSIZE_UNKNOWN); /* Handled in ZSTD_adjustCParams_internal() */
|
||||||
|
{
|
||||||
|
U64 const windowSize = 1ULL << windowLog;
|
||||||
|
U64 const dictAndWindowSize = dictSize + windowSize;
|
||||||
|
/* If the window size is already large enough to fit both the source and the dictionary
|
||||||
|
* then just use the window size. Otherwise adjust so that it fits the dictionary and
|
||||||
|
* the window.
|
||||||
|
*/
|
||||||
|
if (windowSize >= dictSize + srcSize) {
|
||||||
|
return windowLog; /* Window size large enough already */
|
||||||
|
} else if (dictAndWindowSize >= maxWindowSize) {
|
||||||
|
return ZSTD_WINDOWLOG_MAX; /* Larger than max window log */
|
||||||
|
} else {
|
||||||
|
return ZSTD_highbit32((U32)dictAndWindowSize - 1) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** ZSTD_adjustCParams_internal() :
|
/** ZSTD_adjustCParams_internal() :
|
||||||
* optimize `cPar` for a specified input (`srcSize` and `dictSize`).
|
* optimize `cPar` for a specified input (`srcSize` and `dictSize`).
|
||||||
* mostly downsize to reduce memory consumption and initialization latency.
|
* mostly downsize to reduce memory consumption and initialization latency.
|
||||||
* `srcSize` can be ZSTD_CONTENTSIZE_UNKNOWN when not known.
|
* `srcSize` can be ZSTD_CONTENTSIZE_UNKNOWN when not known.
|
||||||
|
* `mode` is the mode for parameter adjustment. See docs for `ZSTD_cParamMode_e`.
|
||||||
* note : `srcSize==0` means 0!
|
* note : `srcSize==0` means 0!
|
||||||
* condition : cPar is presumed validated (can be checked using ZSTD_checkCParams()). */
|
* condition : cPar is presumed validated (can be checked using ZSTD_checkCParams()). */
|
||||||
static ZSTD_compressionParameters
|
static ZSTD_compressionParameters
|
||||||
ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
|
ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
|
||||||
unsigned long long srcSize,
|
unsigned long long srcSize,
|
||||||
size_t dictSize)
|
size_t dictSize,
|
||||||
|
ZSTD_cParamMode_e mode)
|
||||||
{
|
{
|
||||||
static const U64 minSrcSize = 513; /* (1<<9) + 1 */
|
const U64 minSrcSize = 513; /* (1<<9) + 1 */
|
||||||
static const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
|
const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
|
||||||
assert(ZSTD_checkCParams(cPar)==0);
|
assert(ZSTD_checkCParams(cPar)==0);
|
||||||
|
|
||||||
if (dictSize && srcSize == ZSTD_CONTENTSIZE_UNKNOWN)
|
if (dictSize && srcSize == ZSTD_CONTENTSIZE_UNKNOWN)
|
||||||
srcSize = minSrcSize;
|
srcSize = minSrcSize;
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case ZSTD_cpm_noAttachDict:
|
||||||
|
case ZSTD_cpm_unknown:
|
||||||
|
case ZSTD_cpm_createCDict:
|
||||||
|
break;
|
||||||
|
case ZSTD_cpm_attachDict:
|
||||||
|
dictSize = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* resize windowLog if input is small enough, to use less memory */
|
/* resize windowLog if input is small enough, to use less memory */
|
||||||
if ( (srcSize < maxWindowResize)
|
if ( (srcSize < maxWindowResize)
|
||||||
&& (dictSize < maxWindowResize) ) {
|
&& (dictSize < maxWindowResize) ) {
|
||||||
@ -1090,10 +1139,11 @@ ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
|
|||||||
ZSTD_highbit32(tSize-1) + 1;
|
ZSTD_highbit32(tSize-1) + 1;
|
||||||
if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
|
if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
|
||||||
}
|
}
|
||||||
if (cPar.hashLog > cPar.windowLog+1) cPar.hashLog = cPar.windowLog+1;
|
{ U32 const dictAndWindowLog = ZSTD_dictAndWindowLog(cPar.windowLog, (U64)srcSize, (U64)dictSize);
|
||||||
{ U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy);
|
U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy);
|
||||||
if (cycleLog > cPar.windowLog)
|
if (cPar.hashLog > dictAndWindowLog+1) cPar.hashLog = dictAndWindowLog+1;
|
||||||
cPar.chainLog -= (cycleLog - cPar.windowLog);
|
if (cycleLog > dictAndWindowLog)
|
||||||
|
cPar.chainLog -= (cycleLog - dictAndWindowLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN)
|
if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN)
|
||||||
@ -1109,11 +1159,11 @@ ZSTD_adjustCParams(ZSTD_compressionParameters cPar,
|
|||||||
{
|
{
|
||||||
cPar = ZSTD_clampCParams(cPar); /* resulting cPar is necessarily valid (all parameters within range) */
|
cPar = ZSTD_clampCParams(cPar); /* resulting cPar is necessarily valid (all parameters within range) */
|
||||||
if (srcSize == 0) srcSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
if (srcSize == 0) srcSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize);
|
return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize, ZSTD_cpm_unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize);
|
static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode);
|
||||||
static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize);
|
static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode);
|
||||||
|
|
||||||
static void ZSTD_overrideCParams(
|
static void ZSTD_overrideCParams(
|
||||||
ZSTD_compressionParameters* cParams,
|
ZSTD_compressionParameters* cParams,
|
||||||
@ -1129,18 +1179,18 @@ static void ZSTD_overrideCParams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
||||||
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize)
|
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters cParams;
|
ZSTD_compressionParameters cParams;
|
||||||
if (srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN && CCtxParams->srcSizeHint > 0) {
|
if (srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN && CCtxParams->srcSizeHint > 0) {
|
||||||
srcSizeHint = CCtxParams->srcSizeHint;
|
srcSizeHint = CCtxParams->srcSizeHint;
|
||||||
}
|
}
|
||||||
cParams = ZSTD_getCParams_internal(CCtxParams->compressionLevel, srcSizeHint, dictSize);
|
cParams = ZSTD_getCParams_internal(CCtxParams->compressionLevel, srcSizeHint, dictSize, mode);
|
||||||
if (CCtxParams->ldmParams.enableLdm) cParams.windowLog = ZSTD_LDM_DEFAULT_WINDOW_LOG;
|
if (CCtxParams->ldmParams.enableLdm) cParams.windowLog = ZSTD_LDM_DEFAULT_WINDOW_LOG;
|
||||||
ZSTD_overrideCParams(&cParams, &CCtxParams->cParams);
|
ZSTD_overrideCParams(&cParams, &CCtxParams->cParams);
|
||||||
assert(!ZSTD_checkCParams(cParams));
|
assert(!ZSTD_checkCParams(cParams));
|
||||||
/* srcSizeHint == 0 means 0 */
|
/* srcSizeHint == 0 means 0 */
|
||||||
return ZSTD_adjustCParams_internal(cParams, srcSizeHint, dictSize);
|
return ZSTD_adjustCParams_internal(cParams, srcSizeHint, dictSize, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
@ -1218,7 +1268,7 @@ static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal(
|
|||||||
size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters const cParams =
|
ZSTD_compressionParameters const cParams =
|
||||||
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
|
||||||
|
|
||||||
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
||||||
/* estimateCCtxSize is for one-shot compression. So no buffers should
|
/* estimateCCtxSize is for one-shot compression. So no buffers should
|
||||||
@ -1236,7 +1286,7 @@ size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams)
|
|||||||
|
|
||||||
static size_t ZSTD_estimateCCtxSize_internal(int compressionLevel)
|
static size_t ZSTD_estimateCCtxSize_internal(int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
|
||||||
return ZSTD_estimateCCtxSize_usingCParams(cParams);
|
return ZSTD_estimateCCtxSize_usingCParams(cParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1255,7 +1305,7 @@ size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
|||||||
{
|
{
|
||||||
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
||||||
{ ZSTD_compressionParameters const cParams =
|
{ ZSTD_compressionParameters const cParams =
|
||||||
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
|
||||||
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
||||||
size_t const inBuffSize = ((size_t)1 << cParams.windowLog) + blockSize;
|
size_t const inBuffSize = ((size_t)1 << cParams.windowLog) + blockSize;
|
||||||
size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1;
|
size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1;
|
||||||
@ -1274,7 +1324,7 @@ size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams)
|
|||||||
|
|
||||||
static size_t ZSTD_estimateCStreamSize_internal(int compressionLevel)
|
static size_t ZSTD_estimateCStreamSize_internal(int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
|
||||||
return ZSTD_estimateCStreamSize_usingCParams(cParams);
|
return ZSTD_estimateCStreamSize_usingCParams(cParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1699,7 +1749,8 @@ ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx,
|
|||||||
ZSTD_dedicatedDictSearch_revertCParams(&adjusted_cdict_cParams);
|
ZSTD_dedicatedDictSearch_revertCParams(&adjusted_cdict_cParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
params.cParams = ZSTD_adjustCParams_internal(adjusted_cdict_cParams, pledgedSrcSize, 0);
|
params.cParams = ZSTD_adjustCParams_internal(adjusted_cdict_cParams, pledgedSrcSize,
|
||||||
|
cdict->dictContentSize, ZSTD_cpm_attachDict);
|
||||||
params.cParams.windowLog = windowLog;
|
params.cParams.windowLog = windowLog;
|
||||||
FORWARD_IF_ERROR(ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
|
FORWARD_IF_ERROR(ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
|
||||||
ZSTDcrp_makeClean, zbuff), "");
|
ZSTDcrp_makeClean, zbuff), "");
|
||||||
@ -3188,7 +3239,7 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
|
|||||||
ZSTD_compress_insertDictionary(
|
ZSTD_compress_insertDictionary(
|
||||||
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
||||||
&cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent,
|
&cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent,
|
||||||
cdict->dictContentSize, dictContentType, dtlm,
|
cdict->dictContentSize, cdict->dictContentType, dtlm,
|
||||||
cctx->entropyWorkspace)
|
cctx->entropyWorkspace)
|
||||||
: ZSTD_compress_insertDictionary(
|
: ZSTD_compress_insertDictionary(
|
||||||
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
||||||
@ -3235,7 +3286,7 @@ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx,
|
|||||||
|
|
||||||
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel)
|
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_parameters const params = ZSTD_getParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
ZSTD_parameters const params = ZSTD_getParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_noAttachDict);
|
||||||
ZSTD_CCtx_params const cctxParams =
|
ZSTD_CCtx_params const cctxParams =
|
||||||
ZSTD_assignParamsToCCtxParams(&cctx->requestedParams, ¶ms);
|
ZSTD_assignParamsToCCtxParams(&cctx->requestedParams, ¶ms);
|
||||||
DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (unsigned)dictSize);
|
DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (unsigned)dictSize);
|
||||||
@ -3369,7 +3420,7 @@ size_t ZSTD_compress_usingDict(ZSTD_CCtx* cctx,
|
|||||||
const void* dict, size_t dictSize,
|
const void* dict, size_t dictSize,
|
||||||
int compressionLevel)
|
int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_parameters const params = ZSTD_getParams_internal(compressionLevel, srcSize, dict ? dictSize : 0);
|
ZSTD_parameters const params = ZSTD_getParams_internal(compressionLevel, srcSize, dict ? dictSize : 0, ZSTD_cpm_noAttachDict);
|
||||||
ZSTD_CCtx_params cctxParams = ZSTD_assignParamsToCCtxParams(&cctx->requestedParams, ¶ms);
|
ZSTD_CCtx_params cctxParams = ZSTD_assignParamsToCCtxParams(&cctx->requestedParams, ¶ms);
|
||||||
DEBUGLOG(4, "ZSTD_compress_usingDict (srcSize=%u)", (unsigned)srcSize);
|
DEBUGLOG(4, "ZSTD_compress_usingDict (srcSize=%u)", (unsigned)srcSize);
|
||||||
assert(params.fParams.contentSizeFlag == 1);
|
assert(params.fParams.contentSizeFlag == 1);
|
||||||
@ -3424,7 +3475,7 @@ size_t ZSTD_estimateCDictSize_advanced(
|
|||||||
|
|
||||||
size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
|
size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict);
|
||||||
return ZSTD_estimateCDictSize_advanced(dictSize, cParams, ZSTD_dlm_byCopy);
|
return ZSTD_estimateCDictSize_advanced(dictSize, cParams, ZSTD_dlm_byCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3460,6 +3511,7 @@ static size_t ZSTD_initCDict_internal(
|
|||||||
ZSTD_memcpy(internalBuffer, dictBuffer, dictSize);
|
ZSTD_memcpy(internalBuffer, dictBuffer, dictSize);
|
||||||
}
|
}
|
||||||
cdict->dictContentSize = dictSize;
|
cdict->dictContentSize = dictSize;
|
||||||
|
cdict->dictContentType = dictContentType;
|
||||||
|
|
||||||
cdict->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE);
|
cdict->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE);
|
||||||
|
|
||||||
@ -3557,18 +3609,18 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2(
|
|||||||
|
|
||||||
if (cctxParams.enableDedicatedDictSearch) {
|
if (cctxParams.enableDedicatedDictSearch) {
|
||||||
cParams = ZSTD_dedicatedDictSearch_getCParams(
|
cParams = ZSTD_dedicatedDictSearch_getCParams(
|
||||||
cctxParams.compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
cctxParams.compressionLevel, dictSize);
|
||||||
ZSTD_overrideCParams(&cParams, &cctxParams.cParams);
|
ZSTD_overrideCParams(&cParams, &cctxParams.cParams);
|
||||||
} else {
|
} else {
|
||||||
cParams = ZSTD_getCParamsFromCCtxParams(
|
cParams = ZSTD_getCParamsFromCCtxParams(
|
||||||
&cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
&cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ZSTD_dedicatedDictSearch_isSupported(&cParams)) {
|
if (!ZSTD_dedicatedDictSearch_isSupported(&cParams)) {
|
||||||
/* Fall back to non-DDSS params */
|
/* Fall back to non-DDSS params */
|
||||||
cctxParams.enableDedicatedDictSearch = 0;
|
cctxParams.enableDedicatedDictSearch = 0;
|
||||||
cParams = ZSTD_getCParamsFromCCtxParams(
|
cParams = ZSTD_getCParamsFromCCtxParams(
|
||||||
&cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
&cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
cctxParams.cParams = cParams;
|
cctxParams.cParams = cParams;
|
||||||
@ -3590,7 +3642,7 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2(
|
|||||||
|
|
||||||
ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel)
|
ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict);
|
||||||
ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
|
ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
|
||||||
ZSTD_dlm_byCopy, ZSTD_dct_auto,
|
ZSTD_dlm_byCopy, ZSTD_dct_auto,
|
||||||
cParams, ZSTD_defaultCMem);
|
cParams, ZSTD_defaultCMem);
|
||||||
@ -3601,7 +3653,7 @@ ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionL
|
|||||||
|
|
||||||
ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel)
|
ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict);
|
||||||
ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
|
ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
|
||||||
ZSTD_dlm_byRef, ZSTD_dct_auto,
|
ZSTD_dlm_byRef, ZSTD_dct_auto,
|
||||||
cParams, ZSTD_defaultCMem);
|
cParams, ZSTD_defaultCMem);
|
||||||
@ -3791,32 +3843,12 @@ size_t ZSTD_CStreamOutSize(void)
|
|||||||
return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ;
|
return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t ZSTD_resetCStream_internal(ZSTD_CStream* cctx,
|
static ZSTD_cParamMode_e ZSTD_getCParamMode(ZSTD_CDict const* cdict, ZSTD_CCtx_params const* params, U64 pledgedSrcSize)
|
||||||
const void* const dict, size_t const dictSize, ZSTD_dictContentType_e const dictContentType,
|
|
||||||
const ZSTD_CDict* const cdict,
|
|
||||||
ZSTD_CCtx_params params, unsigned long long const pledgedSrcSize)
|
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_resetCStream_internal");
|
if (cdict != NULL && ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize))
|
||||||
/* Finalize the compression parameters */
|
return ZSTD_cpm_attachDict;
|
||||||
params.cParams = ZSTD_getCParamsFromCCtxParams(¶ms, pledgedSrcSize, dictSize);
|
else
|
||||||
/* params are supposed to be fully validated at this point */
|
return ZSTD_cpm_noAttachDict;
|
||||||
assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
|
|
||||||
assert(!((dict) && (cdict))); /* either dict or cdict, not both */
|
|
||||||
|
|
||||||
FORWARD_IF_ERROR( ZSTD_compressBegin_internal(cctx,
|
|
||||||
dict, dictSize, dictContentType, ZSTD_dtlm_fast,
|
|
||||||
cdict,
|
|
||||||
¶ms, pledgedSrcSize,
|
|
||||||
ZSTDb_buffered) , "");
|
|
||||||
|
|
||||||
cctx->inToCompress = 0;
|
|
||||||
cctx->inBuffPos = 0;
|
|
||||||
cctx->inBuffTarget = cctx->blockSize
|
|
||||||
+ (cctx->blockSize == pledgedSrcSize); /* for small input: avoid automatic flush on reaching end of block, since it would require to add a 3-bytes null block to end frame */
|
|
||||||
cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0;
|
|
||||||
cctx->streamStage = zcss_load;
|
|
||||||
cctx->frameEnded = 0;
|
|
||||||
return 0; /* ready to go */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ZSTD_resetCStream():
|
/* ZSTD_resetCStream():
|
||||||
@ -4135,7 +4167,15 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of compression level */
|
params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of compression level */
|
||||||
DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
|
DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
|
||||||
if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
|
if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
|
||||||
params.cParams = ZSTD_getCParamsFromCCtxParams(¶ms, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/);
|
{
|
||||||
|
size_t const dictSize = prefixDict.dict
|
||||||
|
? prefixDict.dictSize
|
||||||
|
: (cctx->cdict ? cctx->cdict->dictContentSize : 0);
|
||||||
|
ZSTD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, ¶ms, cctx->pledgedSrcSizePlusOne - 1);
|
||||||
|
params.cParams = ZSTD_getCParamsFromCCtxParams(
|
||||||
|
¶ms, cctx->pledgedSrcSizePlusOne-1,
|
||||||
|
dictSize, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ZSTD_MULTITHREAD
|
#ifdef ZSTD_MULTITHREAD
|
||||||
@ -4160,12 +4200,21 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
cctx->appliedParams.nbWorkers = params.nbWorkers;
|
cctx->appliedParams.nbWorkers = params.nbWorkers;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{ FORWARD_IF_ERROR( ZSTD_resetCStream_internal(cctx,
|
{ U64 const pledgedSrcSize = cctx->pledgedSrcSizePlusOne - 1;
|
||||||
prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
|
assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
|
||||||
cctx->cdict,
|
FORWARD_IF_ERROR( ZSTD_compressBegin_internal(cctx,
|
||||||
params, cctx->pledgedSrcSizePlusOne-1) , "");
|
prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType, ZSTD_dtlm_fast,
|
||||||
assert(cctx->streamStage == zcss_load);
|
cctx->cdict,
|
||||||
|
¶ms, pledgedSrcSize,
|
||||||
|
ZSTDb_buffered) , "");
|
||||||
assert(cctx->appliedParams.nbWorkers == 0);
|
assert(cctx->appliedParams.nbWorkers == 0);
|
||||||
|
cctx->inToCompress = 0;
|
||||||
|
cctx->inBuffPos = 0;
|
||||||
|
/* for small input: avoid automatic flush on reaching end of block, since it would require to add a 3-bytes null block to end frame */
|
||||||
|
cctx->inBuffTarget = cctx->blockSize + (cctx->blockSize == pledgedSrcSize);
|
||||||
|
cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0;
|
||||||
|
cctx->streamStage = zcss_load;
|
||||||
|
cctx->frameEnded = 0;
|
||||||
} }
|
} }
|
||||||
/* end of transparent initialization stage */
|
/* end of transparent initialization stage */
|
||||||
|
|
||||||
@ -4377,9 +4426,9 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(int const compressionLevel, unsigned long long srcSizeHint, size_t const dictSize)
|
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(int const compressionLevel, size_t const dictSize)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize);
|
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, 0, dictSize, ZSTD_cpm_createCDict);
|
||||||
switch (cParams.strategy) {
|
switch (cParams.strategy) {
|
||||||
case ZSTD_fast:
|
case ZSTD_fast:
|
||||||
case ZSTD_dfast:
|
case ZSTD_dfast:
|
||||||
@ -4428,15 +4477,34 @@ static void ZSTD_dedicatedDictSearch_revertCParams(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static U64 ZSTD_getCParamRowSize(U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode)
|
||||||
|
{
|
||||||
|
switch (mode) {
|
||||||
|
case ZSTD_cpm_unknown:
|
||||||
|
case ZSTD_cpm_noAttachDict:
|
||||||
|
case ZSTD_cpm_createCDict:
|
||||||
|
break;
|
||||||
|
case ZSTD_cpm_attachDict:
|
||||||
|
dictSize = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
{ int const unknown = srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
|
size_t const addedSize = unknown && dictSize > 0 ? 500 : 0;
|
||||||
|
return unknown && dictSize == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : srcSizeHint+dictSize+addedSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*! ZSTD_getCParams_internal() :
|
/*! ZSTD_getCParams_internal() :
|
||||||
* @return ZSTD_compressionParameters structure for a selected compression level, srcSize and dictSize.
|
* @return ZSTD_compressionParameters structure for a selected compression level, srcSize and dictSize.
|
||||||
* Note: srcSizeHint 0 means 0, use ZSTD_CONTENTSIZE_UNKNOWN for unknown.
|
* Note: srcSizeHint 0 means 0, use ZSTD_CONTENTSIZE_UNKNOWN for unknown.
|
||||||
* Use dictSize == 0 for unknown or unused. */
|
* Use dictSize == 0 for unknown or unused.
|
||||||
static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
|
* Note: `mode` controls how we treat the `dictSize`. See docs for `ZSTD_cParamMode_e`. */
|
||||||
|
static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode)
|
||||||
{
|
{
|
||||||
int const unknown = srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN;
|
U64 const rSize = ZSTD_getCParamRowSize(srcSizeHint, dictSize, mode);
|
||||||
size_t const addedSize = unknown && dictSize > 0 ? 500 : 0;
|
|
||||||
U64 const rSize = unknown && dictSize == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : srcSizeHint+dictSize+addedSize;
|
|
||||||
U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB);
|
U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB);
|
||||||
int row = compressionLevel;
|
int row = compressionLevel;
|
||||||
DEBUGLOG(5, "ZSTD_getCParams_internal (cLevel=%i)", compressionLevel);
|
DEBUGLOG(5, "ZSTD_getCParams_internal (cLevel=%i)", compressionLevel);
|
||||||
@ -4446,7 +4514,7 @@ static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel,
|
|||||||
{ ZSTD_compressionParameters cp = ZSTD_defaultCParameters[tableID][row];
|
{ ZSTD_compressionParameters cp = ZSTD_defaultCParameters[tableID][row];
|
||||||
if (compressionLevel < 0) cp.targetLength = (unsigned)(-compressionLevel); /* acceleration factor */
|
if (compressionLevel < 0) cp.targetLength = (unsigned)(-compressionLevel); /* acceleration factor */
|
||||||
/* refine parameters based on srcSize & dictSize */
|
/* refine parameters based on srcSize & dictSize */
|
||||||
return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize);
|
return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4456,16 +4524,16 @@ static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel,
|
|||||||
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
|
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
|
||||||
{
|
{
|
||||||
if (srcSizeHint == 0) srcSizeHint = ZSTD_CONTENTSIZE_UNKNOWN;
|
if (srcSizeHint == 0) srcSizeHint = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
return ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize);
|
return ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize, ZSTD_cpm_unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ZSTD_getParams() :
|
/*! ZSTD_getParams() :
|
||||||
* same idea as ZSTD_getCParams()
|
* same idea as ZSTD_getCParams()
|
||||||
* @return a `ZSTD_parameters` structure (instead of `ZSTD_compressionParameters`).
|
* @return a `ZSTD_parameters` structure (instead of `ZSTD_compressionParameters`).
|
||||||
* Fields of `ZSTD_frameParameters` are set to default values */
|
* Fields of `ZSTD_frameParameters` are set to default values */
|
||||||
static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) {
|
static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode) {
|
||||||
ZSTD_parameters params;
|
ZSTD_parameters params;
|
||||||
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize);
|
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize, mode);
|
||||||
DEBUGLOG(5, "ZSTD_getParams (cLevel=%i)", compressionLevel);
|
DEBUGLOG(5, "ZSTD_getParams (cLevel=%i)", compressionLevel);
|
||||||
ZSTD_memset(¶ms, 0, sizeof(params));
|
ZSTD_memset(¶ms, 0, sizeof(params));
|
||||||
params.cParams = cParams;
|
params.cParams = cParams;
|
||||||
@ -4479,5 +4547,5 @@ static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned lo
|
|||||||
* Fields of `ZSTD_frameParameters` are set to default values */
|
* Fields of `ZSTD_frameParameters` are set to default values */
|
||||||
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) {
|
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) {
|
||||||
if (srcSizeHint == 0) srcSizeHint = ZSTD_CONTENTSIZE_UNKNOWN;
|
if (srcSizeHint == 0) srcSizeHint = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
return ZSTD_getParams_internal(compressionLevel, srcSizeHint, dictSize);
|
return ZSTD_getParams_internal(compressionLevel, srcSizeHint, dictSize, ZSTD_cpm_unknown);
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,25 @@ typedef enum {
|
|||||||
ZSTD_dedicatedDictSearch = 3
|
ZSTD_dedicatedDictSearch = 3
|
||||||
} ZSTD_dictMode_e;
|
} ZSTD_dictMode_e;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_cpm_noAttachDict = 0, /* Compression with ZSTD_noDict or ZSTD_extDict.
|
||||||
|
* In this mode we use both the srcSize and the dictSize
|
||||||
|
* when selecting and adjusting parameters.
|
||||||
|
*/
|
||||||
|
ZSTD_cpm_attachDict = 1, /* Compression with ZSTD_dictMatchState or ZSTD_dedicatedDictSearch.
|
||||||
|
* In this mode we only take the srcSize into account when selecting
|
||||||
|
* and adjusting parameters.
|
||||||
|
*/
|
||||||
|
ZSTD_cpm_createCDict = 2, /* Creating a CDict.
|
||||||
|
* In this mode we take both the source size and the dictionary size
|
||||||
|
* into account when selecting and adjusting the parameters.
|
||||||
|
*/
|
||||||
|
ZSTD_cpm_unknown = 3, /* ZSTD_getCParams, ZSTD_getParams, ZSTD_adjustParams.
|
||||||
|
* We don't know what these parameters are for. We default to the legacy
|
||||||
|
* behavior of taking both the source size and the dict size into account
|
||||||
|
* when selecting and adjusting parameters.
|
||||||
|
*/
|
||||||
|
} ZSTD_cParamMode_e;
|
||||||
|
|
||||||
typedef size_t (*ZSTD_blockCompressor) (
|
typedef size_t (*ZSTD_blockCompressor) (
|
||||||
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
@ -1090,7 +1109,7 @@ void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
|||||||
* Note: srcSizeHint == 0 means 0!
|
* Note: srcSizeHint == 0 means 0!
|
||||||
*/
|
*/
|
||||||
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
||||||
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize);
|
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode);
|
||||||
|
|
||||||
/*! ZSTD_initCStream_internal() :
|
/*! ZSTD_initCStream_internal() :
|
||||||
* Private use only. Init streaming operation.
|
* Private use only. Init streaming operation.
|
||||||
|
@ -1107,7 +1107,7 @@ void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_p
|
|||||||
DEBUGLOG(5, "ZSTDMT_updateCParams_whileCompressing (level:%i)",
|
DEBUGLOG(5, "ZSTDMT_updateCParams_whileCompressing (level:%i)",
|
||||||
compressionLevel);
|
compressionLevel);
|
||||||
mtctx->params.compressionLevel = compressionLevel;
|
mtctx->params.compressionLevel = compressionLevel;
|
||||||
{ ZSTD_compressionParameters cParams = ZSTD_getCParamsFromCCtxParams(cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, 0);
|
{ ZSTD_compressionParameters cParams = ZSTD_getCParamsFromCCtxParams(cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
|
||||||
cParams.windowLog = saved_wlog;
|
cParams.windowLog = saved_wlog;
|
||||||
mtctx->params.cParams = cParams;
|
mtctx->params.cParams = cParams;
|
||||||
}
|
}
|
||||||
|
@ -372,6 +372,19 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
DISPLAYLEVEL(3, "%u (OK) \n", vn);
|
DISPLAYLEVEL(3, "%u (OK) \n", vn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3u : ZSTD_adjustCParams : ", testNb++);
|
||||||
|
{
|
||||||
|
ZSTD_compressionParameters params;
|
||||||
|
memset(¶ms, 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);
|
DISPLAYLEVEL(3, "test%3u : compress %u bytes : ", testNb++, (unsigned)CNBuffSize);
|
||||||
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||||
if (cctx==NULL) goto _output_error;
|
if (cctx==NULL) goto _output_error;
|
||||||
@ -1971,34 +1984,53 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : Loading rawContent starting with dict header w/ ZSTD_dct_auto should fail : ", testNb++);
|
{ char* rawDictBuffer = (char*)malloc(dictSize);
|
||||||
{
|
assert(rawDictBuffer);
|
||||||
size_t ret;
|
memcpy(rawDictBuffer, (char*)dictBuffer + 2, dictSize - 2);
|
||||||
MEM_writeLE32((char*)dictBuffer+2, ZSTD_MAGIC_DICTIONARY);
|
memset(rawDictBuffer + dictSize - 2, 0, 2);
|
||||||
/* Either operation is allowed to fail, but one must fail. */
|
MEM_writeLE32((char*)rawDictBuffer, ZSTD_MAGIC_DICTIONARY);
|
||||||
ret = ZSTD_CCtx_loadDictionary_advanced(
|
|
||||||
cctx, (const char*)dictBuffer+2, dictSize-2, ZSTD_dlm_byRef, ZSTD_dct_auto);
|
|
||||||
if (!ZSTD_isError(ret)) {
|
|
||||||
ret = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, MIN(CNBuffSize, 100));
|
|
||||||
if (!ZSTD_isError(ret)) goto _output_error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : Loading rawContent starting with dict header w/ ZSTD_dct_rawContent should pass : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : Loading rawContent starting with dict header w/ ZSTD_dct_auto should fail : ", testNb++);
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
MEM_writeLE32((char*)dictBuffer+2, ZSTD_MAGIC_DICTIONARY);
|
/* Either operation is allowed to fail, but one must fail. */
|
||||||
ret = ZSTD_CCtx_loadDictionary_advanced(
|
ret = ZSTD_CCtx_loadDictionary_advanced(
|
||||||
cctx, (const char*)dictBuffer+2, dictSize-2, ZSTD_dlm_byRef, ZSTD_dct_rawContent);
|
cctx, (const char*)rawDictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto);
|
||||||
if (ZSTD_isError(ret)) goto _output_error;
|
if (!ZSTD_isError(ret)) {
|
||||||
ret = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, MIN(CNBuffSize, 100));
|
ret = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, MIN(CNBuffSize, 100));
|
||||||
if (ZSTD_isError(ret)) goto _output_error;
|
if (!ZSTD_isError(ret)) goto _output_error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3i : Loading rawContent starting with dict header w/ ZSTD_dct_rawContent should pass : ", testNb++);
|
||||||
|
{
|
||||||
|
size_t ret;
|
||||||
|
ret = ZSTD_CCtx_loadDictionary_advanced(
|
||||||
|
cctx, (const char*)rawDictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_rawContent);
|
||||||
|
if (ZSTD_isError(ret)) goto _output_error;
|
||||||
|
ret = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, MIN(CNBuffSize, 100));
|
||||||
|
if (ZSTD_isError(ret)) goto _output_error;
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3i : Testing non-attached CDict with ZSTD_dct_rawContent : ", testNb++);
|
||||||
|
{ size_t const srcSize = MIN(CNBuffSize, 100);
|
||||||
|
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters);
|
||||||
|
/* Force the dictionary to be reloaded in raw content mode */
|
||||||
|
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_forceAttachDict, ZSTD_dictForceLoad));
|
||||||
|
CHECK_Z(ZSTD_CCtx_loadDictionary_advanced(cctx, rawDictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_rawContent));
|
||||||
|
cSize = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, srcSize);
|
||||||
|
CHECK_Z(cSize);
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
free(rawDictBuffer);
|
||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : ZSTD_CCtx_refCDict() then set parameters : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : ZSTD_CCtx_refCDict() then set parameters : ", testNb++);
|
||||||
{ ZSTD_CDict* const cdict = ZSTD_createCDict(CNBuffer, dictSize, 1);
|
{ ZSTD_CDict* const cdict = ZSTD_createCDict(CNBuffer, dictSize, 1);
|
||||||
|
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters);
|
||||||
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 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_setParameter(cctx, ZSTD_c_hashLog, 12 ));
|
||||||
CHECK_Z( ZSTD_CCtx_refCDict(cctx, cdict) );
|
CHECK_Z( ZSTD_CCtx_refCDict(cctx, cdict) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user