From: senhuang42 Date: Mon, 16 Nov 2020 15:44:57 +0000 (-0500) Subject: Add new sequence format as an experimental CCtx param X-Git-Tag: v1.4.7~30^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f563b0519adb81c95919d8598c27bd47312c217;p=thirdparty%2Fzstd.git Add new sequence format as an experimental CCtx param --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 521752df0..434ad6e1c 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -457,6 +457,11 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param) bounds.lowerBound = (int)ZSTD_bm_buffered; bounds.upperBound = (int)ZSTD_bm_stable; return bounds; + + case ZSTD_c_blockDelimiters: + bounds.lowerBound = (int)ZSTD_sf_noBlockDelimiters; + bounds.upperBound = (int)ZSTD_sf_explicitBlockDelimiters; + return bounds; default: bounds.error = ERROR(parameter_unsupported); @@ -517,6 +522,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param) case ZSTD_c_srcSizeHint: case ZSTD_c_stableInBuffer: case ZSTD_c_stableOutBuffer: + case ZSTD_c_blockDelimiters: default: return 0; } @@ -567,6 +573,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value) case ZSTD_c_srcSizeHint: case ZSTD_c_stableInBuffer: case ZSTD_c_stableOutBuffer: + case ZSTD_c_blockDelimiters: break; default: RETURN_ERROR(parameter_unsupported, "unknown parameter"); @@ -767,6 +774,11 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams, BOUNDCHECK(ZSTD_c_stableOutBuffer, value); CCtxParams->outBufferMode = (ZSTD_bufferMode_e)value; return CCtxParams->outBufferMode; + + case ZSTD_c_blockDelimiters: + BOUNDCHECK(ZSTD_c_blockDelimiters, value); + CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value; + return CCtxParams->blockDelimiters; default: RETURN_ERROR(parameter_unsupported, "unknown parameter"); } @@ -885,6 +897,9 @@ size_t ZSTD_CCtxParams_getParameter( case ZSTD_c_stableOutBuffer : *value = (int)CCtxParams->outBufferMode; break; + case ZSTD_c_blockDelimiters : + *value = (int)CCtxParams->blockDelimiters; + break; default: RETURN_ERROR(parameter_unsupported, "unknown parameter"); } return 0; @@ -1718,9 +1733,6 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc, zc->ldmState.loadedDictEnd = 0; } - zc->blockDelimiters = ZSTD_sf_noBlockDelimiters; - zc->calculateRepcodes = ZSTD_sf_calculateRepcodes; - /* Due to alignment, when reusing a workspace, we can actually consume * up to 3 extra bytes for alignment. See the comments in zstd_cwksp.h */ diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index 41cce6039..51cb66d7b 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -242,6 +242,9 @@ struct ZSTD_CCtx_params_s { ZSTD_bufferMode_e inBufferMode; ZSTD_bufferMode_e outBufferMode; + /* Sequence compression API */ + ZSTD_sequenceFormat_e blockDelimiters; + /* Internal use, for createCCtxParams() and freeCCtxParams() only */ ZSTD_customMem customMem; }; /* typedef'd to ZSTD_CCtx_params within "zstd.h" */ @@ -313,10 +316,6 @@ struct ZSTD_CCtx_s { const ZSTD_CDict* cdict; ZSTD_prefixDict prefixDict; /* single-usage dictionary */ - /* Sequence compression API */ - ZSTD_sequenceFormat_blockBoundaries_e blockDelimiters; - ZSTD_sequenceFormat_repcodes_e calculateRepcodes; - /* Multi-threading */ #ifdef ZSTD_MULTITHREAD ZSTDMT_CCtx* mtctx; diff --git a/lib/zstd.h b/lib/zstd.h index aea0e3cc4..a0aa6d3ac 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -417,6 +417,7 @@ typedef enum { * ZSTD_c_enableDedicatedDictSearch * ZSTD_c_stableInBuffer * ZSTD_c_stableOutBuffer + * ZSTD_c_blockDelimiters * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them. * note : never ever use experimentalParam? names directly; * also, the enums values themselves are unstable and can still change. @@ -430,7 +431,8 @@ typedef enum { ZSTD_c_experimentalParam7=1004, ZSTD_c_experimentalParam8=1005, ZSTD_c_experimentalParam9=1006, - ZSTD_c_experimentalParam10=1007 + ZSTD_c_experimentalParam10=1007, + ZSTD_c_experimentalParam11=1008 } ZSTD_cParameter; typedef struct { @@ -1298,14 +1300,9 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize); typedef enum { - ZSTD_sf_noBlockDelimiters, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */ - ZSTD_sf_explicitBlockDelimiters /* Representation of ZSTD_Sequence contains explicit block delimiters */ -} ZSTD_sequenceFormat_blockBoundaries_e; - -typedef enum { - ZSTD_sf_calculateRepcodes, - ZSTD_sf_noCalculateRepcodes -} ZSTD_sequenceFormat_repcodes_e; + ZSTD_sf_noBlockDelimiters = 0, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */ + ZSTD_sf_explicitBlockDelimiters = 1 /* Representation of ZSTD_Sequence contains explicit block delimiters */ +} ZSTD_sequenceFormat_e; /*! ZSTD_generateSequences() : * Generate sequences using ZSTD_compress2, given a source buffer. @@ -1317,6 +1314,9 @@ typedef enum { * * zc can be used to insert custom compression params. * This function invokes ZSTD_compress2 + * + * The output of this function can be fed into ZSTD_compressSequences() with ZSTD_c_explicitBlockDelimiters + * set to ZSTD_sf_explicitBlockDelimiters * @return : number of sequences generated */ @@ -1329,6 +1329,9 @@ ZSTDLIB_API size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs, * * As such, the final generated result has no explicit representation of block boundaries, * and the final last literals segment is not represented in the sequences. + * + * The output of this function can be fed into ZSTD_compressSequences() with ZSTD_c_blockDelimiters + * set to ZSTD_sf_noBlockDelimiters * @return : number of sequences left after merging */ ZSTDLIB_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize); @@ -1748,6 +1751,15 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre */ #define ZSTD_c_stableOutBuffer ZSTD_c_experimentalParam10 +/* ZSTD_c_blockDelimiters + * Default is 0 == ZSTD_sf_noBlockDelimiters. + * + * For use with sequence compression API: ZSTD_compressSequences(). + * Designates whether or not the given array of ZSTD_Sequence contains block delimiters + * which are defined as sequences with offset == 0 and matchLength == 0. + */ +#define ZSTD_c_blockDelimiters ZSTD_c_experimentalParam11 + /*! ZSTD_CCtx_getParameter() : * Get the requested compression parameter value, selected by enum ZSTD_cParameter, * and store it into int* value.