changed ZSTD_c_compressionStrategy into ZSTD_c_strategy

also : fixed paramgrill, and limit conditions
This commit is contained in:
Yann Collet
2018-12-06 15:00:52 -08:00
parent e9448cdf4c
commit be9e561da4
12 changed files with 78 additions and 67 deletions
+23 -28
View File
@@ -267,7 +267,7 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
bounds.upperBound = ZSTD_TARGETLENGTH_MAX;
return bounds;
case ZSTD_c_compressionStrategy:
case ZSTD_c_strategy:
bounds.lowerBound = (int)ZSTD_fast;
bounds.upperBound = (int)ZSTD_btultra2; /* note : how to ensure at compile time that this is the highest value strategy ? */
return bounds;
@@ -349,12 +349,13 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
case ZSTD_c_format:
ZSTD_STATIC_ASSERT((int)ZSTD_f_zstd1 < (int)ZSTD_f_zstd1_magicless);
bounds.lowerBound = (int)ZSTD_f_zstd1;
bounds.upperBound = (int)ZSTD_f_zstd1_magicless;
bounds.upperBound = (int)ZSTD_f_zstd1_magicless; /* note : how to ensure at compile time that this is the highest value enum ? */
return bounds;
case ZSTD_c_forceAttachDict:
bounds.lowerBound = 0;
bounds.upperBound = 1;
ZSTD_STATIC_ASSERT((int)ZSTD_dictDefaultAttach < (int)ZSTD_dictForceCopy);
bounds.lowerBound = ZSTD_dictDefaultAttach;
bounds.upperBound = ZSTD_dictForceCopy; /* note : how to ensure at compile time that this is the highest value enum ? */
return bounds;
default:
@@ -392,7 +393,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
case ZSTD_c_searchLog:
case ZSTD_c_minMatch:
case ZSTD_c_targetLength:
case ZSTD_c_compressionStrategy:
case ZSTD_c_strategy:
return 1;
case ZSTD_c_format:
@@ -441,7 +442,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
case ZSTD_c_searchLog:
case ZSTD_c_minMatch:
case ZSTD_c_targetLength:
case ZSTD_c_compressionStrategy:
case ZSTD_c_strategy:
if (cctx->cdict) return ERROR(stage_wrong);
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
@@ -534,13 +535,13 @@ size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
return CCtxParams->cParams.minMatch;
case ZSTD_c_targetLength :
/* all values are valid. 0 => use default */
CLAMPCHECK(ZSTD_c_targetLength, value);
CCtxParams->cParams.targetLength = value;
return CCtxParams->cParams.targetLength;
case ZSTD_c_compressionStrategy :
case ZSTD_c_strategy :
if (value!=0) /* 0 => use default */
CLAMPCHECK(ZSTD_c_compressionStrategy, value);
CLAMPCHECK(ZSTD_c_strategy, value);
CCtxParams->cParams.strategy = (ZSTD_strategy)value;
return (size_t)CCtxParams->cParams.strategy;
@@ -666,7 +667,7 @@ size_t ZSTD_CCtxParam_getParameter(
case ZSTD_c_targetLength :
*value = CCtxParams->cParams.targetLength;
break;
case ZSTD_c_compressionStrategy :
case ZSTD_c_strategy :
*value = (unsigned)CCtxParams->cParams.strategy;
break;
case ZSTD_c_contentSizeFlag :
@@ -849,10 +850,8 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
CLAMPCHECK(ZSTD_c_hashLog, cParams.hashLog);
CLAMPCHECK(ZSTD_c_searchLog, cParams.searchLog);
CLAMPCHECK(ZSTD_c_minMatch, cParams.minMatch);
ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
return ERROR(parameter_outOfBound);
CLAMPCHECK(ZSTD_c_compressionStrategy, cParams.strategy);
CLAMPCHECK(ZSTD_c_targetLength,cParams.targetLength);
CLAMPCHECK(ZSTD_c_strategy, cParams.strategy);
return 0;
}
@@ -862,20 +861,18 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
static ZSTD_compressionParameters
ZSTD_clampCParams(ZSTD_compressionParameters cParams)
{
# define CLAMP(cParam, val) { \
ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
if (val<bounds.lowerBound) val=bounds.lowerBound; \
else if (val>bounds.upperBound) val=bounds.upperBound; \
# define CLAMP(cParam, val) { \
ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
if ((int)val<bounds.lowerBound) val=bounds.lowerBound; \
else if ((int)val>bounds.upperBound) val=bounds.upperBound; \
}
CLAMP(ZSTD_c_windowLog, cParams.windowLog);
CLAMP(ZSTD_c_chainLog, cParams.chainLog);
CLAMP(ZSTD_c_hashLog, cParams.hashLog);
CLAMP(ZSTD_c_searchLog, cParams.searchLog);
CLAMP(ZSTD_c_minMatch, cParams.minMatch);
ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
cParams.targetLength = ZSTD_TARGETLENGTH_MAX;
CLAMP(ZSTD_c_compressionStrategy, cParams.strategy);
CLAMP(ZSTD_c_targetLength,cParams.targetLength);
CLAMP(ZSTD_c_strategy, cParams.strategy);
return cParams;
}
@@ -1841,11 +1838,9 @@ static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, cons
* note : use same formula for both situations */
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
{
U32 const minlog = (U32)strat - 1;
ZSTD_STATIC_ASSERT(ZSTD_btopt == 7);
assert(strat >= ZSTD_btopt);
return (srcSize >> minlog) + 2;
}
U32 const minlog = (strat>=ZSTD_btultra) ? (U32)(strat) - 1 : 6;
ZSTD_STATIC_ASSERT(ZSTD_btultra == 8);
return (srcSize >> minlog) + 2;}
static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
ZSTD_hufCTables_t* nextHuf,
@@ -2585,7 +2580,7 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMo
ZSTD_blockCompressor selectedCompressor;
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1);
assert(ZSTD_cParam_withinBounds(ZSTD_c_compressionStrategy, strat));
assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat));
selectedCompressor = blockCompressor[(int)dictMode][(int)strat];
assert(selectedCompressor != NULL);
return selectedCompressor;
+1
View File
@@ -188,6 +188,7 @@ static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
case ZSTD_btlazy2:
case ZSTD_btopt:
case ZSTD_btultra:
case ZSTD_btultra2:
break;
default:
assert(0); /* not possible : not a valid strategy id */
+1 -1
View File
@@ -1162,5 +1162,5 @@ size_t ZSTD_compressBlock_btultra_extDict(
}
/* note : no btultra2 variant for extDict nor dictMatchState,
* tbecause btultra2 is not meant to work with dictionaries
* because btultra2 is not meant to work with dictionaries
* and is only specific for the first block (no prefix) */
+8
View File
@@ -26,6 +26,10 @@ size_t ZSTD_compressBlock_btopt(
size_t ZSTD_compressBlock_btultra(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
size_t ZSTD_compressBlock_btultra2(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
size_t ZSTD_compressBlock_btopt_dictMatchState(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
@@ -41,6 +45,10 @@ size_t ZSTD_compressBlock_btultra_extDict(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
/* note : no btultra2 variant for extDict nor dictMatchState,
* because btultra2 is not meant to work with dictionaries
* and is only specific for the first block (no prefix) */
#if defined (__cplusplus)
}
#endif
+3 -4
View File
@@ -496,9 +496,8 @@ typedef enum { ZSTD_fast=1,
ZSTD_btopt=7,
ZSTD_btultra=8,
ZSTD_btultra2=9
/* note : new strategies might be added in the future.
Only the order (from fast to strong) is guaranteed, not the exact position.
new strategy names might be introduced, pushing the maximum number upward */
/* note : new strategies _might_ be added in the future.
Only the order (from fast to strong) is guaranteed */
} ZSTD_strategy;
@@ -549,7 +548,7 @@ typedef enum {
* Distance between match sampling.
* Larger values make compression faster, and weaker.
* Special: value 0 means "use default targetLength". */
ZSTD_c_compressionStrategy=107, /* See ZSTD_strategy enum definition.
ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
* The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */