From 399ae013d4028bb197b14b183cb91b53742884f6 Mon Sep 17 00:00:00 2001 From: Stella Lau Date: Fri, 18 Aug 2017 13:01:55 -0700 Subject: [PATCH] Add function to apply cctx params --- lib/common/zstd_internal.h | 34 ++++++++++++++++++---------------- lib/compress/zstd_compress.c | 29 +++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/lib/common/zstd_internal.h b/lib/common/zstd_internal.h index 7ea2ecc4..fa9f0c49 100644 --- a/lib/common/zstd_internal.h +++ b/lib/common/zstd_internal.h @@ -221,22 +221,6 @@ typedef struct seqDef_s { U16 matchLength; } seqDef; -typedef struct ZSTD_CCtx_params_s { - ZSTD_compressionParameters cParams; - ZSTD_frameParameters fParams; - - int compressionLevel; - U32 forceWindow; - - /* Dictionary */ - ZSTD_dictMode_e dictMode; - U32 dictContentByRef; - - /* Multithreading */ - U32 nbThreads; - -} ZSTD_CCtx_params; - typedef struct { seqDef* sequencesStart; seqDef* sequences; @@ -251,6 +235,24 @@ typedef struct { U32 repToConfirm[ZSTD_REP_NUM]; } seqStore_t; +struct ZSTD_CCtx_params_s { + ZSTD_compressionParameters cParams; + ZSTD_frameParameters fParams; + + int compressionLevel; + + U32 forceWindow; /* force back-references to respect limit of 1<nbThreads <= 1) { return ERROR(parameter_unsupported); } + params->jobSize = value; return 0; case ZSTD_p_overlapSizeLog : - // TODO + params->overlapSizeLog = value; return 0; default: return ERROR(parameter_unsupported); } } +// This function should probably be updated whenever ZSTD_CCtx_params is updated. ZSTDLIB_API size_t ZSTD_CCtx_applyCCtxParams(ZSTD_CCtx* cctx, ZSTD_CCtx_params* params) { - (void)cctx; - (void)params; + if (cctx->cdict) { return ERROR(stage_wrong); } + + /* Assume the compression and frame parameters are validated */ + cctx->requestedParams.cParams = params->cParams; + cctx->requestedParams.fParams = params->fParams; + cctx->requestedParams.compressionLevel = params->compressionLevel; + + /* Assume dictionary parameters are validated */ + cctx->requestedParams.dictMode = params->dictMode; + cctx->requestedParams.dictContentByRef = params->dictContentByRef; + + /* Set force window explicitly since it sets cctx->loadedDictEnd */ + CHECK_F( ZSTD_CCtx_setParameter( + cctx, ZSTD_p_forceMaxWindow, params->forceWindow) ); + + /* Set multithreading parameters explicitly */ + CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_nbThreads, params->nbThreads) ); + CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_jobSize, params->jobSize) ); + CHECK_F( ZSTD_CCtx_setParameter( + cctx, ZSTD_p_overlapSizeLog, params->overlapSizeLog) ); return 0; }