mirror of
https://github.com/facebook/zstd.git
synced 2025-11-30 00:03:21 -05:00
Add ZSTD_CCtx_resetParameters() function
* Fix docs for `ZSTD_CCtx_reset()`. * Add `ZSTD_CCtx_resetParameters()`. Fixes #1094.
This commit is contained in:
parent
3c3f59e68f
commit
9f76eebd17
@ -72,9 +72,11 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
|
|||||||
{ ZSTD_CCtx* const cctx = (ZSTD_CCtx*)ZSTD_calloc(sizeof(ZSTD_CCtx), customMem);
|
{ ZSTD_CCtx* const cctx = (ZSTD_CCtx*)ZSTD_calloc(sizeof(ZSTD_CCtx), customMem);
|
||||||
if (!cctx) return NULL;
|
if (!cctx) return NULL;
|
||||||
cctx->customMem = customMem;
|
cctx->customMem = customMem;
|
||||||
cctx->requestedParams.compressionLevel = ZSTD_CLEVEL_DEFAULT;
|
|
||||||
cctx->requestedParams.fParams.contentSizeFlag = 1;
|
|
||||||
cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
||||||
|
{ size_t const err = ZSTD_CCtx_resetParameters(cctx);
|
||||||
|
assert(!ZSTD_isError(err));
|
||||||
|
(void)err;
|
||||||
|
}
|
||||||
return cctx;
|
return cctx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -671,6 +673,12 @@ void ZSTD_CCtx_reset(ZSTD_CCtx* cctx)
|
|||||||
cctx->cdict = NULL;
|
cctx->cdict = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ZSTD_CCtx_resetParameters(ZSTD_CCtx* cctx)
|
||||||
|
{
|
||||||
|
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
||||||
|
return ZSTD_CCtxParams_reset(&cctx->requestedParams);
|
||||||
|
}
|
||||||
|
|
||||||
/** ZSTD_checkCParams() :
|
/** ZSTD_checkCParams() :
|
||||||
control CParam values remain within authorized range.
|
control CParam values remain within authorized range.
|
||||||
@return : 0, or an error code if one value is beyond authorized range */
|
@return : 0, or an error code if one value is beyond authorized range */
|
||||||
|
|||||||
@ -1142,11 +1142,16 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
|
|||||||
* Useful after an error, or to interrupt an ongoing compression job and start a new one.
|
* Useful after an error, or to interrupt an ongoing compression job and start a new one.
|
||||||
* Any internal data not yet flushed is cancelled.
|
* Any internal data not yet flushed is cancelled.
|
||||||
* Dictionary (if any) is dropped.
|
* Dictionary (if any) is dropped.
|
||||||
* All parameters are back to default values (compression level is ZSTD_CLEVEL_DEFAULT).
|
|
||||||
* After a reset, all compression parameters can be modified again.
|
|
||||||
*/
|
*/
|
||||||
ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx);
|
ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx);
|
||||||
|
|
||||||
|
/*! ZSTD_CCtx_resetParameters() :
|
||||||
|
* All parameters are back to default values (compression level is ZSTD_CLEVEL_DEFAULT).
|
||||||
|
* Resetting parameters is only possible during frame initialization (before starting compression).
|
||||||
|
* @return 0 or an error code (which can be checked with ZSTD_isError()).
|
||||||
|
*/
|
||||||
|
ZSTDLIB_API size_t ZSTD_CCtx_resetParameters(ZSTD_CCtx* cctx);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|||||||
@ -433,6 +433,12 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
CHECK_EQ(value, 7);
|
CHECK_EQ(value, 7);
|
||||||
CHECK_Z(ZSTD_CCtx_getParameter(cctx, ZSTD_p_hashLog, &value));
|
CHECK_Z(ZSTD_CCtx_getParameter(cctx, ZSTD_p_hashLog, &value));
|
||||||
CHECK_EQ(value, ZSTD_HASHLOG_MIN);
|
CHECK_EQ(value, ZSTD_HASHLOG_MIN);
|
||||||
|
/* Reset the parameters */
|
||||||
|
ZSTD_CCtx_resetParameters(cctx);
|
||||||
|
CHECK_Z(ZSTD_CCtx_getParameter(cctx, ZSTD_p_compressionLevel, &value));
|
||||||
|
CHECK_EQ(value, 3);
|
||||||
|
CHECK_Z(ZSTD_CCtx_getParameter(cctx, ZSTD_p_hashLog, &value));
|
||||||
|
CHECK_EQ(value, 0);
|
||||||
|
|
||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user