ReactOS  0.4.14-dev-552-g2fad488
zstd_compress.c File Reference
#include <string.h>
#include "cpu.h"
#include "mem.h"
#include "hist.h"
#include "fse.h"
#include "huf.h"
#include "zstd_compress_internal.h"
#include "zstd_fast.h"
#include "zstd_double_fast.h"
#include "zstd_lazy.h"
#include "zstd_opt.h"
#include "zstd_ldm.h"
Include dependency graph for zstd_compress.c:

Go to the source code of this file.

Classes

struct  ZSTD_CDict_s
 

Macros

#define FSE_STATIC_LINKING_ONLY   /* FSE_encodeSymbol */
 
#define HUF_STATIC_LINKING_ONLY
 
#define CLAMPCHECK(val, min, max)
 
#define CLAMP(val, min, max)
 
#define ZSTD_WORKSPACETOOLARGE_FACTOR   3 /* define "workspace is too large" as this number of times larger than needed */
 
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION
 
#define ZSTD_ROWSIZE   16
 
#define COMPRESS_LITERALS_SIZE_MIN   63
 
#define ZSTD_MAX_CLEVEL   22
 

Enumerations

enum  ZSTD_buffered_policy_e { ZSTDb_not_buffered, ZSTDb_buffered }
 
enum  ZSTD_compResetPolicy_e { ZSTDcrp_continue, ZSTDcrp_noMemset }
 
enum  ZSTD_defaultPolicy_e { ZSTD_defaultDisallowed = 0, ZSTD_defaultAllowed = 1 }
 

Functions

size_t ZSTD_compressBound (size_t srcSize)
 
ZSTD_CCtxZSTD_createCCtx (void)
 
static void ZSTD_initCCtx (ZSTD_CCtx *cctx, ZSTD_customMem memManager)
 
ZSTD_CCtxZSTD_createCCtx_advanced (ZSTD_customMem customMem)
 
ZSTD_CCtxZSTD_initStaticCCtx (void *workspace, size_t workspaceSize)
 
static void ZSTD_freeCCtxContent (ZSTD_CCtx *cctx)
 
size_t ZSTD_freeCCtx (ZSTD_CCtx *cctx)
 
static size_t ZSTD_sizeof_mtctx (const ZSTD_CCtx *cctx)
 
size_t ZSTD_sizeof_CCtx (const ZSTD_CCtx *cctx)
 
size_t ZSTD_sizeof_CStream (const ZSTD_CStream *zcs)
 
const seqStore_tZSTD_getSeqStore (const ZSTD_CCtx *ctx)
 
static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams (ZSTD_compressionParameters cParams)
 
static ZSTD_CCtx_params * ZSTD_createCCtxParams_advanced (ZSTD_customMem customMem)
 
ZSTD_CCtx_params * ZSTD_createCCtxParams (void)
 
size_t ZSTD_freeCCtxParams (ZSTD_CCtx_params *params)
 
size_t ZSTD_CCtxParams_reset (ZSTD_CCtx_params *params)
 
size_t ZSTD_CCtxParams_init (ZSTD_CCtx_params *cctxParams, int compressionLevel)
 
size_t ZSTD_CCtxParams_init_advanced (ZSTD_CCtx_params *cctxParams, ZSTD_parameters params)
 
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams (ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
 
static int ZSTD_isUpdateAuthorized (ZSTD_cParameter param)
 
size_t ZSTD_CCtx_setParameter (ZSTD_CCtx *cctx, ZSTD_cParameter param, unsigned value)
 
size_t ZSTD_CCtxParam_setParameter (ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, unsigned value)
 
size_t ZSTD_CCtx_getParameter (ZSTD_CCtx *cctx, ZSTD_cParameter param, unsigned *value)
 
size_t ZSTD_CCtxParam_getParameter (ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, unsigned *value)
 
size_t ZSTD_CCtx_setParametersUsingCCtxParams (ZSTD_CCtx *cctx, const ZSTD_CCtx_params *params)
 
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize (ZSTD_CCtx *cctx, unsigned long long pledgedSrcSize)
 
size_t ZSTD_CCtx_loadDictionary_advanced (ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
 
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference (ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
 
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary (ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
 
size_t ZSTD_CCtx_refCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
 
size_t ZSTD_CCtx_refPrefix (ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize)
 
size_t ZSTD_CCtx_refPrefix_advanced (ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
 
void ZSTD_CCtx_reset (ZSTD_CCtx *cctx)
 
size_t ZSTD_CCtx_resetParameters (ZSTD_CCtx *cctx)
 
size_t ZSTD_checkCParams (ZSTD_compressionParameters cParams)
 
static ZSTD_compressionParameters ZSTD_clampCParams (ZSTD_compressionParameters cParams)
 
static U32 ZSTD_cycleLog (U32 hashLog, ZSTD_strategy strat)
 
static ZSTD_compressionParameters ZSTD_adjustCParams_internal (ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize)
 
ZSTD_compressionParameters ZSTD_adjustCParams (ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize)
 
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams (const ZSTD_CCtx_params *CCtxParams, U64 srcSizeHint, size_t dictSize)
 
static size_t ZSTD_sizeof_matchState (const ZSTD_compressionParameters *const cParams, const U32 forCCtx)
 
size_t ZSTD_estimateCCtxSize_usingCCtxParams (const ZSTD_CCtx_params *params)
 
size_t ZSTD_estimateCCtxSize_usingCParams (ZSTD_compressionParameters cParams)
 
static size_t ZSTD_estimateCCtxSize_internal (int compressionLevel)
 
size_t ZSTD_estimateCCtxSize (int compressionLevel)
 
size_t ZSTD_estimateCStreamSize_usingCCtxParams (const ZSTD_CCtx_params *params)
 
size_t ZSTD_estimateCStreamSize_usingCParams (ZSTD_compressionParameters cParams)
 
static size_t ZSTD_estimateCStreamSize_internal (int compressionLevel)
 
size_t ZSTD_estimateCStreamSize (int compressionLevel)
 
ZSTD_frameProgression ZSTD_getFrameProgression (const ZSTD_CCtx *cctx)
 
size_t ZSTD_toFlushNow (ZSTD_CCtx *cctx)
 
static U32 ZSTD_equivalentCParams (ZSTD_compressionParameters cParams1, ZSTD_compressionParameters cParams2)
 
static void ZSTD_assertEqualCParams (ZSTD_compressionParameters cParams1, ZSTD_compressionParameters cParams2)
 
static U32 ZSTD_equivalentLdmParams (ldmParams_t ldmParams1, ldmParams_t ldmParams2)
 
static U32 ZSTD_sufficientBuff (size_t bufferSize1, size_t maxNbSeq1, size_t maxNbLit1, ZSTD_buffered_policy_e buffPol2, ZSTD_compressionParameters cParams2, U64 pledgedSrcSize)
 
static U32 ZSTD_equivalentParams (ZSTD_CCtx_params params1, ZSTD_CCtx_params params2, size_t buffSize1, size_t maxNbSeq1, size_t maxNbLit1, ZSTD_buffered_policy_e buffPol2, U64 pledgedSrcSize)
 
static void ZSTD_reset_compressedBlockState (ZSTD_compressedBlockState_t *bs)
 
static void ZSTD_invalidateMatchState (ZSTD_matchState_t *ms)
 
static size_t ZSTD_continueCCtx (ZSTD_CCtx *cctx, ZSTD_CCtx_params params, U64 pledgedSrcSize)
 
static voidZSTD_reset_matchState (ZSTD_matchState_t *ms, void *ptr, const ZSTD_compressionParameters *cParams, ZSTD_compResetPolicy_e const crp, U32 const forCCtx)
 
static size_t ZSTD_resetCCtx_internal (ZSTD_CCtx *zc, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_compResetPolicy_e const crp, ZSTD_buffered_policy_e const zbuff)
 
void ZSTD_invalidateRepCodes (ZSTD_CCtx *cctx)
 
static int ZSTD_shouldAttachDict (const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize)
 
static size_t ZSTD_resetCCtx_byAttachingCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
 
static size_t ZSTD_resetCCtx_byCopyingCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
 
static size_t ZSTD_resetCCtx_usingCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
 
static size_t ZSTD_copyCCtx_internal (ZSTD_CCtx *dstCCtx, const ZSTD_CCtx *srcCCtx, ZSTD_frameParameters fParams, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
 
size_t ZSTD_copyCCtx (ZSTD_CCtx *dstCCtx, const ZSTD_CCtx *srcCCtx, unsigned long long pledgedSrcSize)
 
FORCE_INLINE_TEMPLATE void ZSTD_reduceTable_internal (U32 *const table, U32 const size, U32 const reducerValue, int const preserveMark)
 
static void ZSTD_reduceTable (U32 *const table, U32 const size, U32 const reducerValue)
 
static void ZSTD_reduceTable_btlazy2 (U32 *const table, U32 const size, U32 const reducerValue)
 
static void ZSTD_reduceIndex (ZSTD_CCtx *zc, const U32 reducerValue)
 
static size_t ZSTD_noCompressBlock (void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 lastBlock)
 
static size_t ZSTD_noCompressLiterals (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_compressRleLiteralsBlock (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_minGain (size_t srcSize, ZSTD_strategy strat)
 
static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const *prevHuf, ZSTD_hufCTables_t *nextHuf, ZSTD_strategy strategy, int disableLiteralCompression, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 *workspace, const int bmi2)
 
void ZSTD_seqToCodes (const seqStore_t *seqStorePtr)
 
static size_t ZSTD_entropyCost (unsigned const *count, unsigned const max, size_t const total)
 
static size_t ZSTD_crossEntropyCost (short const *norm, unsigned accuracyLog, unsigned const *count, unsigned const max)
 
static unsigned ZSTD_getFSEMaxSymbolValue (FSE_CTable const *ctable)
 
static size_t ZSTD_fseBitCost (FSE_CTable const *ctable, unsigned const *count, unsigned const max)
 
static size_t ZSTD_NCountCost (unsigned const *count, unsigned const max, size_t const nbSeq, unsigned const FSELog)
 
MEM_STATIC symbolEncodingType_e ZSTD_selectEncodingType (FSE_repeat *repeatMode, unsigned const *count, unsigned const max, size_t const mostFrequent, size_t nbSeq, unsigned const FSELog, FSE_CTable const *prevCTable, short const *defaultNorm, U32 defaultNormLog, ZSTD_defaultPolicy_e const isDefaultAllowed, ZSTD_strategy const strategy)
 
MEM_STATIC size_t ZSTD_buildCTable (void *dst, size_t dstCapacity, FSE_CTable *nextCTable, U32 FSELog, symbolEncodingType_e type, U32 *count, U32 max, const BYTE *codeTable, size_t nbSeq, const S16 *defaultNorm, U32 defaultNormLog, U32 defaultMax, const FSE_CTable *prevCTable, size_t prevCTableSize, void *workspace, size_t workspaceSize)
 
FORCE_INLINE_TEMPLATE size_t ZSTD_encodeSequences_body (void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets)
 
static size_t ZSTD_encodeSequences_default (void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets)
 
static size_t ZSTD_encodeSequences (void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets, int bmi2)
 
MEM_STATIC size_t ZSTD_compressSequences_internal (seqStore_t *seqStorePtr, ZSTD_entropyCTables_t const *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, ZSTD_CCtx_params const *cctxParams, void *dst, size_t dstCapacity, U32 *workspace, const int bmi2)
 
MEM_STATIC size_t ZSTD_compressSequences (seqStore_t *seqStorePtr, const ZSTD_entropyCTables_t *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, const ZSTD_CCtx_params *cctxParams, void *dst, size_t dstCapacity, size_t srcSize, U32 *workspace, int bmi2)
 
ZSTD_blockCompressor ZSTD_selectBlockCompressor (ZSTD_strategy strat, ZSTD_dictMode_e dictMode)
 
static void ZSTD_storeLastLiterals (seqStore_t *seqStorePtr, const BYTE *anchor, size_t lastLLSize)
 
void ZSTD_resetSeqStore (seqStore_t *ssPtr)
 
static size_t ZSTD_compressBlock_internal (ZSTD_CCtx *zc, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_compress_frameChunk (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 lastFrameChunk)
 
static size_t ZSTD_writeFrameHeader (void *dst, size_t dstCapacity, ZSTD_CCtx_params params, U64 pledgedSrcSize, U32 dictID)
 
size_t ZSTD_writeLastEmptyBlock (void *dst, size_t dstCapacity)
 
size_t ZSTD_referenceExternalSequences (ZSTD_CCtx *cctx, rawSeq *seq, size_t nbSeq)
 
static size_t ZSTD_compressContinue_internal (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 frame, U32 lastFrameChunk)
 
size_t ZSTD_compressContinue (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
size_t ZSTD_getBlockSize (const ZSTD_CCtx *cctx)
 
size_t ZSTD_compressBlock (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_loadDictionaryContent (ZSTD_matchState_t *ms, ZSTD_CCtx_params const *params, const void *src, size_t srcSize, ZSTD_dictTableLoadMethod_e dtlm)
 
static size_t ZSTD_checkDictNCount (short *normalizedCounter, unsigned dictMaxSymbolValue, unsigned maxSymbolValue)
 
static size_t ZSTD_loadZstdDictionary (ZSTD_compressedBlockState_t *bs, ZSTD_matchState_t *ms, ZSTD_CCtx_params const *params, const void *dict, size_t dictSize, ZSTD_dictTableLoadMethod_e dtlm, void *workspace)
 
static size_t ZSTD_compress_insertDictionary (ZSTD_compressedBlockState_t *bs, ZSTD_matchState_t *ms, const ZSTD_CCtx_params *params, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, void *workspace)
 
static size_t ZSTD_compressBegin_internal (ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
 
size_t ZSTD_compressBegin_advanced_internal (ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, unsigned long long pledgedSrcSize)
 
size_t ZSTD_compressBegin_advanced (ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize)
 
size_t ZSTD_compressBegin_usingDict (ZSTD_CCtx *cctx, const void *dict, size_t dictSize, int compressionLevel)
 
size_t ZSTD_compressBegin (ZSTD_CCtx *cctx, int compressionLevel)
 
static size_t ZSTD_writeEpilogue (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity)
 
size_t ZSTD_compressEnd (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_compress_internal (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params)
 
size_t ZSTD_compress_advanced (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params)
 
size_t ZSTD_compress_advanced_internal (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_CCtx_params params)
 
size_t ZSTD_compress_usingDict (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
 
size_t ZSTD_compressCCtx (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
size_t ZSTD_compress (void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
size_t ZSTD_estimateCDictSize_advanced (size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod)
 
size_t ZSTD_estimateCDictSize (size_t dictSize, int compressionLevel)
 
size_t ZSTD_sizeof_CDict (const ZSTD_CDict *cdict)
 
static size_t ZSTD_initCDict_internal (ZSTD_CDict *cdict, const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams)
 
ZSTD_CDictZSTD_createCDict_advanced (const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)
 
ZSTD_CDictZSTD_createCDict (const void *dict, size_t dictSize, int compressionLevel)
 
ZSTD_CDictZSTD_createCDict_byReference (const void *dict, size_t dictSize, int compressionLevel)
 
size_t ZSTD_freeCDict (ZSTD_CDict *cdict)
 
const ZSTD_CDictZSTD_initStaticCDict (void *workspace, size_t workspaceSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams)
 
ZSTD_compressionParameters ZSTD_getCParamsFromCDict (const ZSTD_CDict *cdict)
 
size_t ZSTD_compressBegin_usingCDict_advanced (ZSTD_CCtx *const cctx, const ZSTD_CDict *const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)
 
size_t ZSTD_compressBegin_usingCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
 
size_t ZSTD_compress_usingCDict_advanced (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams)
 
size_t ZSTD_compress_usingCDict (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict)
 
ZSTD_CStreamZSTD_createCStream (void)
 
ZSTD_CStreamZSTD_initStaticCStream (void *workspace, size_t workspaceSize)
 
ZSTD_CStreamZSTD_createCStream_advanced (ZSTD_customMem customMem)
 
size_t ZSTD_freeCStream (ZSTD_CStream *zcs)
 
size_t ZSTD_CStreamInSize (void)
 
size_t ZSTD_CStreamOutSize (void)
 
static size_t ZSTD_resetCStream_internal (ZSTD_CStream *cctx, 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)
 
size_t ZSTD_resetCStream (ZSTD_CStream *zcs, unsigned long long pledgedSrcSize)
 
size_t ZSTD_initCStream_internal (ZSTD_CStream *zcs, const void *dict, size_t dictSize, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, unsigned long long pledgedSrcSize)
 
size_t ZSTD_initCStream_usingCDict_advanced (ZSTD_CStream *zcs, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize)
 
size_t ZSTD_initCStream_usingCDict (ZSTD_CStream *zcs, const ZSTD_CDict *cdict)
 
size_t ZSTD_initCStream_advanced (ZSTD_CStream *zcs, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize)
 
size_t ZSTD_initCStream_usingDict (ZSTD_CStream *zcs, const void *dict, size_t dictSize, int compressionLevel)
 
size_t ZSTD_initCStream_srcSize (ZSTD_CStream *zcs, int compressionLevel, unsigned long long pss)
 
size_t ZSTD_initCStream (ZSTD_CStream *zcs, int compressionLevel)
 
MEM_STATIC size_t ZSTD_limitCopy (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
size_t ZSTD_compressStream_generic (ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
 
size_t ZSTD_compressStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
size_t ZSTD_compress_generic (ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
 
size_t ZSTD_compress_generic_simpleArgs (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos, ZSTD_EndDirective endOp)
 
size_t ZSTD_flushStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
size_t ZSTD_endStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
int ZSTD_maxCLevel (void)
 
int ZSTD_minCLevel (void)
 
ZSTD_compressionParameters ZSTD_getCParams (int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
 
ZSTD_parameters ZSTD_getParams (int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
 

Variables

static const size_t attachDictSizeCutoffs [(unsigned) ZSTD_btultra+1]
 
static unsigned const kInverseProbabiltyLog256 [256]
 
static const ZSTD_compressionParameters ZSTD_defaultCParameters [4][ZSTD_MAX_CLEVEL+1]
 

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   val,
  min,
  max 
)
Value:
{ \
if (val<min) val=min; \
else if (val>max) val=max; \
}
#define max(a, b)
Definition: svc.c:63
GLuint GLfloat * val
Definition: glext.h:7180
#define min(a, b)
Definition: monoChain.cc:55

◆ CLAMPCHECK

#define CLAMPCHECK (   val,
  min,
  max 
)
Value:
{ \
if (((val)<(min)) | ((val)>(max))) { \
return ERROR(parameter_outOfBound); \
} }
#define max(a, b)
Definition: svc.c:63
#define ERROR(name)
Definition: error_private.h:53
GLuint GLfloat * val
Definition: glext.h:7180
#define min(a, b)
Definition: monoChain.cc:55

Definition at line 229 of file zstd_compress.c.

◆ COMPRESS_LITERALS_SIZE_MIN

#define COMPRESS_LITERALS_SIZE_MIN   63

◆ FSE_STATIC_LINKING_ONLY

#define FSE_STATIC_LINKING_ONLY   /* FSE_encodeSymbol */

Definition at line 18 of file zstd_compress.c.

◆ HUF_STATIC_LINKING_ONLY

#define HUF_STATIC_LINKING_ONLY

Definition at line 20 of file zstd_compress.c.

◆ ZSTD_MAX_CLEVEL

#define ZSTD_MAX_CLEVEL   22

Definition at line 3899 of file zstd_compress.c.

◆ ZSTD_ROWSIZE

#define ZSTD_ROWSIZE   16

Definition at line 1537 of file zstd_compress.c.

◆ ZSTD_WORKSPACETOOLARGE_FACTOR

#define ZSTD_WORKSPACETOOLARGE_FACTOR   3 /* define "workspace is too large" as this number of times larger than needed */

Definition at line 1125 of file zstd_compress.c.

◆ ZSTD_WORKSPACETOOLARGE_MAXDURATION

#define ZSTD_WORKSPACETOOLARGE_MAXDURATION
Value:
128 /* when workspace is continuously too large
* during at least this number of times,
* context's memory usage is considered wasteful,
* because it's sized to handle a worst case scenario which rarely happens.
* In which case, resize it down to free some memory */

Definition at line 1126 of file zstd_compress.c.

Enumeration Type Documentation

◆ ZSTD_buffered_policy_e

Enumerator
ZSTDb_not_buffered 
ZSTDb_buffered 

Definition at line 966 of file zstd_compress.c.

◆ ZSTD_compResetPolicy_e

Enumerator
ZSTDcrp_continue 
ZSTDcrp_noMemset 

Definition at line 1073 of file zstd_compress.c.

◆ ZSTD_defaultPolicy_e

Enumerator
ZSTD_defaultDisallowed 
ZSTD_defaultAllowed 

Definition at line 1913 of file zstd_compress.c.

Function Documentation

◆ ZSTD_adjustCParams()

ZSTD_compressionParameters ZSTD_adjustCParams ( ZSTD_compressionParameters  cPar,
unsigned long long  srcSize,
size_t  dictSize 
)

Definition at line 760 of file zstd_compress.c.

763 {
764  cPar = ZSTD_clampCParams(cPar);
765  return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize);
766 }
static ZSTD_compressionParameters ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize)
static ZSTD_compressionParameters ZSTD_clampCParams(ZSTD_compressionParameters cParams)

◆ ZSTD_adjustCParams_internal()

static ZSTD_compressionParameters ZSTD_adjustCParams_internal ( ZSTD_compressionParameters  cPar,
unsigned long long  srcSize,
size_t  dictSize 
)
static

ZSTD_adjustCParams_internal() : optimize cPar for a given input (srcSize and dictSize). mostly downsizing to reduce memory consumption and initialization latency. Both srcSize and dictSize are optional (use 0 if unknown). Note : cPar is assumed validated. Use ZSTD_checkCParams() to ensure this condition.

Definition at line 725 of file zstd_compress.c.

728 {
729  static const U64 minSrcSize = 513; /* (1<<9) + 1 */
730  static const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
731  assert(ZSTD_checkCParams(cPar)==0);
732 
733  if (dictSize && (srcSize+1<2) /* srcSize unknown */ )
734  srcSize = minSrcSize; /* presumed small when there is a dictionary */
735  else if (srcSize == 0)
736  srcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* 0 == unknown : presumed large */
737 
738  /* resize windowLog if input is small enough, to use less memory */
739  if ( (srcSize < maxWindowResize)
740  && (dictSize < maxWindowResize) ) {
741  U32 const tSize = (U32)(srcSize + dictSize);
742  static U32 const hashSizeMin = 1 << ZSTD_HASHLOG_MIN;
743  U32 const srcLog = (tSize < hashSizeMin) ? ZSTD_HASHLOG_MIN :
744  ZSTD_highbit32(tSize-1) + 1;
745  if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
746  }
747  if (cPar.hashLog > cPar.windowLog+1) cPar.hashLog = cPar.windowLog+1;
748  { U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy);
749  if (cycleLog > cPar.windowLog)
750  cPar.chainLog -= (cycleLog - cPar.windowLog);
751  }
752 
753  if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN)
754  cPar.windowLog = ZSTD_WINDOWLOG_ABSOLUTEMIN; /* required for frame header */
755 
756  return cPar;
757 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
Definition: zstd_internal.h:77
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define ULL(a, b)
Definition: format_msg.c:27
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
unsigned long long U64
Definition: mem.h:81
MEM_STATIC U32 ZSTD_highbit32(U32 val)

Referenced by ZSTD_adjustCParams(), ZSTD_getCParams(), ZSTD_getCParamsFromCCtxParams(), and ZSTD_resetCCtx_byAttachingCDict().

◆ ZSTD_assertEqualCParams()

static void ZSTD_assertEqualCParams ( ZSTD_compressionParameters  cParams1,
ZSTD_compressionParameters  cParams2 
)
static

Definition at line 939 of file zstd_compress.c.

941 {
942  (void)cParams1;
943  (void)cParams2;
944  assert(cParams1.windowLog == cParams2.windowLog);
945  assert(cParams1.chainLog == cParams2.chainLog);
946  assert(cParams1.hashLog == cParams2.hashLog);
947  assert(cParams1.searchLog == cParams2.searchLog);
948  assert(cParams1.searchLength == cParams2.searchLength);
949  assert(cParams1.targetLength == cParams2.targetLength);
950  assert(cParams1.strategy == cParams2.strategy);
951 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define assert(x)
Definition: debug.h:53

Referenced by ZSTD_compressBlock_internal(), and ZSTD_loadDictionaryContent().

◆ ZSTD_assignParamsToCCtxParams()

static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams ( ZSTD_CCtx_params  cctxParams,
ZSTD_parameters  params 
)
static

Definition at line 218 of file zstd_compress.c.

220 {
221  ZSTD_CCtx_params ret = cctxParams;
222  ret.cParams = params.cParams;
223  ret.fParams = params.fParams;
224  ret.compressionLevel = ZSTD_CLEVEL_DEFAULT; /* should not matter, as all cParams are presumed properly defined */
225  assert(!ZSTD_checkCParams(params.cParams));
226  return ret;
227 }
#define ZSTD_CLEVEL_DEFAULT
Definition: zstd.h:89
#define assert(x)
Definition: debug.h:53
GLenum const GLfloat * params
Definition: glext.h:5645
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
int ret

Referenced by ZSTD_compress_internal(), ZSTD_compress_usingDict(), ZSTD_compressBegin_advanced(), ZSTD_compressBegin_usingDict(), and ZSTD_initCStream_advanced().

◆ ZSTD_buildCTable()

MEM_STATIC size_t ZSTD_buildCTable ( void dst,
size_t  dstCapacity,
FSE_CTable nextCTable,
U32  FSELog,
symbolEncodingType_e  type,
U32 count,
U32  max,
const BYTE codeTable,
size_t  nbSeq,
const S16 defaultNorm,
U32  defaultNormLog,
U32  defaultMax,
const FSE_CTable prevCTable,
size_t  prevCTableSize,
void workspace,
size_t  workspaceSize 
)

Definition at line 2000 of file zstd_compress.c.

2007 {
2008  BYTE* op = (BYTE*)dst;
2009  const BYTE* const oend = op + dstCapacity;
2010 
2011  switch (type) {
2012  case set_rle:
2013  *op = codeTable[0];
2014  CHECK_F(FSE_buildCTable_rle(nextCTable, (BYTE)max));
2015  return 1;
2016  case set_repeat:
2017  memcpy(nextCTable, prevCTable, prevCTableSize);
2018  return 0;
2019  case set_basic:
2020  CHECK_F(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, workspace, workspaceSize)); /* note : could be pre-calculated */
2021  return 0;
2022  case set_compressed: {
2023  S16 norm[MaxSeq + 1];
2024  size_t nbSeq_1 = nbSeq;
2025  const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
2026  if (count[codeTable[nbSeq-1]] > 1) {
2027  count[codeTable[nbSeq-1]]--;
2028  nbSeq_1--;
2029  }
2030  assert(nbSeq_1 > 1);
2031  CHECK_F(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max));
2032  { size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
2033  if (FSE_isError(NCountSize)) return NCountSize;
2034  CHECK_F(FSE_buildCTable_wksp(nextCTable, norm, max, tableLog, workspace, workspaceSize));
2035  return NCountSize;
2036  }
2037  }
2038  default: return assert(0), ERROR(GENERIC);
2039  }
2040 }
FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue)
Definition: fse_compress.c:371
size_t FSE_buildCTable_wksp(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize)
Definition: fse_compress.c:89
FSE_PUBLIC_API size_t FSE_normalizeCount(short *normalizedCounter, unsigned tableLog, const unsigned *count, size_t srcSize, unsigned maxSymbolValue)
Definition: fse_compress.c:467
#define max(a, b)
Definition: svc.c:63
#define MaxSeq
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
Definition: _complex.h:741
#define ERROR(name)
Definition: error_private.h:53
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int U32
Definition: mem.h:77
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define assert(x)
Definition: debug.h:53
#define FSE_isError
Definition: fse_compress.c:55
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t FSE_buildCTable_rle(FSE_CTable *ct, BYTE symbolValue)
Definition: fse_compress.c:563
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLenum GLenum dst
Definition: glext.h:6340
FSE_PUBLIC_API size_t FSE_writeNCount(void *buffer, size_t bufferSize, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
Definition: fse_compress.c:320
signed short S16
Definition: mem.h:73
UINT op
Definition: effect.c:223

Referenced by ZSTD_compressSequences_internal().

◆ ZSTD_CCtx_getParameter()

size_t ZSTD_CCtx_getParameter ( ZSTD_CCtx cctx,
ZSTD_cParameter  param,
unsigned value 
)

Definition at line 475 of file zstd_compress.c.

476 {
478 }
GLfloat param
Definition: glext.h:5796
ZSTD_CCtx_params requestedParams
size_t ZSTD_CCtxParam_getParameter(ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, unsigned *value)

◆ ZSTD_CCtx_loadDictionary()

ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize 
)

Definition at line 625 of file zstd_compress.c.

626 {
628  cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto);
629 }
size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_CCtx_loadDictionary_advanced()

size_t ZSTD_CCtx_loadDictionary_advanced ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize,
ZSTD_dictLoadMethod_e  dictLoadMethod,
ZSTD_dictContentType_e  dictContentType 
)

Definition at line 593 of file zstd_compress.c.

596 {
597  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
598  if (cctx->staticSize) return ERROR(memory_allocation); /* no malloc for static CCtx */
599  DEBUGLOG(4, "ZSTD_CCtx_loadDictionary_advanced (size: %u)", (U32)dictSize);
600  ZSTD_freeCDict(cctx->cdictLocal); /* in case one already exists */
601  if (dict==NULL || dictSize==0) { /* no dictionary mode */
602  cctx->cdictLocal = NULL;
603  cctx->cdict = NULL;
604  } else {
605  ZSTD_compressionParameters const cParams =
608  dict, dictSize,
609  dictLoadMethod, dictContentType,
610  cParams, cctx->customMem);
611  cctx->cdict = cctx->cdictLocal;
612  if (cctx->cdictLocal == NULL)
613  return ERROR(memory_allocation);
614  }
615  return 0;
616 }
unsigned long long pledgedSrcSizePlusOne
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
ZSTD_CDict * cdictLocal
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(const ZSTD_CCtx_params *CCtxParams, U64 srcSizeHint, size_t dictSize)
const ZSTD_CDict * cdict
ZSTD_customMem customMem
ZSTD_cStreamStage streamStage
ZSTD_CCtx_params requestedParams
size_t ZSTD_freeCDict(ZSTD_CDict *cdict)

Referenced by ZSTD_CCtx_loadDictionary(), and ZSTD_CCtx_loadDictionary_byReference().

◆ ZSTD_CCtx_loadDictionary_byReference()

ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize 
)

Definition at line 618 of file zstd_compress.c.

620 {
622  cctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto);
623 }
size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_CCtx_refCDict()

size_t ZSTD_CCtx_refCDict ( ZSTD_CCtx cctx,
const ZSTD_CDict cdict 
)

Definition at line 632 of file zstd_compress.c.

633 {
634  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
635  cctx->cdict = cdict;
636  memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* exclusive */
637  return 0;
638 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_prefixDict prefixDict
const ZSTD_CDict * cdict
ZSTD_cStreamStage streamStage
#define memset(x, y, z)
Definition: compat.h:39

◆ ZSTD_CCtx_refPrefix()

size_t ZSTD_CCtx_refPrefix ( ZSTD_CCtx cctx,
const void prefix,
size_t  prefixSize 
)

Definition at line 640 of file zstd_compress.c.

641 {
642  return ZSTD_CCtx_refPrefix_advanced(cctx, prefix, prefixSize, ZSTD_dct_rawContent);
643 }
size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_CCtx_refPrefix_advanced()

size_t ZSTD_CCtx_refPrefix_advanced ( ZSTD_CCtx cctx,
const void prefix,
size_t  prefixSize,
ZSTD_dictContentType_e  dictContentType 
)

Definition at line 645 of file zstd_compress.c.

647 {
648  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
649  cctx->cdict = NULL; /* prefix discards any prior cdict */
650  cctx->prefixDict.dict = prefix;
651  cctx->prefixDict.dictSize = prefixSize;
652  cctx->prefixDict.dictContentType = dictContentType;
653  return 0;
654 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_prefixDict prefixDict
smooth NULL
Definition: ftsmooth.c:416
ZSTD_dictContentType_e dictContentType
const ZSTD_CDict * cdict
ZSTD_cStreamStage streamStage

Referenced by ZSTD_CCtx_refPrefix().

◆ ZSTD_CCtx_reset()

void ZSTD_CCtx_reset ( ZSTD_CCtx cctx)

ZSTD_CCtx_reset() : Also dumps dictionary

Definition at line 658 of file zstd_compress.c.

659 {
660  cctx->streamStage = zcss_init;
661  cctx->pledgedSrcSizePlusOne = 0;
662 }
unsigned long long pledgedSrcSizePlusOne
ZSTD_cStreamStage streamStage

Referenced by ZSTD_compress_generic(), and ZSTD_compressStream_generic().

◆ ZSTD_CCtx_resetParameters()

size_t ZSTD_CCtx_resetParameters ( ZSTD_CCtx cctx)

Definition at line 664 of file zstd_compress.c.

665 {
666  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
667  cctx->cdict = NULL;
668  return ZSTD_CCtxParams_reset(&cctx->requestedParams);
669 }
#define ERROR(name)
Definition: error_private.h:53
smooth NULL
Definition: ftsmooth.c:416
size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params *params)
const ZSTD_CDict * cdict
ZSTD_cStreamStage streamStage
ZSTD_CCtx_params requestedParams

Referenced by ZSTD_initCCtx().

◆ ZSTD_CCtx_setParameter()

size_t ZSTD_CCtx_setParameter ( ZSTD_CCtx cctx,
ZSTD_cParameter  param,
unsigned  value 
)

Definition at line 268 of file zstd_compress.c.

269 {
270  DEBUGLOG(4, "ZSTD_CCtx_setParameter (%u, %u)", (U32)param, value);
271  if (cctx->streamStage != zcss_init) {
273  cctx->cParamsChanged = 1;
274  } else {
275  return ERROR(stage_wrong);
276  } }
277 
278  switch(param)
279  {
280  case ZSTD_p_format :
282 
283  case ZSTD_p_compressionLevel:
284  if (cctx->cdict) return ERROR(stage_wrong);
286 
287  case ZSTD_p_windowLog:
288  case ZSTD_p_hashLog:
289  case ZSTD_p_chainLog:
290  case ZSTD_p_searchLog:
291  case ZSTD_p_minMatch:
292  case ZSTD_p_targetLength:
293  case ZSTD_p_compressionStrategy:
294  if (cctx->cdict) return ERROR(stage_wrong);
296 
297  case ZSTD_p_contentSizeFlag:
298  case ZSTD_p_checksumFlag:
299  case ZSTD_p_dictIDFlag:
301 
302  case ZSTD_p_forceMaxWindow : /* Force back-references to remain < windowSize,
303  * even when referencing into Dictionary content.
304  * default : 0 when using a CDict, 1 when using a Prefix */
306 
307  case ZSTD_p_forceAttachDict:
309 
310  case ZSTD_p_nbWorkers:
311  if ((value>0) && cctx->staticSize) {
312  return ERROR(parameter_unsupported); /* MT not compatible with static alloc */
313  }
315 
316  case ZSTD_p_jobSize:
317  case ZSTD_p_overlapSizeLog:
319 
320  case ZSTD_p_enableLongDistanceMatching:
321  case ZSTD_p_ldmHashLog:
322  case ZSTD_p_ldmMinMatch:
323  case ZSTD_p_ldmBucketSizeLog:
324  case ZSTD_p_ldmHashEveryLog:
325  if (cctx->cdict) return ERROR(stage_wrong);
327 
328  default: return ERROR(parameter_unsupported);
329  }
330 }
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, unsigned value)
GLfloat param
Definition: glext.h:5796
const ZSTD_CDict * cdict
ZSTD_cStreamStage streamStage
ZSTD_CCtx_params requestedParams
static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)

◆ ZSTD_CCtx_setParametersUsingCCtxParams()

size_t ZSTD_CCtx_setParametersUsingCCtxParams ( ZSTD_CCtx cctx,
const ZSTD_CCtx_params *  params 
)

ZSTD_CCtx_setParametersUsingCCtxParams() : just applies params into cctx no action is performed, parameters are merely stored. If ZSTDMT is enabled, parameters are pushed to cctx->mtctx. This is possible even if a compression is ongoing. In which case, new parameters will be applied on the fly, starting with next compression job.

Definition at line 574 of file zstd_compress.c.

576 {
577  DEBUGLOG(4, "ZSTD_CCtx_setParametersUsingCCtxParams");
578  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
579  if (cctx->cdict) return ERROR(stage_wrong);
580 
581  cctx->requestedParams = *params;
582  return 0;
583 }
#define ERROR(name)
Definition: error_private.h:53
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
const ZSTD_CDict * cdict
ZSTD_cStreamStage streamStage
ZSTD_CCtx_params requestedParams

◆ ZSTD_CCtx_setPledgedSrcSize()

ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize ( ZSTD_CCtx cctx,
unsigned long long  pledgedSrcSize 
)

Definition at line 585 of file zstd_compress.c.

586 {
587  DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %u bytes", (U32)pledgedSrcSize);
588  if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
589  cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
590  return 0;
591 }
unsigned long long pledgedSrcSizePlusOne
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_cStreamStage streamStage

◆ ZSTD_CCtxParam_getParameter()

size_t ZSTD_CCtxParam_getParameter ( ZSTD_CCtx_params *  CCtxParams,
ZSTD_cParameter  param,
unsigned value 
)

Definition at line 480 of file zstd_compress.c.

482 {
483  switch(param)
484  {
485  case ZSTD_p_format :
486  *value = CCtxParams->format;
487  break;
488  case ZSTD_p_compressionLevel :
489  *value = CCtxParams->compressionLevel;
490  break;
491  case ZSTD_p_windowLog :
492  *value = CCtxParams->cParams.windowLog;
493  break;
494  case ZSTD_p_hashLog :
495  *value = CCtxParams->cParams.hashLog;
496  break;
497  case ZSTD_p_chainLog :
498  *value = CCtxParams->cParams.chainLog;
499  break;
500  case ZSTD_p_searchLog :
501  *value = CCtxParams->cParams.searchLog;
502  break;
503  case ZSTD_p_minMatch :
504  *value = CCtxParams->cParams.searchLength;
505  break;
506  case ZSTD_p_targetLength :
507  *value = CCtxParams->cParams.targetLength;
508  break;
509  case ZSTD_p_compressionStrategy :
510  *value = (unsigned)CCtxParams->cParams.strategy;
511  break;
512  case ZSTD_p_contentSizeFlag :
513  *value = CCtxParams->fParams.contentSizeFlag;
514  break;
515  case ZSTD_p_checksumFlag :
516  *value = CCtxParams->fParams.checksumFlag;
517  break;
518  case ZSTD_p_dictIDFlag :
519  *value = !CCtxParams->fParams.noDictIDFlag;
520  break;
521  case ZSTD_p_forceMaxWindow :
522  *value = CCtxParams->forceWindow;
523  break;
524  case ZSTD_p_forceAttachDict :
525  *value = CCtxParams->attachDictPref;
526  break;
527  case ZSTD_p_nbWorkers :
528 #ifndef ZSTD_MULTITHREAD
529  assert(CCtxParams->nbWorkers == 0);
530 #endif
531  *value = CCtxParams->nbWorkers;
532  break;
533  case ZSTD_p_jobSize :
534 #ifndef ZSTD_MULTITHREAD
535  return ERROR(parameter_unsupported);
536 #else
537  *value = CCtxParams->jobSize;
538  break;
539 #endif
540  case ZSTD_p_overlapSizeLog :
541 #ifndef ZSTD_MULTITHREAD
542  return ERROR(parameter_unsupported);
543 #else
544  *value = CCtxParams->overlapSizeLog;
545  break;
546 #endif
547  case ZSTD_p_enableLongDistanceMatching :
548  *value = CCtxParams->ldmParams.enableLdm;
549  break;
550  case ZSTD_p_ldmHashLog :
551  *value = CCtxParams->ldmParams.hashLog;
552  break;
553  case ZSTD_p_ldmMinMatch :
554  *value = CCtxParams->ldmParams.minMatchLength;
555  break;
556  case ZSTD_p_ldmBucketSizeLog :
557  *value = CCtxParams->ldmParams.bucketSizeLog;
558  break;
559  case ZSTD_p_ldmHashEveryLog :
560  *value = CCtxParams->ldmParams.hashEveryLog;
561  break;
562  default: return ERROR(parameter_unsupported);
563  }
564  return 0;
565 }
#define ERROR(name)
Definition: error_private.h:53
#define assert(x)
Definition: debug.h:53
GLfloat param
Definition: glext.h:5796
static unsigned(__cdecl *hash_bstr)(bstr_t s)

Referenced by ZSTD_CCtx_getParameter().

◆ ZSTD_CCtxParam_setParameter()

size_t ZSTD_CCtxParam_setParameter ( ZSTD_CCtx_params *  CCtxParams,
ZSTD_cParameter  param,
unsigned  value 
)

Definition at line 332 of file zstd_compress.c.

334 {
335  DEBUGLOG(4, "ZSTD_CCtxParam_setParameter (%u, %u)", (U32)param, value);
336  switch(param)
337  {
338  case ZSTD_p_format :
339  if (value > (unsigned)ZSTD_f_zstd1_magicless)
340  return ERROR(parameter_unsupported);
341  CCtxParams->format = (ZSTD_format_e)value;
342  return (size_t)CCtxParams->format;
343 
344  case ZSTD_p_compressionLevel : {
345  int cLevel = (int)value; /* cast expected to restore negative sign */
346  if (cLevel > ZSTD_maxCLevel()) cLevel = ZSTD_maxCLevel();
347  if (cLevel) { /* 0 : does not change current level */
348  CCtxParams->compressionLevel = cLevel;
349  }
350  if (CCtxParams->compressionLevel >= 0) return CCtxParams->compressionLevel;
351  return 0; /* return type (size_t) cannot represent negative values */
352  }
353 
354  case ZSTD_p_windowLog :
355  if (value>0) /* 0 => use default */
356  CLAMPCHECK(value, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
357  CCtxParams->cParams.windowLog = value;
358  return CCtxParams->cParams.windowLog;
359 
360  case ZSTD_p_hashLog :
361  if (value>0) /* 0 => use default */
362  CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
363  CCtxParams->cParams.hashLog = value;
364  return CCtxParams->cParams.hashLog;
365 
366  case ZSTD_p_chainLog :
367  if (value>0) /* 0 => use default */
368  CLAMPCHECK(value, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
369  CCtxParams->cParams.chainLog = value;
370  return CCtxParams->cParams.chainLog;
371 
372  case ZSTD_p_searchLog :
373  if (value>0) /* 0 => use default */
374  CLAMPCHECK(value, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX);
375  CCtxParams->cParams.searchLog = value;
376  return value;
377 
378  case ZSTD_p_minMatch :
379  if (value>0) /* 0 => use default */
380  CLAMPCHECK(value, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX);
381  CCtxParams->cParams.searchLength = value;
382  return CCtxParams->cParams.searchLength;
383 
384  case ZSTD_p_targetLength :
385  /* all values are valid. 0 => use default */
386  CCtxParams->cParams.targetLength = value;
387  return CCtxParams->cParams.targetLength;
388 
389  case ZSTD_p_compressionStrategy :
390  if (value>0) /* 0 => use default */
391  CLAMPCHECK(value, (unsigned)ZSTD_fast, (unsigned)ZSTD_btultra);
392  CCtxParams->cParams.strategy = (ZSTD_strategy)value;
393  return (size_t)CCtxParams->cParams.strategy;
394 
395  case ZSTD_p_contentSizeFlag :
396  /* Content size written in frame header _when known_ (default:1) */
397  DEBUGLOG(4, "set content size flag = %u", (value>0));
398  CCtxParams->fParams.contentSizeFlag = value > 0;
399  return CCtxParams->fParams.contentSizeFlag;
400 
401  case ZSTD_p_checksumFlag :
402  /* A 32-bits content checksum will be calculated and written at end of frame (default:0) */
403  CCtxParams->fParams.checksumFlag = value > 0;
404  return CCtxParams->fParams.checksumFlag;
405 
406  case ZSTD_p_dictIDFlag : /* When applicable, dictionary's dictID is provided in frame header (default:1) */
407  DEBUGLOG(4, "set dictIDFlag = %u", (value>0));
408  CCtxParams->fParams.noDictIDFlag = !value;
409  return !CCtxParams->fParams.noDictIDFlag;
410 
411  case ZSTD_p_forceMaxWindow :
412  CCtxParams->forceWindow = (value > 0);
413  return CCtxParams->forceWindow;
414 
415  case ZSTD_p_forceAttachDict :
416  CCtxParams->attachDictPref = value ?
419  return CCtxParams->attachDictPref;
420 
421  case ZSTD_p_nbWorkers :
422 #ifndef ZSTD_MULTITHREAD
423  if (value>0) return ERROR(parameter_unsupported);
424  return 0;
425 #else
426  return ZSTDMT_CCtxParam_setNbWorkers(CCtxParams, value);
427 #endif
428 
429  case ZSTD_p_jobSize :
430 #ifndef ZSTD_MULTITHREAD
431  return ERROR(parameter_unsupported);
432 #else
433  return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_jobSize, value);
434 #endif
435 
436  case ZSTD_p_overlapSizeLog :
437 #ifndef ZSTD_MULTITHREAD
438  return ERROR(parameter_unsupported);
439 #else
440  return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_overlapSectionLog, value);
441 #endif
442 
443  case ZSTD_p_enableLongDistanceMatching :
444  CCtxParams->ldmParams.enableLdm = (value>0);
445  return CCtxParams->ldmParams.enableLdm;
446 
447  case ZSTD_p_ldmHashLog :
448  if (value>0) /* 0 ==> auto */
449  CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
450  CCtxParams->ldmParams.hashLog = value;
451  return CCtxParams->ldmParams.hashLog;
452 
453  case ZSTD_p_ldmMinMatch :
454  if (value>0) /* 0 ==> default */
455  CLAMPCHECK(value, ZSTD_LDM_MINMATCH_MIN, ZSTD_LDM_MINMATCH_MAX);
456  CCtxParams->ldmParams.minMatchLength = value;
457  return CCtxParams->ldmParams.minMatchLength;
458 
459  case ZSTD_p_ldmBucketSizeLog :
460  if (value > ZSTD_LDM_BUCKETSIZELOG_MAX)
461  return ERROR(parameter_outOfBound);
462  CCtxParams->ldmParams.bucketSizeLog = value;
463  return CCtxParams->ldmParams.bucketSizeLog;
464 
465  case ZSTD_p_ldmHashEveryLog :
466  if (value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
467  return ERROR(parameter_outOfBound);
468  CCtxParams->ldmParams.hashEveryLog = value;
469  return CCtxParams->ldmParams.hashEveryLog;
470 
471  default: return ERROR(parameter_unsupported);
472  }
473 }
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLfloat param
Definition: glext.h:5796
#define CLAMPCHECK(val, min, max)
GLsizei const GLfloat * value
Definition: glext.h:6069
int ZSTD_maxCLevel(void)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by ZSTD_CCtx_setParameter().

◆ ZSTD_CCtxParams_init()

size_t ZSTD_CCtxParams_init ( ZSTD_CCtx_params *  cctxParams,
int  compressionLevel 
)

Definition at line 196 of file zstd_compress.c.

196  {
197  if (!cctxParams) { return ERROR(GENERIC); }
198  memset(cctxParams, 0, sizeof(*cctxParams));
199  cctxParams->compressionLevel = compressionLevel;
200  cctxParams->fParams.contentSizeFlag = 1;
201  return 0;
202 }
#define ERROR(name)
Definition: error_private.h:53
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ZSTD_CCtxParams_reset(), ZSTD_initCStream_srcSize(), and ZSTD_initCStream_usingDict().

◆ ZSTD_CCtxParams_init_advanced()

size_t ZSTD_CCtxParams_init_advanced ( ZSTD_CCtx_params *  cctxParams,
ZSTD_parameters  params 
)

Definition at line 204 of file zstd_compress.c.

205 {
206  if (!cctxParams) { return ERROR(GENERIC); }
207  CHECK_F( ZSTD_checkCParams(params.cParams) );
208  memset(cctxParams, 0, sizeof(*cctxParams));
209  cctxParams->cParams = params.cParams;
210  cctxParams->fParams = params.fParams;
211  cctxParams->compressionLevel = ZSTD_CLEVEL_DEFAULT; /* should not matter, as all cParams are presumed properly defined */
212  assert(!ZSTD_checkCParams(params.cParams));
213  return 0;
214 }
#define ZSTD_CLEVEL_DEFAULT
Definition: zstd.h:89
#define ERROR(name)
Definition: error_private.h:53
#define assert(x)
Definition: debug.h:53
GLenum const GLfloat * params
Definition: glext.h:5645
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
#define memset(x, y, z)
Definition: compat.h:39

◆ ZSTD_CCtxParams_reset()

size_t ZSTD_CCtxParams_reset ( ZSTD_CCtx_params *  params)

Definition at line 191 of file zstd_compress.c.

192 {
194 }
#define ZSTD_CLEVEL_DEFAULT
Definition: zstd.h:89
GLenum const GLfloat * params
Definition: glext.h:5645
size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params *cctxParams, int compressionLevel)

Referenced by ZSTD_CCtx_resetParameters().

◆ ZSTD_checkCParams()

size_t ZSTD_checkCParams ( ZSTD_compressionParameters  cParams)

ZSTD_checkCParams() : control CParam values remain within authorized range.

Returns
: 0, or an error code if one value is beyond authorized range

Definition at line 674 of file zstd_compress.c.

675 {
676  CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
677  CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
678  CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
679  CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX);
680  CLAMPCHECK(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX);
681  ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
682  if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
683  return ERROR(parameter_outOfBound);
684  if ((U32)(cParams.strategy) > (U32)ZSTD_btultra)
685  return ERROR(parameter_unsupported);
686  return 0;
687 }
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
#define CLAMPCHECK(val, min, max)

Referenced by ZSTD_adjustCParams_internal(), ZSTD_assignParamsToCCtxParams(), ZSTD_CCtxParams_init_advanced(), ZSTD_compress_advanced(), ZSTD_compressBegin_advanced_internal(), ZSTD_compressBegin_internal(), ZSTD_getBlockSize(), ZSTD_getCParamsFromCCtxParams(), ZSTD_initCDict_internal(), ZSTD_initCStream_advanced(), ZSTD_initCStream_internal(), ZSTD_makeCCtxParamsFromCParams(), ZSTD_resetCCtx_internal(), and ZSTD_resetCStream_internal().

◆ ZSTD_checkDictNCount()

static size_t ZSTD_checkDictNCount ( short normalizedCounter,
unsigned  dictMaxSymbolValue,
unsigned  maxSymbolValue 
)
static

Definition at line 2811 of file zstd_compress.c.

2811  {
2812  U32 s;
2813  if (dictMaxSymbolValue < maxSymbolValue) return ERROR(dictionary_corrupted);
2814  for (s = 0; s <= maxSymbolValue; ++s) {
2815  if (normalizedCounter[s] == 0) return ERROR(dictionary_corrupted);
2816  }
2817  return 0;
2818 }
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
GLdouble s
Definition: gl.h:2039

Referenced by ZSTD_loadZstdDictionary().

◆ ZSTD_clampCParams()

static ZSTD_compressionParameters ZSTD_clampCParams ( ZSTD_compressionParameters  cParams)
static

ZSTD_clampCParams() : make CParam values within valid range.

Returns
: valid CParams

Definition at line 693 of file zstd_compress.c.

694 {
695 # define CLAMP(val,min,max) { \
696  if (val<min) val=min; \
697  else if (val>max) val=max; \
698  }
699  CLAMP(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
700  CLAMP(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
701  CLAMP(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
702  CLAMP(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX);
703  CLAMP(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX);
704  ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
705  if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
706  cParams.targetLength = ZSTD_TARGETLENGTH_MAX;
707  CLAMP(cParams.strategy, ZSTD_fast, ZSTD_btultra);
708  return cParams;
709 }
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
#define CLAMP(val, min, max)

Referenced by ZSTD_adjustCParams().

◆ ZSTD_compress()

size_t ZSTD_compress ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compress() : Compresses src content as a single zstd compressed frame into already allocated dst. Hint : compression runs faster if dstCapacity >= ZSTD_compressBound(srcSize).

Returns
: compressed size written into dst (<= `dstCapacity), or an error code if it fails (which can be tested using ZSTD_isError()).

Definition at line 3171 of file zstd_compress.c.

3174 {
3175  size_t result;
3176  ZSTD_CCtx ctxBody;
3177  ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
3178  result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
3179  ZSTD_freeCCtxContent(&ctxBody); /* can't free ctxBody itself, as it's on stack; free only heap content */
3180  return result;
3181 }
size_t ZSTD_compressCCtx(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
static void ZSTD_freeCCtxContent(ZSTD_CCtx *cctx)
GLenum src
Definition: glext.h:6340
static void ZSTD_initCCtx(ZSTD_CCtx *cctx, ZSTD_customMem memManager)
Definition: zstd_compress.c:58
GLenum GLenum dst
Definition: glext.h:6340
GLuint64EXT * result
Definition: glext.h:11304

◆ ZSTD_compress_advanced()

size_t ZSTD_compress_advanced ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
ZSTD_parameters  params 
)

Definition at line 3119 of file zstd_compress.c.

3124 {
3125  DEBUGLOG(4, "ZSTD_compress_advanced");
3126  CHECK_F(ZSTD_checkCParams(params.cParams));
3127  return ZSTD_compress_internal(cctx,
3128  dst, dstCapacity,
3129  src, srcSize,
3130  dict, dictSize,
3131  params);
3132 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
static size_t ZSTD_compress_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params)
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_compress_advanced_internal()

size_t ZSTD_compress_advanced_internal ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
ZSTD_CCtx_params  params 
)

Definition at line 3135 of file zstd_compress.c.

3141 {
3142  DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (U32)srcSize);
3144  dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
3145  params, srcSize, ZSTDb_not_buffered) );
3146  return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
3147 }
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
#define CHECK_F(f)
Definition: fse_compress.c:661
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_compressBegin_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
size_t ZSTD_compressEnd(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)

Referenced by ZSTD_compress_internal(), and ZSTD_compress_usingDict().

◆ ZSTD_compress_frameChunk()

static size_t ZSTD_compress_frameChunk ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
U32  lastFrameChunk 
)
static

ZSTD_compress_frameChunk() : Compress a chunk of data into one or multiple blocks. All blocks will be terminated, all input will be consumed. Function will issue an error if there is not enough dstCapacity to hold the compressed content. Frame is supposed already started (header already produced)

Returns
: compressed size, or an error code

Definition at line 2525 of file zstd_compress.c.

2529 {
2530  size_t blockSize = cctx->blockSize;
2531  size_t remaining = srcSize;
2532  const BYTE* ip = (const BYTE*)src;
2533  BYTE* const ostart = (BYTE*)dst;
2534  BYTE* op = ostart;
2535  U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog;
2536  assert(cctx->appliedParams.cParams.windowLog <= 31);
2537 
2538  DEBUGLOG(5, "ZSTD_compress_frameChunk (blockSize=%u)", (U32)blockSize);
2539  if (cctx->appliedParams.fParams.checksumFlag && srcSize)
2540  XXH64_update(&cctx->xxhState, src, srcSize);
2541 
2542  while (remaining) {
2543  ZSTD_matchState_t* const ms = &cctx->blockState.matchState;
2544  U32 const lastBlock = lastFrameChunk & (blockSize >= remaining);
2545 
2546  if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE)
2547  return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */
2548  if (remaining < blockSize) blockSize = remaining;
2549 
2550  if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) {
2551  U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy);
2552  U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip);
2553  ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30);
2554  ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30);
2555  ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31);
2556  ZSTD_reduceIndex(cctx, correction);
2557  if (ms->nextToUpdate < correction) ms->nextToUpdate = 0;
2558  else ms->nextToUpdate -= correction;
2559  ms->loadedDictEnd = 0;
2560  ms->dictMatchState = NULL;
2561  }
2562  ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState);
2563  if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit;
2564 
2565  { size_t cSize = ZSTD_compressBlock_internal(cctx,
2567  ip, blockSize);
2568  if (ZSTD_isError(cSize)) return cSize;
2569 
2570  if (cSize == 0) { /* block is not compressible */
2571  cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
2572  if (ZSTD_isError(cSize)) return cSize;
2573  } else {
2574  U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
2575  MEM_writeLE24(op, cBlockHeader24);
2576  cSize += ZSTD_blockHeaderSize;
2577  }
2578 
2579  ip += blockSize;
2580  assert(remaining >= blockSize);
2581  remaining -= blockSize;
2582  op += cSize;
2583  assert(dstCapacity >= cSize);
2584  dstCapacity -= cSize;
2585  DEBUGLOG(5, "ZSTD_compress_frameChunk: adding a block of size %u",
2586  (U32)cSize);
2587  } }
2588 
2589  if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending;
2590  return op-ostart;
2591 }
static size_t ZSTD_compressBlock_internal(ZSTD_CCtx *zc, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
#define DEBUGLOG(l,...)
Definition: debug.h:115
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
ZSTD_compressionStage_e stage
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
ZSTD_blockState_t blockState
MEM_STATIC void ZSTD_window_enforceMaxDist(ZSTD_window_t *window, void const *srcEnd, U32 maxDist, U32 *loadedDictEndPtr, const ZSTD_matchState_t **dictMatchStatePtr)
Definition: dhcpd.h:61
const ZSTD_matchState_t * dictMatchState
XXH64_state_t xxhState
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:780
static size_t ZSTD_noCompressBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 lastBlock)
MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window, void const *srcEnd)
#define MIN_CBLOCK_SIZE
Definition: zstd_internal.h:89
unsigned char BYTE
Definition: mem.h:68
ZSTD_matchState_t matchState
GLenum src
Definition: glext.h:6340
MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t *window, U32 cycleLog, U32 maxDist, void const *src)
#define ZSTD_isError
static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
static void ZSTD_reduceIndex(ZSTD_CCtx *zc, const U32 reducerValue)
GLenum GLenum dst
Definition: glext.h:6340
MEM_STATIC void MEM_writeLE24(void *memPtr, U32 val)
Definition: mem.h:267
UINT op
Definition: effect.c:223

Referenced by ZSTD_compressContinue_internal().

◆ ZSTD_compress_generic()

size_t ZSTD_compress_generic ( ZSTD_CCtx cctx,
ZSTD_outBuffer output,
ZSTD_inBuffer input,
ZSTD_EndDirective  endOp 
)

Definition at line 3780 of file zstd_compress.c.

3784 {
3785  DEBUGLOG(5, "ZSTD_compress_generic, endOp=%u ", (U32)endOp);
3786  /* check conditions */
3787  if (output->pos > output->size) return ERROR(GENERIC);
3788  if (input->pos > input->size) return ERROR(GENERIC);
3789  assert(cctx!=NULL);
3790 
3791  /* transparent initialization stage */
3792  if (cctx->streamStage == zcss_init) {
3793  ZSTD_CCtx_params params = cctx->requestedParams;
3794  ZSTD_prefixDict const prefixDict = cctx->prefixDict;
3795  memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */
3796  assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */
3797  DEBUGLOG(4, "ZSTD_compress_generic : transparent init stage");
3798  if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
3800  &cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/);
3801 
3802 
3803 #ifdef ZSTD_MULTITHREAD
3804  if ((cctx->pledgedSrcSizePlusOne-1) <= ZSTDMT_JOBSIZE_MIN) {
3805  params.nbWorkers = 0; /* do not invoke multi-threading when src size is too small */
3806  }
3807  if (params.nbWorkers > 0) {
3808  /* mt context creation */
3809  if (cctx->mtctx == NULL) {
3810  DEBUGLOG(4, "ZSTD_compress_generic: creating new mtctx for nbWorkers=%u",
3811  params.nbWorkers);
3812  cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbWorkers, cctx->customMem);
3813  if (cctx->mtctx == NULL) return ERROR(memory_allocation);
3814  }
3815  /* mt compression */
3816  DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbWorkers=%u", params.nbWorkers);
3817  CHECK_F( ZSTDMT_initCStream_internal(
3818  cctx->mtctx,
3819  prefixDict.dict, prefixDict.dictSize, ZSTD_dct_rawContent,
3820  cctx->cdict, params, cctx->pledgedSrcSizePlusOne-1) );
3821  cctx->streamStage = zcss_load;
3822  cctx->appliedParams.nbWorkers = params.nbWorkers;
3823  } else
3824 #endif
3826  prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
3827  cctx->cdict,
3828  params, cctx->pledgedSrcSizePlusOne-1) );
3829  assert(cctx->streamStage == zcss_load);
3830  assert(cctx->appliedParams.nbWorkers == 0);
3831  } }
3832 
3833  /* compression stage */
3834 #ifdef ZSTD_MULTITHREAD
3835  if (cctx->appliedParams.nbWorkers > 0) {
3836  if (cctx->cParamsChanged) {
3837  ZSTDMT_updateCParams_whileCompressing(cctx->mtctx, &cctx->requestedParams);
3838  cctx->cParamsChanged = 0;
3839  }
3840  { size_t const flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp);
3841  if ( ZSTD_isError(flushMin)
3842  || (endOp == ZSTD_e_end && flushMin == 0) ) { /* compression completed */
3843  ZSTD_CCtx_reset(cctx);
3844  }
3845  DEBUGLOG(5, "completed ZSTD_compress_generic delegating to ZSTDMT_compressStream_generic");
3846  return flushMin;
3847  } }
3848 #endif
3849  CHECK_F( ZSTD_compressStream_generic(cctx, output, input, endOp) );
3850  DEBUGLOG(5, "completed ZSTD_compress_generic");
3851  return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */
3852 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
unsigned long long pledgedSrcSizePlusOne
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
ZSTD_prefixDict prefixDict
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
#define CHECK_F(f)
Definition: fse_compress.c:661
ZSTD_dictContentType_e dictContentType
void ZSTD_CCtx_reset(ZSTD_CCtx *cctx)
size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
#define ZSTD_isError
GLenum GLenum GLenum input
Definition: glext.h:9031
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(const ZSTD_CCtx_params *CCtxParams, U64 srcSizeHint, size_t dictSize)
const ZSTD_CDict * cdict
ZSTD_customMem customMem
ZSTD_cStreamStage streamStage
ZSTD_CCtx_params requestedParams
#define memset(x, y, z)
Definition: compat.h:39
static size_t ZSTD_resetCStream_internal(ZSTD_CStream *cctx, 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)

Referenced by ZSTD_compress_generic_simpleArgs().

◆ ZSTD_compress_generic_simpleArgs()

size_t ZSTD_compress_generic_simpleArgs ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
size_t dstPos,
const void src,
size_t  srcSize,
size_t srcPos,
ZSTD_EndDirective  endOp 
)

Definition at line 3854 of file zstd_compress.c.

3859 {
3860  ZSTD_outBuffer output = { dst, dstCapacity, *dstPos };
3861  ZSTD_inBuffer input = { src, srcSize, *srcPos };
3862  /* ZSTD_compress_generic() will check validity of dstPos and srcPos */
3863  size_t const cErr = ZSTD_compress_generic(cctx, &output, &input, endOp);
3864  *dstPos = output.pos;
3865  *srcPos = input.pos;
3866  return cErr;
3867 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_generic(ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
GLenum GLenum GLenum input
Definition: glext.h:9031
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_compress_insertDictionary()

static size_t ZSTD_compress_insertDictionary ( ZSTD_compressedBlockState_t bs,
ZSTD_matchState_t ms,
const ZSTD_CCtx_params *  params,
const void dict,
size_t  dictSize,
ZSTD_dictContentType_e  dictContentType,
ZSTD_dictTableLoadMethod_e  dtlm,
void workspace 
)
static

ZSTD_compress_insertDictionary() :

Returns
: dictID, or an error code

Definition at line 2926 of file zstd_compress.c.

2933 {
2934  DEBUGLOG(4, "ZSTD_compress_insertDictionary (dictSize=%u)", (U32)dictSize);
2935  if ((dict==NULL) || (dictSize<=8)) return 0;
2936 
2938 
2939  /* dict restricted modes */
2940  if (dictContentType == ZSTD_dct_rawContent)
2941  return ZSTD_loadDictionaryContent(ms, params, dict, dictSize, dtlm);
2942 
2943  if (MEM_readLE32(dict) != ZSTD_MAGIC_DICTIONARY) {
2944  if (dictContentType == ZSTD_dct_auto) {
2945  DEBUGLOG(4, "raw content dictionary detected");
2946  return ZSTD_loadDictionaryContent(ms, params, dict, dictSize, dtlm);
2947  }
2948  if (dictContentType == ZSTD_dct_fullDict)
2949  return ERROR(dictionary_wrong);
2950  assert(0); /* impossible */
2951  }
2952 
2953  /* dict as full zstd dictionary */
2954  return ZSTD_loadZstdDictionary(bs, ms, params, dict, dictSize, dtlm, workspace);
2955 }
static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t *bs, ZSTD_matchState_t *ms, ZSTD_CCtx_params const *params, const void *dict, size_t dictSize, ZSTD_dictTableLoadMethod_e dtlm, void *workspace)
static void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t *bs)
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t *ms, ZSTD_CCtx_params const *params, const void *src, size_t srcSize, ZSTD_dictTableLoadMethod_e dtlm)
smooth NULL
Definition: ftsmooth.c:416
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by ZSTD_compressBegin_internal(), and ZSTD_initCDict_internal().

◆ ZSTD_compress_internal()

static size_t ZSTD_compress_internal ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
ZSTD_parameters  params 
)
static

Definition at line 3103 of file zstd_compress.c.

3108 {
3109  ZSTD_CCtx_params const cctxParams =
3111  DEBUGLOG(4, "ZSTD_compress_internal");
3112  return ZSTD_compress_advanced_internal(cctx,
3113  dst, dstCapacity,
3114  src, srcSize,
3115  dict, dictSize,
3116  cctxParams);
3117 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_advanced_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_CCtx_params params)
GLenum GLenum dst
Definition: glext.h:6340
ZSTD_CCtx_params requestedParams

Referenced by ZSTD_compress_advanced().

◆ ZSTD_compress_usingCDict()

size_t ZSTD_compress_usingCDict ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_CDict cdict 
)

ZSTD_compress_usingCDict() : Compression using a digested Dictionary. Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. Note that compression parameters are decided at CDict creation time while frame parameters are hardcoded

Definition at line 3428 of file zstd_compress.c.

3432 {
3433  ZSTD_frameParameters const fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ };
3434  return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
3435 }
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams)
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_compress_usingCDict_advanced()

size_t ZSTD_compress_usingCDict_advanced ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_CDict cdict,
ZSTD_frameParameters  fParams 
)

Definition at line 3414 of file zstd_compress.c.

3418 {
3419  CHECK_F (ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, srcSize)); /* will check if cdict != NULL */
3420  return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
3421 }
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx *const cctx, const ZSTD_CDict *const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
size_t ZSTD_compressEnd(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)

Referenced by ZSTD_compress_usingCDict().

◆ ZSTD_compress_usingDict()

size_t ZSTD_compress_usingDict ( ZSTD_CCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
int  compressionLevel 
)

ZSTD_compress_usingDict() : Compression using a predefined Dictionary (see dictBuilder/zdict.h). Note : This function loads the dictionary, resulting in significant startup delay. Note : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 3149 of file zstd_compress.c.

3154 {
3155  ZSTD_parameters const params = ZSTD_getParams(compressionLevel, srcSize + (!srcSize), dict ? dictSize : 0);
3156  ZSTD_CCtx_params cctxParams = ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params);
3157  assert(params.fParams.contentSizeFlag == 1);
3158  return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, cctxParams);
3159 }
#define assert(x)
Definition: debug.h:53
GLenum const GLfloat * params
Definition: glext.h:5645
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_advanced_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_CCtx_params params)
GLenum GLenum dst
Definition: glext.h:6340
ZSTD_CCtx_params requestedParams
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)

Referenced by ZSTD_compressCCtx().

◆ ZSTD_compressBegin()

size_t ZSTD_compressBegin ( ZSTD_CCtx cctx,
int  compressionLevel 
)

Definition at line 3031 of file zstd_compress.c.

3032 {
3033  return ZSTD_compressBegin_usingDict(cctx, NULL, 0, compressionLevel);
3034 }
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, int compressionLevel)
smooth NULL
Definition: ftsmooth.c:416

◆ ZSTD_compressBegin_advanced()

size_t ZSTD_compressBegin_advanced ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize,
ZSTD_parameters  params,
unsigned long long  pledgedSrcSize 
)

ZSTD_compressBegin_advanced() :

Returns
: 0, or an error code

Definition at line 3009 of file zstd_compress.c.

3012 {
3013  ZSTD_CCtx_params const cctxParams =
3016  dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast,
3017  NULL /*cdict*/,
3018  cctxParams, pledgedSrcSize);
3019 }
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, unsigned long long pledgedSrcSize)
ZSTD_CCtx_params requestedParams

◆ ZSTD_compressBegin_advanced_internal()

size_t ZSTD_compressBegin_advanced_internal ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize,
ZSTD_dictContentType_e  dictContentType,
ZSTD_dictTableLoadMethod_e  dtlm,
const ZSTD_CDict cdict,
ZSTD_CCtx_params  params,
unsigned long long  pledgedSrcSize 
)

Definition at line 2989 of file zstd_compress.c.

2996 {
2997  DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params.cParams.windowLog);
2998  /* compression parameters verification and optimization */
2999  CHECK_F( ZSTD_checkCParams(params.cParams) );
3000  return ZSTD_compressBegin_internal(cctx,
3001  dict, dictSize, dictContentType, dtlm,
3002  cdict,
3003  params, pledgedSrcSize,
3005 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
static size_t ZSTD_compressBegin_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)

Referenced by ZSTD_compressBegin_advanced().

◆ ZSTD_compressBegin_internal()

static size_t ZSTD_compressBegin_internal ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize,
ZSTD_dictContentType_e  dictContentType,
ZSTD_dictTableLoadMethod_e  dtlm,
const ZSTD_CDict cdict,
ZSTD_CCtx_params  params,
U64  pledgedSrcSize,
ZSTD_buffered_policy_e  zbuff 
)
static

ZSTD_compressBegin_internal() :

Returns
: 0, or an error code

Definition at line 2959 of file zstd_compress.c.

2966 {
2967  DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params.cParams.windowLog);
2968  /* params are supposed to be fully validated at this point */
2970  assert(!((dict) && (cdict))); /* either dict or cdict, not both */
2971 
2972  if (cdict && cdict->dictContentSize>0) {
2973  return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
2974  }
2975 
2976  CHECK_F( ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
2977  ZSTDcrp_continue, zbuff) );
2978  {
2979  size_t const dictID = ZSTD_compress_insertDictionary(
2981  &params, dict, dictSize, dictContentType, dtlm, cctx->entropyWorkspace);
2982  if (ZSTD_isError(dictID)) return dictID;
2983  assert(dictID <= (size_t)(U32)-1);
2984  cctx->dictID = (U32)dictID;
2985  }
2986  return 0;
2987 }
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
static size_t ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t *bs, ZSTD_matchState_t *ms, const ZSTD_CCtx_params *params, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, void *workspace)
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx *zc, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_compResetPolicy_e const crp, ZSTD_buffered_policy_e const zbuff)
ZSTD_blockState_t blockState
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
ZSTD_matchState_t matchState
#define ZSTD_isError
size_t dictContentSize
Definition: zstd_compress.c:44
static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
ZSTD_compressedBlockState_t * prevCBlock

Referenced by ZSTD_compress_advanced_internal(), ZSTD_compressBegin_advanced_internal(), ZSTD_compressBegin_usingCDict_advanced(), ZSTD_compressBegin_usingDict(), and ZSTD_resetCStream_internal().

◆ ZSTD_compressBegin_usingCDict()

size_t ZSTD_compressBegin_usingCDict ( ZSTD_CCtx cctx,
const ZSTD_CDict cdict 
)

Definition at line 3407 of file zstd_compress.c.

3408 {
3409  ZSTD_frameParameters const fParams = { 0 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ };
3410  DEBUGLOG(4, "ZSTD_compressBegin_usingCDict : dictIDFlag == %u", !fParams.noDictIDFlag);
3412 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define DEBUGLOG(l,...)
Definition: debug.h:115
size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx *const cctx, const ZSTD_CDict *const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)

◆ ZSTD_compressBegin_usingCDict_advanced()

size_t ZSTD_compressBegin_usingCDict_advanced ( ZSTD_CCtx *const  cctx,
const ZSTD_CDict *const  cdict,
ZSTD_frameParameters const  fParams,
unsigned long long const  pledgedSrcSize 
)

Definition at line 3378 of file zstd_compress.c.

3381 {
3382  DEBUGLOG(4, "ZSTD_compressBegin_usingCDict_advanced");
3383  if (cdict==NULL) return ERROR(dictionary_wrong);
3384  { ZSTD_CCtx_params params = cctx->requestedParams;
3385  params.cParams = ZSTD_getCParamsFromCDict(cdict);
3386  /* Increase window log to fit the entire dictionary and source if the
3387  * source size is known. Limit the increase to 19, which is the
3388  * window log for compression level 1 with the largest source size.
3389  */
3390  if (pledgedSrcSize != ZSTD_CONTENTSIZE_UNKNOWN) {
3391  U32 const limitedSrcSize = (U32)MIN(pledgedSrcSize, 1U << 19);
3392  U32 const limitedSrcLog = limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1;
3393  params.cParams.windowLog = MAX(params.cParams.windowLog, limitedSrcLog);
3394  }
3395  params.fParams = fParams;
3396  return ZSTD_compressBegin_internal(cctx,
3397  NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast,
3398  cdict,
3399  params, pledgedSrcSize,
3401  }
3402 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ERROR(name)
Definition: error_private.h:53
#define U(x)
Definition: wordpad.c:44
unsigned int U32
Definition: mem.h:77
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict *cdict)
T MAX(T a, T b)
Definition: polytest.cpp:85
static size_t ZSTD_compressBegin_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
MEM_STATIC U32 ZSTD_highbit32(U32 val)
ZSTD_CCtx_params requestedParams

Referenced by ZSTD_compress_usingCDict_advanced(), and ZSTD_compressBegin_usingCDict().

◆ ZSTD_compressBegin_usingDict()

size_t ZSTD_compressBegin_usingDict ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize,
int  compressionLevel 
)

Definition at line 3021 of file zstd_compress.c.

3022 {
3023  ZSTD_parameters const params = ZSTD_getParams(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
3024  ZSTD_CCtx_params const cctxParams =
3026  DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (U32)dictSize);
3027  return ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
3029 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
static size_t ZSTD_compressBegin_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)
ZSTD_CCtx_params requestedParams
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)

Referenced by ZSTD_compressBegin().

◆ ZSTD_compressBlock()

size_t ZSTD_compressBlock ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

Definition at line 2748 of file zstd_compress.c.

2749 {
2750  size_t const blockSizeMax = ZSTD_getBlockSize(cctx);
2751  if (srcSize > blockSizeMax) return ERROR(srcSize_wrong);
2752 
2753  return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */);
2754 }
#define ERROR(name)
Definition: error_private.h:53
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_compressContinue_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 frame, U32 lastFrameChunk)
size_t ZSTD_getBlockSize(const ZSTD_CCtx *cctx)

◆ ZSTD_compressBlock_internal()

static size_t ZSTD_compressBlock_internal ( ZSTD_CCtx zc,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)
static

Definition at line 2418 of file zstd_compress.c.

2421 {
2422  ZSTD_matchState_t* const ms = &zc->blockState.matchState;
2423  size_t cSize;
2424  DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%zu, dictLimit=%u, nextToUpdate=%u)",
2425  dstCapacity, ms->window.dictLimit, ms->nextToUpdate);
2426  assert(srcSize <= ZSTD_BLOCKSIZE_MAX);
2427 
2428  /* Assert that we have correctly flushed the ctx params into the ms's copy */
2429  ZSTD_assertEqualCParams(zc->appliedParams.cParams, ms->cParams);
2430 
2431  if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) {
2432  ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.searchLength);
2433  cSize = 0;
2434  goto out; /* don't even attempt compression below a certain srcSize */
2435  }
2436  ZSTD_resetSeqStore(&(zc->seqStore));
2437  ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; /* required for optimal parser to read stats from dictionary */
2438 
2439  /* a gap between an attached dict and the current window is not safe,
2440  * they must remain adjacent, and when that stops being the case, the dict
2441  * must be unset */
2442  assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit);
2443 
2444  /* limited update after a very long match */
2445  { const BYTE* const base = ms->window.base;
2446  const BYTE* const istart = (const BYTE*)src;
2447  const U32 current = (U32)(istart-base);
2448  if (sizeof(ptrdiff_t)==8) assert(istart - base < (ptrdiff_t)(U32)(-1)); /* ensure no overflow */
2449  if (current > ms->nextToUpdate + 384)
2450  ms->nextToUpdate = current - MIN(192, (U32)(current - ms->nextToUpdate - 384));
2451  }
2452 
2453  /* select and store sequences */
2454  { ZSTD_dictMode_e const dictMode = ZSTD_matchState_dictMode(ms);
2455  size_t lastLLSize;
2456  { int i;
2457  for (i = 0; i < ZSTD_REP_NUM; ++i)
2459  }
2460  if (zc->externSeqStore.pos < zc->externSeqStore.size) {
2461  assert(!zc->appliedParams.ldmParams.enableLdm);
2462  /* Updates ldmSeqStore.pos */
2463  lastLLSize =
2465  ms, &zc->seqStore,
2466  zc->blockState.nextCBlock->rep,
2467  src, srcSize);
2469  } else if (zc->appliedParams.ldmParams.enableLdm) {
2470  rawSeqStore_t ldmSeqStore = {NULL, 0, 0, 0};
2471 
2472  ldmSeqStore.seq = zc->ldmSequences;
2473  ldmSeqStore.capacity = zc->maxNbLdmSequences;
2474  /* Updates ldmSeqStore.size */
2475  CHECK_F(ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore,
2476  &zc->appliedParams.ldmParams,
2477  src, srcSize));
2478  /* Updates ldmSeqStore.pos */
2479  lastLLSize =
2480  ZSTD_ldm_blockCompress(&ldmSeqStore,
2481  ms, &zc->seqStore,
2482  zc->blockState.nextCBlock->rep,
2483  src, srcSize);
2484  assert(ldmSeqStore.pos == ldmSeqStore.size);
2485  } else { /* not long range mode */
2486  ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, dictMode);
2487  lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
2488  }
2489  { const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize;
2490  ZSTD_storeLastLiterals(&zc->seqStore, lastLiterals, lastLLSize);
2491  } }
2492 
2493  /* encode sequences and literals */
2494  cSize = ZSTD_compressSequences(&zc->seqStore,
2496  &zc->appliedParams,
2497  dst, dstCapacity,
2498  srcSize, zc->entropyWorkspace, zc->bmi2);
2499 
2500 out:
2501  if (!ZSTD_isError(cSize) && cSize != 0) {
2502  /* confirm repcodes and entropy tables when emitting a compressed block */
2505  zc->blockState.nextCBlock = tmp;
2506  }
2507  /* We check that dictionaries have offset codes available for the first
2508  * block. After the first block, the offcode table might not have large
2509  * enough codes to represent the offsets in the data.
2510  */
2511  if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid)
2512  zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check;
2513 
2514  return cSize;
2515 }
rawSeqStore_t externSeqStore
MEM_STATIC size_t ZSTD_compressSequences(seqStore_t *seqStorePtr, const ZSTD_entropyCTables_t *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, const ZSTD_CCtx_params *cctxParams, void *dst, size_t dstCapacity, size_t srcSize, U32 *workspace, int bmi2)
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
size_t ZSTD_ldm_blockCompress(rawSeqStore_t *rawSeqStore, ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
Definition: zstd_ldm.c:591
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
void ZSTD_resetSeqStore(seqStore_t *ssPtr)
ZSTD_compressionParameters cParams
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e dictMode)
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
ZSTD_blockState_t blockState
#define CHECK_F(f)
Definition: fse_compress.c:661
static void ZSTD_storeLastLiterals(seqStore_t *seqStorePtr, const BYTE *anchor, size_t lastLLSize)
const ZSTD_matchState_t * dictMatchState
static FILE * out
Definition: regtests2xml.c:44
size_t(* ZSTD_blockCompressor)(ZSTD_matchState_t *bs, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
ZSTD_compressedBlockState_t * nextCBlock
#define MIN_CBLOCK_SIZE
Definition: zstd_internal.h:89
const ZSTD_entropyCTables_t * symbolCosts
unsigned char BYTE
Definition: mem.h:68
ZSTD_matchState_t matchState
GLenum src
Definition: glext.h:6340
#define ZSTD_isError
MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
GLenum GLenum dst
Definition: glext.h:6340
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
size_t ZSTD_ldm_generateSequences(ldmState_t *ldmState, rawSeqStore_t *sequences, ldmParams_t const *params, void const *src, size_t srcSize)
Definition: zstd_ldm.c:463
void ZSTD_ldm_skipSequences(rawSeqStore_t *rawSeqStore, size_t srcSize, U32 const minMatch)
Definition: zstd_ldm.c:532
ZSTD_compressedBlockState_t * prevCBlock
static void ZSTD_assertEqualCParams(ZSTD_compressionParameters cParams1, ZSTD_compressionParameters cParams2)
#define ZSTD_REP_NUM
Definition: zstd_internal.h:62
struct task_struct * current
Definition: linux.c:32

Referenced by ZSTD_compress_frameChunk(), and ZSTD_compressContinue_internal().

◆ ZSTD_compressBound()

size_t ZSTD_compressBound ( size_t  srcSize)

maximum compressed size in worst case single-pass scenario

Definition at line 33 of file zstd_compress.c.

33  {
34  return ZSTD_COMPRESSBOUND(srcSize);
35 }
#define ZSTD_COMPRESSBOUND(srcSize)
Definition: zstd.h:150

Referenced by ZSTD_compressStream_generic(), ZSTD_CStreamOutSize(), ZSTD_estimateCStreamSize_usingCCtxParams(), and ZSTD_resetCCtx_internal().

◆ ZSTD_compressCCtx()

size_t ZSTD_compressCCtx ( ZSTD_CCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compressCCtx() : Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()).

Definition at line 3161 of file zstd_compress.c.

3165 {
3166  DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (U32)srcSize);
3167  assert(cctx != NULL);
3168  return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
3169 }
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_usingDict(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_compress().

◆ ZSTD_compressContinue()

size_t ZSTD_compressContinue ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

Definition at line 2732 of file zstd_compress.c.

2735 {
2736  DEBUGLOG(5, "ZSTD_compressContinue (srcSize=%u)", (U32)srcSize);
2737  return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1 /* frame mode */, 0 /* last chunk */);
2738 }
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_compressContinue_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 frame, U32 lastFrameChunk)

Referenced by ZSTD_compressStream_generic().

◆ ZSTD_compressContinue_internal()

static size_t ZSTD_compressContinue_internal ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
U32  frame,
U32  lastFrameChunk 
)
static

Definition at line 2666 of file zstd_compress.c.

2670 {
2671  ZSTD_matchState_t* const ms = &cctx->blockState.matchState;
2672  size_t fhSize = 0;
2673 
2674  DEBUGLOG(5, "ZSTD_compressContinue_internal, stage: %u, srcSize: %u",
2675  cctx->stage, (U32)srcSize);
2676  if (cctx->stage==ZSTDcs_created) return ERROR(stage_wrong); /* missing init (ZSTD_compressBegin) */
2677 
2678  if (frame && (cctx->stage==ZSTDcs_init)) {
2679  fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams,
2680  cctx->pledgedSrcSizePlusOne-1, cctx->dictID);
2681  if (ZSTD_isError(fhSize)) return fhSize;
2682  dstCapacity -= fhSize;
2683  dst = (char*)dst + fhSize;
2684  cctx->stage = ZSTDcs_ongoing;
2685  }
2686 
2687  if (!srcSize) return fhSize; /* do not generate an empty block if no input */
2688 
2689  if (!ZSTD_window_update(&ms->window, src, srcSize)) {
2690  ms->nextToUpdate = ms->window.dictLimit;
2691  }
2692  if (cctx->appliedParams.ldmParams.enableLdm) {
2693  ZSTD_window_update(&cctx->ldmState.window, src, srcSize);
2694  }
2695 
2696  if (!frame) {
2697  /* overflow check and correction for block mode */
2698  if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) {
2699  U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy);
2700  U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src);
2701  ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30);
2702  ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30);
2703  ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31);
2704  ZSTD_reduceIndex(cctx, correction);
2705  if (ms->nextToUpdate < correction) ms->nextToUpdate = 0;
2706  else ms->nextToUpdate -= correction;
2707  ms->loadedDictEnd = 0;
2708  ms->dictMatchState = NULL;
2709  }
2710  }
2711 
2712  DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (U32)cctx->blockSize);
2713  { size_t const cSize = frame ?
2714  ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) :
2715  ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize);
2716  if (ZSTD_isError(cSize)) return cSize;
2717  cctx->consumedSrcSize += srcSize;
2718  cctx->producedCSize += (cSize + fhSize);
2719  assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
2720  if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
2721  ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
2722  if (cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne) {
2723  DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize >= %u",
2724  (U32)cctx->pledgedSrcSizePlusOne-1, (U32)cctx->consumedSrcSize);
2725  return ERROR(srcSize_wrong);
2726  }
2727  }
2728  return cSize + fhSize;
2729  }
2730 }
unsigned long long consumedSrcSize
static size_t ZSTD_compressBlock_internal(ZSTD_CCtx *zc, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
unsigned long long pledgedSrcSizePlusOne
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
static size_t ZSTD_compress_frameChunk(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 lastFrameChunk)
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_compressionStage_e stage
static size_t ZSTD_writeFrameHeader(void *dst, size_t dstCapacity, ZSTD_CCtx_params params, U64 pledgedSrcSize, U32 dictID)
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
ZSTD_blockState_t blockState
const ZSTD_matchState_t * dictMatchState
MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window, void const *srcEnd)
ZSTD_matchState_t matchState
GLenum src
Definition: glext.h:6340
MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t *window, U32 cycleLog, U32 maxDist, void const *src)
#define ZSTD_isError
static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
static void ZSTD_reduceIndex(ZSTD_CCtx *zc, const U32 reducerValue)
GLenum GLenum dst
Definition: glext.h:6340
MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t *window, void const *src, size_t srcSize)
unsigned long long producedCSize
ZSTD_window_t window

Referenced by ZSTD_compressBlock(), ZSTD_compressContinue(), and ZSTD_compressEnd().

◆ ZSTD_compressEnd()

size_t ZSTD_compressEnd ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

Definition at line 3079 of file zstd_compress.c.

3082 {
3083  size_t endResult;
3084  size_t const cSize = ZSTD_compressContinue_internal(cctx,
3085  dst, dstCapacity, src, srcSize,
3086  1 /* frame mode */, 1 /* last chunk */);
3087  if (ZSTD_isError(cSize)) return cSize;
3088  endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize);
3089  if (ZSTD_isError(endResult)) return endResult;
3090  assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
3091  if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
3092  ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
3093  DEBUGLOG(4, "end of frame : controlling src size");
3094  if (cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1) {
3095  DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize = %u",
3096  (U32)cctx->pledgedSrcSizePlusOne-1, (U32)cctx->consumedSrcSize);
3097  return ERROR(srcSize_wrong);
3098  } }
3099  return cSize + endResult;
3100 }
unsigned long long consumedSrcSize
unsigned long long pledgedSrcSizePlusOne
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_CCtx_params appliedParams
GLenum src
Definition: glext.h:6340
#define ZSTD_isError
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_writeEpilogue(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity)
static size_t ZSTD_compressContinue_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 frame, U32 lastFrameChunk)

Referenced by ZSTD_compress_advanced_internal(), ZSTD_compress_usingCDict_advanced(), and ZSTD_compressStream_generic().

◆ ZSTD_compressLiterals()

static size_t ZSTD_compressLiterals ( ZSTD_hufCTables_t const prevHuf,
ZSTD_hufCTables_t nextHuf,
ZSTD_strategy  strategy,
int  disableLiteralCompression,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
U32 workspace,
const int  bmi2 
)
static

Definition at line 1677 of file zstd_compress.c.

1683 {
1684  size_t const minGain = ZSTD_minGain(srcSize, strategy);
1685  size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB);
1686  BYTE* const ostart = (BYTE*)dst;
1687  U32 singleStream = srcSize < 256;
1689  size_t cLitSize;
1690 
1691  DEBUGLOG(5,"ZSTD_compressLiterals (disableLiteralCompression=%i)",
1692  disableLiteralCompression);
1693 
1694  /* Prepare nextEntropy assuming reusing the existing table */
1695  memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
1696 
1697  if (disableLiteralCompression)
1698  return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
1699 
1700  /* small ? don't even attempt compression (speed opt) */
1701 # define COMPRESS_LITERALS_SIZE_MIN 63
1702  { size_t const minLitSize = (prevHuf->repeatMode == HUF_repeat_valid) ? 6 : COMPRESS_LITERALS_SIZE_MIN;
1703  if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
1704  }
1705 
1706  if (dstCapacity < lhSize+1) return ERROR(dstSize_tooSmall); /* not enough space for compression */
1707  { HUF_repeat repeat = prevHuf->repeatMode;
1708  int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0;
1709  if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
1710  cLitSize = singleStream ? HUF_compress1X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11,
1711  workspace, HUF_WORKSPACE_SIZE, (HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2)
1712  : HUF_compress4X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11,
1713  workspace, HUF_WORKSPACE_SIZE, (HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2);
1714  if (repeat != HUF_repeat_none) {
1715  /* reused the existing table */
1716  hType = set_repeat;
1717  }
1718  }
1719 
1720  if ((cLitSize==0) | (cLitSize >= srcSize - minGain) | ERR_isError(cLitSize)) {
1721  memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
1722  return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
1723  }
1724  if (cLitSize==1) {
1725  memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
1726  return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);
1727  }
1728 
1729  if (hType == set_compressed) {
1730  /* using a newly constructed table */
1731  nextHuf->repeatMode = HUF_repeat_check;
1732  }
1733 
1734  /* Build header */
1735  switch(lhSize)
1736  {
1737  case 3: /* 2 - 2 - 10 - 10 */
1738  { U32 const lhc = hType + ((!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14);
1739  MEM_writeLE24(ostart, lhc);
1740  break;
1741  }
1742  case 4: /* 2 - 2 - 14 - 14 */
1743  { U32 const lhc = hType + (2 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<18);
1744  MEM_writeLE32(ostart, lhc);
1745  break;
1746  }
1747  case 5: /* 2 - 2 - 18 - 18 */
1748  { U32 const lhc = hType + (3 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<22);
1749  MEM_writeLE32(ostart, lhc);
1750  ostart[4] = (BYTE)(cLitSize >> 10);
1751  break;
1752  }
1753  default: /* not possible : lhSize is {3,4,5} */
1754  assert(0);
1755  }
1756  return lhSize+cLitSize;
1757 }
size_t HUF_compress1X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
Definition: huf_compress.c:749
symbolEncodingType_e
Definition: zstd_internal.h:92
#define ERROR(name)
Definition: error_private.h:53
static size_t ZSTD_compressRleLiteralsBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
#define DEBUGLOG(l,...)
Definition: debug.h:115
size_t HUF_compress4X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
Definition: huf_compress.c:795
ERR_STATIC unsigned ERR_isError(size_t code)
Definition: error_private.h:56
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
Definition: mem.h:281
#define COMPRESS_LITERALS_SIZE_MIN
U32 CTable[HUF_CTABLE_SIZE_U32(255)]
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
static int repeat
Definition: xmllint.c:143
static size_t ZSTD_noCompressLiterals(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
GLenum GLenum dst
Definition: glext.h:6340
MEM_STATIC void MEM_writeLE24(void *memPtr, U32 val)
Definition: mem.h:267
#define HUF_WORKSPACE_SIZE
Definition: huf.h:113
#define KB
Definition: setuplib.h:52

Referenced by ZSTD_compressSequences_internal().

◆ ZSTD_compressRleLiteralsBlock()

static size_t ZSTD_compressRleLiteralsBlock ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)
static

Definition at line 1640 of file zstd_compress.c.

1641 {
1642  BYTE* const ostart = (BYTE* const)dst;
1643  U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
1644 
1645  (void)dstCapacity; /* dstCapacity already guaranteed to be >=4, hence large enough */
1646 
1647  switch(flSize)
1648  {
1649  case 1: /* 2 - 1 - 5 */
1650  ostart[0] = (BYTE)((U32)set_rle + (srcSize<<3));
1651  break;
1652  case 2: /* 2 - 2 - 12 */
1653  MEM_writeLE16(ostart, (U16)((U32)set_rle + (1<<2) + (srcSize<<4)));
1654  break;
1655  case 3: /* 2 - 2 - 20 */
1656  MEM_writeLE32(ostart, (U32)((U32)set_rle + (3<<2) + (srcSize<<4)));
1657  break;
1658  default: /* not necessary : flSize is {1,2,3} */
1659  assert(0);
1660  }
1661 
1662  ostart[flSize] = *(const BYTE*)src;
1663  return flSize+1;
1664 }
unsigned short U16
Definition: mem.h:72
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
Definition: mem.h:251
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
Definition: mem.h:281
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_compressLiterals().

◆ ZSTD_compressSequences()

MEM_STATIC size_t ZSTD_compressSequences ( seqStore_t seqStorePtr,
const ZSTD_entropyCTables_t prevEntropy,
ZSTD_entropyCTables_t nextEntropy,
const ZSTD_CCtx_params *  cctxParams,
void dst,
size_t  dstCapacity,
size_t  srcSize,
U32 workspace,
int  bmi2 
)

Definition at line 2334 of file zstd_compress.c.

2340 {
2341  size_t const cSize = ZSTD_compressSequences_internal(
2342  seqStorePtr, prevEntropy, nextEntropy, cctxParams, dst, dstCapacity,
2343  workspace, bmi2);
2344  if (cSize == 0) return 0;
2345  /* When srcSize <= dstCapacity, there is enough space to write a raw uncompressed block.
2346  * Since we ran out of space, block must be not compressible, so fall back to raw uncompressed block.
2347  */
2348  if ((cSize == ERROR(dstSize_tooSmall)) & (srcSize <= dstCapacity))
2349  return 0; /* block not compressed */
2350  if (ZSTD_isError(cSize)) return cSize;
2351 
2352  /* Check compressibility */
2353  { size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, cctxParams->cParams.strategy);
2354  if (cSize >= maxCSize) return 0; /* block not compressed */
2355  }
2356 
2357  return cSize;
2358 }
#define ERROR(name)
Definition: error_private.h:53
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t *seqStorePtr, ZSTD_entropyCTables_t const *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, ZSTD_CCtx_params const *cctxParams, void *dst, size_t dstCapacity, U32 *workspace, const int bmi2)
#define ZSTD_isError
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_compressBlock_internal().

◆ ZSTD_compressSequences_internal()

MEM_STATIC size_t ZSTD_compressSequences_internal ( seqStore_t seqStorePtr,
ZSTD_entropyCTables_t const prevEntropy,
ZSTD_entropyCTables_t nextEntropy,
ZSTD_CCtx_params const cctxParams,
void dst,
size_t  dstCapacity,
U32 workspace,
const int  bmi2 
)

Definition at line 2189 of file zstd_compress.c.

2195 {
2196  const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN;
2197  ZSTD_strategy const strategy = cctxParams->cParams.strategy;
2198  U32 count[MaxSeq+1];
2199  FSE_CTable* CTable_LitLength = nextEntropy->fse.litlengthCTable;
2200  FSE_CTable* CTable_OffsetBits = nextEntropy->fse.offcodeCTable;
2201  FSE_CTable* CTable_MatchLength = nextEntropy->fse.matchlengthCTable;
2202  U32 LLtype, Offtype, MLtype; /* compressed, raw or rle */
2203  const seqDef* const sequences = seqStorePtr->sequencesStart;
2204  const BYTE* const ofCodeTable = seqStorePtr->ofCode;
2205  const BYTE* const llCodeTable = seqStorePtr->llCode;
2206  const BYTE* const mlCodeTable = seqStorePtr->mlCode;
2207  BYTE* const ostart = (BYTE*)dst;
2208  BYTE* const oend = ostart + dstCapacity;
2209  BYTE* op = ostart;
2210  size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart;
2211  BYTE* seqHead;
2212  BYTE* lastNCount = NULL;
2213 
2215 
2216  /* Compress literals */
2217  { const BYTE* const literals = seqStorePtr->litStart;
2218  size_t const litSize = seqStorePtr->lit - literals;
2219  int const disableLiteralCompression = (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0);
2220  size_t const cSize = ZSTD_compressLiterals(
2221  &prevEntropy->huf, &nextEntropy->huf,
2222  cctxParams->cParams.strategy, disableLiteralCompression,
2223  op, dstCapacity,
2224  literals, litSize,
2225  workspace, bmi2);
2226  if (ZSTD_isError(cSize))
2227  return cSize;
2228  assert(cSize <= dstCapacity);
2229  op += cSize;
2230  }
2231 
2232  /* Sequences Header */
2233  if ((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/) return ERROR(dstSize_tooSmall);
2234  if (nbSeq < 0x7F)
2235  *op++ = (BYTE)nbSeq;
2236  else if (nbSeq < LONGNBSEQ)
2237  op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2;
2238  else
2239  op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3;
2240  if (nbSeq==0) {
2241  /* Copy the old tables over as if we repeated them */
2242  memcpy(&nextEntropy->fse, &prevEntropy->fse, sizeof(prevEntropy->fse));
2243  return op - ostart;
2244  }
2245 
2246  /* seqHead : flags for FSE encoding type */
2247  seqHead = op++;
2248 
2249  /* convert length/distances into codes */
2250  ZSTD_seqToCodes(seqStorePtr);
2251  /* build CTable for Literal Lengths */
2252  { U32 max = MaxLL;
2253  size_t const mostFrequent = HIST_countFast_wksp(count, &max, llCodeTable, nbSeq, workspace); /* can't fail */
2254  DEBUGLOG(5, "Building LL table");
2255  nextEntropy->fse.litlength_repeatMode = prevEntropy->fse.litlength_repeatMode;
2256  LLtype = ZSTD_selectEncodingType(&nextEntropy->fse.litlength_repeatMode, count, max, mostFrequent, nbSeq, LLFSELog, prevEntropy->fse.litlengthCTable, LL_defaultNorm, LL_defaultNormLog, ZSTD_defaultAllowed, strategy);
2258  assert(!(LLtype < set_compressed && nextEntropy->fse.litlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
2259  { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype,
2260  count, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL,
2261  prevEntropy->fse.litlengthCTable, sizeof(prevEntropy->fse.litlengthCTable),
2262  workspace, HUF_WORKSPACE_SIZE);
2263  if (ZSTD_isError(countSize)) return countSize;
2264  if (LLtype == set_compressed)
2265  lastNCount = op;
2266  op += countSize;
2267  } }
2268  /* build CTable for Offsets */
2269  { U32 max = MaxOff;
2270  size_t const mostFrequent = HIST_countFast_wksp(count, &max, ofCodeTable, nbSeq, workspace); /* can't fail */
2271  /* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */
2273  DEBUGLOG(5, "Building OF table");
2274  nextEntropy->fse.offcode_repeatMode = prevEntropy->fse.offcode_repeatMode;
2275  Offtype = ZSTD_selectEncodingType(&nextEntropy->fse.offcode_repeatMode, count, max, mostFrequent, nbSeq, OffFSELog, prevEntropy->fse.offcodeCTable, OF_defaultNorm, OF_defaultNormLog, defaultPolicy, strategy);
2276  assert(!(Offtype < set_compressed && nextEntropy->fse.offcode_repeatMode != FSE_repeat_none)); /* We don't copy tables */
2277  { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype,
2278  count, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
2279  prevEntropy->fse.offcodeCTable, sizeof(prevEntropy->fse.offcodeCTable),
2280  workspace, HUF_WORKSPACE_SIZE);
2281  if (ZSTD_isError(countSize)) return countSize;
2282  if (Offtype == set_compressed)
2283  lastNCount = op;
2284  op += countSize;
2285  } }
2286  /* build CTable for MatchLengths */
2287  { U32 max = MaxML;
2288  size_t const mostFrequent = HIST_countFast_wksp(count, &max, mlCodeTable, nbSeq, workspace); /* can't fail */
2289  DEBUGLOG(5, "Building ML table");
2290  nextEntropy->fse.matchlength_repeatMode = prevEntropy->fse.matchlength_repeatMode;
2291  MLtype = ZSTD_selectEncodingType(&nextEntropy->fse.matchlength_repeatMode, count, max, mostFrequent, nbSeq, MLFSELog, prevEntropy->fse.matchlengthCTable, ML_defaultNorm, ML_defaultNormLog, ZSTD_defaultAllowed, strategy);
2292  assert(!(MLtype < set_compressed && nextEntropy->fse.matchlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
2293  { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype,
2294  count, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML,
2295  prevEntropy->fse.matchlengthCTable, sizeof(prevEntropy->fse.matchlengthCTable),
2296  workspace, HUF_WORKSPACE_SIZE);
2297  if (ZSTD_isError(countSize)) return countSize;
2298  if (MLtype == set_compressed)
2299  lastNCount = op;
2300  op += countSize;
2301  } }
2302 
2303  *seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2));
2304 
2305  { size_t const bitstreamSize = ZSTD_encodeSequences(
2306  op, oend - op,
2307  CTable_MatchLength, mlCodeTable,
2308  CTable_OffsetBits, ofCodeTable,
2309  CTable_LitLength, llCodeTable,
2310  sequences, nbSeq,
2311  longOffsets, bmi2);
2312  if (ZSTD_isError(bitstreamSize)) return bitstreamSize;
2313  op += bitstreamSize;
2314  /* zstd versions <= 1.3.4 mistakenly report corruption when
2315  * FSE_readNCount() recieves a buffer < 4 bytes.
2316  * Fixed by https://github.com/facebook/zstd/pull/1146.
2317  * This can happen when the last set_compressed table present is 2
2318  * bytes and the bitstream is only one byte.
2319  * In this exceedingly rare case, we will simply emit an uncompressed
2320  * block, since it isn't worth optimizing.
2321  */
2322  if (lastNCount && (op - lastNCount) < 4) {
2323  /* NCountSize >= 2 && bitstreamSize > 0 ==> lastCountSize == 3 */
2324  assert(op - lastNCount == 3);
2325  DEBUGLOG(5, "Avoiding bug in zstd decoder in versions <= 1.3.4 by "
2326  "emitting an uncompressed block.");
2327  return 0;
2328  }
2329  }
2330 
2331  return op - ostart;
2332 }
unsigned short U16
Definition: mem.h:72
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
Definition: mem.h:251
symbolEncodingType_e
Definition: zstd_internal.h:92
#define max(a, b)
Definition: svc.c:63
#define MaxSeq
static size_t ZSTD_compressLiterals(ZSTD_hufCTables_t const *prevHuf, ZSTD_hufCTables_t *nextHuf, ZSTD_strategy strategy, int disableLiteralCompression, void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 *workspace, const int bmi2)
BYTE * ofCode
#define ERROR(name)
Definition: error_private.h:53
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
static const U32 ML_defaultNormLog
unsigned FSE_CTable
Definition: fse.h:180
seqDef * sequencesStart
void ZSTD_seqToCodes(const seqStore_t *seqStorePtr)
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
static const S16 LL_defaultNorm[MaxLL+1]
#define DEBUGLOG(l,...)
Definition: debug.h:115
seqDef * sequences
MEM_STATIC size_t ZSTD_buildCTable(void *dst, size_t dstCapacity, FSE_CTable *nextCTable, U32 FSELog, symbolEncodingType_e type, U32 *count, U32 max, const BYTE *codeTable, size_t nbSeq, const S16 *defaultNorm, U32 defaultNormLog, U32 defaultMax, const FSE_CTable *prevCTable, size_t prevCTableSize, void *workspace, size_t workspaceSize)
static size_t ZSTD_encodeSequences(void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets, int bmi2)
ZSTD_defaultPolicy_e
smooth NULL
Definition: ftsmooth.c:416
#define DefaultMaxOff
static const U32 OF_defaultNormLog
#define MaxML
#define MLFSELog
FSE_CTable offcodeCTable[FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)]
FSE_CTable litlengthCTable[FSE_CTABLE_SIZE_U32(LLFSELog, MaxLL)]
size_t HIST_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned *workSpace)
Definition: hist.c:164
#define OffFSELog
static const U32 LL_defaultNormLog
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define LONGNBSEQ
Definition: zstd_internal.h:94
BYTE * mlCode
static struct msg_sequence * sequences[NUM_MSG_SEQUENCES]
Definition: button.c:54
static const S16 OF_defaultNorm[DefaultMaxOff+1]
T MAX(T a, T b)
Definition: polytest.cpp:85
#define STREAM_ACCUMULATOR_MIN
Definition: bitstream.h:64
#define MaxOff
#define ZSTD_isError
static const S16 ML_defaultNorm[MaxML+1]
MEM_STATIC symbolEncodingType_e ZSTD_selectEncodingType(FSE_repeat *repeatMode, unsigned const *count, unsigned const max, size_t const mostFrequent, size_t nbSeq, unsigned const FSELog, FSE_CTable const *prevCTable, short const *defaultNorm, U32 defaultNormLog, ZSTD_defaultPolicy_e const isDefaultAllowed, ZSTD_strategy const strategy)
FSE_CTable matchlengthCTable[FSE_CTABLE_SIZE_U32(MLFSELog, MaxML)]
GLenum GLenum dst
Definition: glext.h:6340
#define MaxLL
#define HUF_WORKSPACE_SIZE
Definition: huf.h:113
#define LLFSELog
BYTE * llCode
UINT op
Definition: effect.c:223
BYTE * litStart

Referenced by ZSTD_compressSequences().

◆ ZSTD_compressStream()

size_t ZSTD_compressStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 3770 of file zstd_compress.c.

3771 {
3772  /* check conditions */
3773  if (output->pos > output->size) return ERROR(GENERIC);
3774  if (input->pos > input->size) return ERROR(GENERIC);
3775 
3776  return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue);
3777 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define ERROR(name)
Definition: error_private.h:53
size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
GLenum GLenum GLenum input
Definition: glext.h:9031

Referenced by zstd_write_compressed_bit().

◆ ZSTD_compressStream_generic()

size_t ZSTD_compressStream_generic ( ZSTD_CStream zcs,
ZSTD_outBuffer output,
ZSTD_inBuffer input,
ZSTD_EndDirective const  flushMode 
)

ZSTD_compressStream_generic(): internal function for all compressStream() variants and *compress_generic() non-static, because can be called from zstdmt_compress.c

Returns
: hint size for next input

Definition at line 3627 of file zstd_compress.c.

3631 {
3632  const char* const istart = (const char*)input->src;
3633  const char* const iend = istart + input->size;
3634  const char* ip = istart + input->pos;
3635  char* const ostart = (char*)output->dst;
3636  char* const oend = ostart + output->size;
3637  char* op = ostart + output->pos;
3638  U32 someMoreWork = 1;
3639 
3640  /* check expectations */
3641  DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (U32)flushMode);
3642  assert(zcs->inBuff != NULL);
3643  assert(zcs->inBuffSize > 0);
3644  assert(zcs->outBuff != NULL);
3645  assert(zcs->outBuffSize > 0);
3646  assert(output->pos <= output->size);
3647  assert(input->pos <= input->size);
3648 
3649  while (someMoreWork) {
3650  switch(zcs->streamStage)
3651  {
3652  case zcss_init:
3653  /* call ZSTD_initCStream() first ! */
3654  return ERROR(init_missing);
3655 
3656  case zcss_load:
3657  if ( (flushMode == ZSTD_e_end)
3658  && ((size_t)(oend-op) >= ZSTD_compressBound(iend-ip)) /* enough dstCapacity */
3659  && (zcs->inBuffPos == 0) ) {
3660  /* shortcut to compression pass directly into output buffer */
3661  size_t const cSize = ZSTD_compressEnd(zcs,
3662  op, oend-op, ip, iend-ip);
3663  DEBUGLOG(4, "ZSTD_compressEnd : %u", (U32)cSize);
3664  if (ZSTD_isError(cSize)) return cSize;
3665  ip = iend;
3666  op += cSize;
3667  zcs->frameEnded = 1;
3668  ZSTD_CCtx_reset(zcs);
3669  someMoreWork = 0; break;
3670  }
3671  /* complete loading into inBuffer */
3672  { size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos;
3673  size_t const loaded = ZSTD_limitCopy(
3674  zcs->inBuff + zcs->inBuffPos, toLoad,
3675  ip, iend-ip);
3676  zcs->inBuffPos += loaded;
3677  ip += loaded;
3678  if ( (flushMode == ZSTD_e_continue)
3679  && (zcs->inBuffPos < zcs->inBuffTarget) ) {
3680  /* not enough input to fill full block : stop here */
3681  someMoreWork = 0; break;
3682  }
3683  if ( (flushMode == ZSTD_e_flush)
3684  && (zcs->inBuffPos == zcs->inToCompress) ) {
3685  /* empty */
3686  someMoreWork = 0; break;
3687  }
3688  }
3689  /* compress current block (note : this stage cannot be stopped in the middle) */
3690  DEBUGLOG(5, "stream compression stage (flushMode==%u)", flushMode);
3691  { void* cDst;
3692  size_t cSize;
3693  size_t const iSize = zcs->inBuffPos - zcs->inToCompress;
3694  size_t oSize = oend-op;
3695  unsigned const lastBlock = (flushMode == ZSTD_e_end) && (ip==iend);
3696  if (oSize >= ZSTD_compressBound(iSize))
3697  cDst = op; /* compress into output buffer, to skip flush stage */
3698  else
3699  cDst = zcs->outBuff, oSize = zcs->outBuffSize;
3700  cSize = lastBlock ?
3701  ZSTD_compressEnd(zcs, cDst, oSize,
3702  zcs->inBuff + zcs->inToCompress, iSize) :
3703  ZSTD_compressContinue(zcs, cDst, oSize,
3704  zcs->inBuff + zcs->inToCompress, iSize);
3705  if (ZSTD_isError(cSize)) return cSize;
3706  zcs->frameEnded = lastBlock;
3707  /* prepare next block */
3708  zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize;
3709  if (zcs->inBuffTarget > zcs->inBuffSize)
3710  zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize;
3711  DEBUGLOG(5, "inBuffTarget:%u / inBuffSize:%u",
3712  (U32)zcs->inBuffTarget, (U32)zcs->inBuffSize);
3713  if (!lastBlock)
3714  assert(zcs->inBuffTarget <= zcs->inBuffSize);
3715  zcs->inToCompress = zcs->inBuffPos;
3716  if (cDst == op) { /* no need to flush */
3717  op += cSize;
3718  if (zcs->frameEnded) {
3719  DEBUGLOG(5, "Frame completed directly in outBuffer");
3720  someMoreWork = 0;
3721  ZSTD_CCtx_reset(zcs);
3722  }
3723  break;
3724  }
3725  zcs->outBuffContentSize = cSize;
3726  zcs->outBuffFlushedSize = 0;
3727  zcs->streamStage = zcss_flush; /* pass-through to flush stage */
3728  }
3729  /* fall-through */
3730  case zcss_flush:
3731  DEBUGLOG(5, "flush stage");
3732  { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;
3733  size_t const flushed = ZSTD_limitCopy(op, oend-op,
3734  zcs->outBuff + zcs->outBuffFlushedSize, toFlush);
3735  DEBUGLOG(5, "toFlush: %u into %u ==> flushed: %u",
3736  (U32)toFlush, (U32)(oend-op), (U32)flushed);
3737  op += flushed;
3738  zcs->outBuffFlushedSize += flushed;
3739  if (toFlush!=flushed) {
3740  /* flush not fully completed, presumably because dst is too small */
3741  assert(op==oend);
3742  someMoreWork = 0;
3743  break;
3744  }
3745  zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0;
3746  if (zcs->frameEnded) {
3747  DEBUGLOG(5, "Frame completed on flush");
3748  someMoreWork = 0;
3749  ZSTD_CCtx_reset(zcs);
3750  break;
3751  }
3752  zcs->streamStage = zcss_load;
3753  break;
3754  }
3755 
3756  default: /* impossible */
3757  assert(0);
3758  }
3759  }
3760 
3761  input->pos = ip - istart;
3762  output->pos = op - ostart;
3763  if (zcs->frameEnded) return 0;
3764  { size_t hintInSize = zcs->inBuffTarget - zcs->inBuffPos;
3765  if (hintInSize==0) hintInSize = zcs->blockSize;
3766  return hintInSize;
3767  }
3768 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define ERROR(name)
Definition: error_private.h:53
size_t ZSTD_compressContinue(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416
Definition: dhcpd.h:61
BOOL loaded
Definition: xmlview.c:54
void ZSTD_CCtx_reset(ZSTD_CCtx *cctx)
#define ZSTD_isError
GLenum GLenum GLenum input
Definition: glext.h:9031
ZSTD_cStreamStage streamStage
size_t ZSTD_compressEnd(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
UINT op
Definition: effect.c:223
size_t ZSTD_compressBound(size_t srcSize)
Definition: zstd_compress.c:33

Referenced by ZSTD_compress_generic(), ZSTD_compressStream(), ZSTD_endStream(), and ZSTD_flushStream().

◆ ZSTD_continueCCtx()

static size_t ZSTD_continueCCtx ( ZSTD_CCtx cctx,
ZSTD_CCtx_params  params,
U64  pledgedSrcSize 
)
static

ZSTD_continueCCtx() : reuse CCtx without reset (note : requires no dictionary)

Definition at line 1046 of file zstd_compress.c.

1047 {
1048  size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params.cParams.windowLog), pledgedSrcSize));
1049  size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, windowSize);
1050  DEBUGLOG(4, "ZSTD_continueCCtx: re-use context in place");
1051 
1052  cctx->blockSize = blockSize; /* previous block size could be different even for same windowLog, due to pledgedSrcSize */
1053  cctx->appliedParams = params;
1054  cctx->blockState.matchState.cParams = params.cParams;
1055  cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
1056  cctx->consumedSrcSize = 0;
1057  cctx->producedCSize = 0;
1058  if (pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN)
1059  cctx->appliedParams.fParams.contentSizeFlag = 0;
1060  DEBUGLOG(4, "pledged content size : %u ; flag : %u",
1061  (U32)pledgedSrcSize, cctx->appliedParams.fParams.contentSizeFlag);
1062  cctx->stage = ZSTDcs_init;
1063  cctx->dictID = 0;
1064  if (params.ldmParams.enableLdm)
1069  XXH64_reset(&cctx->xxhState, 0);
1070  return 0;
1071 }
unsigned long long consumedSrcSize
size_t ZSTD_referenceExternalSequences(ZSTD_CCtx *cctx, rawSeq *seq, size_t nbSeq)
unsigned long long pledgedSrcSizePlusOne
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
static void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t *bs)
MEM_STATIC void ZSTD_window_clear(ZSTD_window_t *window)
unsigned int U32
Definition: mem.h:77
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
ZSTD_compressionStage_e stage
ZSTD_compressionParameters cParams
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
ZSTD_blockState_t blockState
XXH64_state_t xxhState
static void ZSTD_invalidateMatchState(ZSTD_matchState_t *ms)
ZSTD_matchState_t matchState
T MAX(T a, T b)
Definition: polytest.cpp:85
unsigned long long U64
Definition: mem.h:81
unsigned long long producedCSize
ZSTD_window_t window
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition: xxhash.c:592
ZSTD_compressedBlockState_t * prevCBlock

Referenced by ZSTD_resetCCtx_internal().

◆ ZSTD_copyCCtx()

size_t ZSTD_copyCCtx ( ZSTD_CCtx dstCCtx,
const ZSTD_CCtx srcCCtx,
unsigned long long  pledgedSrcSize 
)

ZSTD_copyCCtx() : Duplicate an existing context srcCCtx into another one dstCCtx. Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). pledgedSrcSize==0 means "unknown".

Returns
: 0, or an error code

Definition at line 1523 of file zstd_compress.c.

1524 {
1525  ZSTD_frameParameters fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ };
1526  ZSTD_buffered_policy_e const zbuff = (ZSTD_buffered_policy_e)(srcCCtx->inBuffSize>0);
1528  if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN;
1529  fParams.contentSizeFlag = (pledgedSrcSize != ZSTD_CONTENTSIZE_UNKNOWN);
1530 
1531  return ZSTD_copyCCtx_internal(dstCCtx, srcCCtx,
1532  fParams, pledgedSrcSize,
1533  zbuff);
1534 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
unsigned int U32
Definition: mem.h:77
ZSTD_buffered_policy_e
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx *dstCCtx, const ZSTD_CCtx *srcCCtx, ZSTD_frameParameters fParams, U64 pledgedSrcSize, ZSTD_buffered_policy_e zbuff)

◆ ZSTD_copyCCtx_internal()

static size_t ZSTD_copyCCtx_internal ( ZSTD_CCtx dstCCtx,
const ZSTD_CCtx srcCCtx,
ZSTD_frameParameters  fParams,
U64  pledgedSrcSize,
ZSTD_buffered_policy_e  zbuff 
)
static

ZSTD_copyCCtx_internal() : Duplicate an existing context srcCCtx into another one dstCCtx. Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). The "context", in this case, refers to the hash and chain tables, entropy tables, and dictionary references. windowLog value is enforced if != 0, otherwise value is copied from srcCCtx.

Returns
: 0, or an error code

Definition at line 1468 of file zstd_compress.c.

1473 {
1474  DEBUGLOG(5, "ZSTD_copyCCtx_internal");
1475  if (srcCCtx->stage!=ZSTDcs_init) return ERROR(stage_wrong);
1476 
1477  memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem));
1478  { ZSTD_CCtx_params params = dstCCtx->requestedParams;
1479  /* Copy only compression parameters related to tables. */
1480  params.cParams = srcCCtx->appliedParams.cParams;
1481  params.fParams = fParams;
1482  ZSTD_resetCCtx_internal(dstCCtx, params, pledgedSrcSize,
1483  ZSTDcrp_noMemset, zbuff);
1484  assert(dstCCtx->appliedParams.cParams.windowLog == srcCCtx->appliedParams.cParams.windowLog);
1485  assert(dstCCtx->appliedParams.cParams.strategy == srcCCtx->appliedParams.cParams.strategy);
1486  assert(dstCCtx->appliedParams.cParams.hashLog == srcCCtx->appliedParams.cParams.hashLog);
1487  assert(dstCCtx->appliedParams.cParams.chainLog == srcCCtx->appliedParams.cParams.chainLog);
1489  }
1490 
1491  /* copy tables */
1492  { size_t const chainSize = (srcCCtx->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((size_t)1 << srcCCtx->appliedParams.cParams.chainLog);
1493  size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog;
1494  size_t const h3Size = (size_t)1 << srcCCtx->blockState.matchState.hashLog3;
1495  size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
1496  assert((U32*)dstCCtx->blockState.matchState.chainTable == (U32*)dstCCtx->blockState.matchState.hashTable + hSize); /* chainTable must follow hashTable */
1497  assert((U32*)dstCCtx->blockState.matchState.hashTable3 == (U32*)dstCCtx->blockState.matchState.chainTable + chainSize);
1498  memcpy(dstCCtx->blockState.matchState.hashTable, srcCCtx->blockState.matchState.hashTable, tableSpace); /* presumes all tables follow each other */
1499  }
1500 
1501  /* copy dictionary offsets */
1502  {
1503  const ZSTD_matchState_t* srcMatchState = &srcCCtx->blockState.matchState;
1504  ZSTD_matchState_t* dstMatchState = &dstCCtx->blockState.matchState;
1505  dstMatchState->window = srcMatchState->window;
1506  dstMatchState->nextToUpdate = srcMatchState->nextToUpdate;
1507  dstMatchState->nextToUpdate3= srcMatchState->nextToUpdate3;
1508  dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd;
1509  }
1510  dstCCtx->dictID = srcCCtx->dictID;
1511 
1512  /* copy block state */
1513  memcpy(dstCCtx->blockState.prevCBlock, srcCCtx->blockState.prevCBlock, sizeof(*srcCCtx->blockState.prevCBlock));
1514 
1515  return 0;
1516 }
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum const GLfloat * params
Definition: glext.h:5645
ZSTD_compressionStage_e stage
static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx *zc, ZSTD_CCtx_params params, U64 pledgedSrcSize, ZSTD_compResetPolicy_e const crp, ZSTD_buffered_policy_e const zbuff)
ZSTD_CCtx_params appliedParams
ZSTD_blockState_t blockState
__kernel_size_t size_t
Definition: linux.h:237
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ZSTD_matchState_t matchState
ZSTD_customMem customMem
ZSTD_CCtx_params requestedParams
ZSTD_compressedBlockState_t * prevCBlock

Referenced by ZSTD_copyCCtx().

◆ ZSTD_createCCtx()

ZSTD_CCtx* ZSTD_createCCtx ( void  )

Definition at line 53 of file zstd_compress.c.

54 {
55  return ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
56 }
ZSTD_CCtx * ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
Definition: zstd_compress.c:70

◆ ZSTD_createCCtx_advanced()

ZSTD_CCtx* ZSTD_createCCtx_advanced ( ZSTD_customMem  customMem)

Definition at line 70 of file zstd_compress.c.

71 {
74  if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
75  { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)ZSTD_malloc(sizeof(ZSTD_CCtx), customMem);
76  if (!cctx) return NULL;
77  ZSTD_initCCtx(cctx, customMem);
78  return cctx;
79  }
80 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
smooth NULL
Definition: ftsmooth.c:416
#define ULL(a, b)
Definition: format_msg.c:27
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
static void ZSTD_initCCtx(ZSTD_CCtx *cctx, ZSTD_customMem memManager)
Definition: zstd_compress.c:58

Referenced by ZSTD_createCCtx(), and ZSTD_createCStream_advanced().

◆ ZSTD_createCCtxParams()

ZSTD_CCtx_params* ZSTD_createCCtxParams ( void  )

Definition at line 179 of file zstd_compress.c.

180 {
181  return ZSTD_createCCtxParams_advanced(ZSTD_defaultCMem);
182 }
static ZSTD_CCtx_params * ZSTD_createCCtxParams_advanced(ZSTD_customMem customMem)

◆ ZSTD_createCCtxParams_advanced()

static ZSTD_CCtx_params* ZSTD_createCCtxParams_advanced ( ZSTD_customMem  customMem)
static

Definition at line 165 of file zstd_compress.c.

167 {
168  ZSTD_CCtx_params* params;
169  if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
170  params = (ZSTD_CCtx_params*)ZSTD_calloc(
171  sizeof(ZSTD_CCtx_params), customMem);
172  if (!params) { return NULL; }
173  params->customMem = customMem;
174  params->compressionLevel = ZSTD_CLEVEL_DEFAULT;
175  params->fParams.contentSizeFlag = 1;
176  return params;
177 }
#define ZSTD_CLEVEL_DEFAULT
Definition: zstd.h:89
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
void * ZSTD_calloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:59

Referenced by ZSTD_createCCtxParams().

◆ ZSTD_createCDict()

ZSTD_CDict* ZSTD_createCDict ( const void dictBuffer,
size_t  dictSize,
int  compressionLevel 
)

ZSTD_createCDict() : When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. dictBuffer can be released after ZSTD_CDict creation, since its content is copied within CDict Note : A ZSTD_CDict can be created with an empty dictionary, but it is inefficient for small data.

Definition at line 3294 of file zstd_compress.c.

3295 {
3296  ZSTD_compressionParameters cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
3297  return ZSTD_createCDict_advanced(dict, dictSize,
3298  ZSTD_dlm_byCopy, ZSTD_dct_auto,
3299  cParams, ZSTD_defaultCMem);
3300 }
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)

◆ ZSTD_createCDict_advanced()

ZSTD_CDict* ZSTD_createCDict_advanced ( const void dictBuffer,
size_t  dictSize,
ZSTD_dictLoadMethod_e  dictLoadMethod,
ZSTD_dictContentType_e  dictContentType,
ZSTD_compressionParameters  cParams,
ZSTD_customMem  customMem 
)

Definition at line 3262 of file zstd_compress.c.

3266 {
3267  DEBUGLOG(3, "ZSTD_createCDict_advanced, mode %u", (U32)dictContentType);
3268  if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
3269 
3270  { ZSTD_CDict* const cdict = (ZSTD_CDict*)ZSTD_malloc(sizeof(ZSTD_CDict), customMem);
3271  size_t const workspaceSize = HUF_WORKSPACE_SIZE + ZSTD_sizeof_matchState(&cParams, /* forCCtx */ 0);
3272  void* const workspace = ZSTD_malloc(workspaceSize, customMem);
3273 
3274  if (!cdict || !workspace) {
3275  ZSTD_free(cdict, customMem);
3276  ZSTD_free(workspace, customMem);
3277  return NULL;
3278  }
3279  cdict->customMem = customMem;
3280  cdict->workspace = workspace;
3281  cdict->workspaceSize = workspaceSize;
3283  dictBuffer, dictSize,
3284  dictLoadMethod, dictContentType,
3285  cParams) )) {
3286  ZSTD_freeCDict(cdict);
3287  return NULL;
3288  }
3289 
3290  return cdict;
3291  }
3292 }
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
static size_t ZSTD_sizeof_matchState(const ZSTD_compressionParameters *const cParams, const U32 forCCtx)
smooth NULL
Definition: ftsmooth.c:416
void * workspace
Definition: zstd_compress.c:45
static size_t ZSTD_initCDict_internal(ZSTD_CDict *cdict, const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams)
ZSTD_customMem customMem
Definition: zstd_compress.c:49
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
size_t workspaceSize
Definition: zstd_compress.c:46
#define ZSTD_isError
#define HUF_WORKSPACE_SIZE
Definition: huf.h:113
size_t ZSTD_freeCDict(ZSTD_CDict *cdict)

Referenced by ZSTD_CCtx_loadDictionary_advanced(), ZSTD_createCDict(), ZSTD_createCDict_byReference(), and ZSTD_initCStream_internal().

◆ ZSTD_createCDict_byReference()

ZSTD_CDict* ZSTD_createCDict_byReference ( const void dict,
size_t  dictSize,
int  compressionLevel 
)

Definition at line 3302 of file zstd_compress.c.

3303 {
3304  ZSTD_compressionParameters cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
3305  return ZSTD_createCDict_advanced(dict, dictSize,
3306  ZSTD_dlm_byRef, ZSTD_dct_auto,
3307  cParams, ZSTD_defaultCMem);
3308 }
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)

◆ ZSTD_createCStream()

ZSTD_CStream* ZSTD_createCStream ( void  )

Definition at line 3443 of file zstd_compress.c.

3444 {
3445  DEBUGLOG(3, "ZSTD_createCStream");
3446  return