/*--- Dependency ---*/
#include "mem.h" /* U32 */
-
/*--- Constants ---*/
#define ZSTD_MAGICNUMBER 0xFD2FB527 /* v0.7 */
#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U
typedef enum { ZSTD_fast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /*< from faster to stronger */
typedef struct {
- U32 windowLog; /*< largest match distance : larger == more compression, more memory needed during decompression */
- U32 chainLog; /*< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
- U32 hashLog; /*< dispatch table : larger == faster, more memory */
- U32 searchLog; /*< nb of searches : larger == more compression, slower */
- U32 searchLength; /*< match length searched : larger == faster decompression, sometimes less compression */
- U32 targetLength; /*< acceptable match size for optimal parser (only) : larger == more compression, slower */
+ U32 windowLog; /*< largest match distance : larger == more compression, more memory needed during decompression */
+ U32 chainLog; /*< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
+ U32 hashLog; /*< dispatch table : larger == faster, more memory */
+ U32 searchLog; /*< nb of searches : larger == more compression, slower */
+ U32 searchLength; /*< match length searched : larger == faster decompression, sometimes less compression */
+ U32 targetLength; /*< acceptable match size for optimal parser (only) : larger == more compression, slower */
ZSTD_strategy strategy;
} ZSTD_compressionParameters;
typedef struct {
- U32 contentSizeFlag; /*< 1: content size will be in frame header (if known). */
- U32 checksumFlag; /*< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */
- U32 noDictIDFlag; /*< 1: no dict ID will be saved into frame header (if dictionary compression) */
+ U32 contentSizeFlag; /*< 1: content size will be in frame header (if known). */
+ U32 checksumFlag; /*< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */
+ U32 noDictIDFlag; /*< 1: no dict ID will be saved into frame header (if dictionary compression) */
} ZSTD_frameParameters;
typedef struct {
* `srcSize` value is optional, select 0 if not known */
ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, size_t dictSize);
-/*! ZSTD_checkParams() :
+/*! ZSTD_checkCParams() :
* Ensure param values remain within authorized range */
ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
-/*! ZSTD_adjustParams() :
+/*! ZSTD_adjustCParams() :
* optimize params for a given `srcSize` and `dictSize`.
* both values are optional, select `0` if unknown. */
ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, U64 srcSize, size_t dictSize);
+/*! ZSTD_getParams() :
+* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
+* All fields of `ZSTD_frameParameters` are set to default (0) */
+ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize, size_t dictSize);
+
/*! ZSTD_compress_advanced() :
* Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
if (!customMem.customAlloc && !customMem.customFree)
customMem = defaultCustomMem;
- if (!customMem.customAlloc || !customMem.customFree)
+ if (!customMem.customAlloc || !customMem.customFree) /* can't have 1/2 custom alloc/free as NULL */
return NULL;
{ ZSTD_CDict* const cdict = (ZSTD_CDict*) customMem.customAlloc(customMem.opaque, sizeof(*cdict));
cp = ZSTD_adjustCParams(cp, srcSize, dictSize);
return cp;
}
+
+/*! ZSTD_getParams() :
+* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
+* All fields of `ZSTD_frameParameters` are set to default (0) */
+ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize, size_t dictSize) {
+ ZSTD_parameters params;
+ ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, srcSize, dictSize);
+ memset(¶ms, 0, sizeof(params));
+ params.cParams = cParams;
+ return params;
+}
/* checks */
if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
- EXM_THROW(31, "not enough memory");
+ EXM_THROW(31, "allocation error : not enough memory");
/* init */
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize);
memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */
- UTIL_sleepMilli(1); /* give processor time to other processes */
+ UTIL_sleepMilli(1); /* give processor time to other processes */
UTIL_waitForNextTick(ticksPerSecond);
UTIL_getTime(&clockStart);
- { U32 nbLoops = 0;
- ZSTD_CDict* cdict = ZSTD_createCDict(dictBuffer, dictBufferSize, cLevel);
+ { size_t const refSrcSize = (nbBlocks == 1) ? srcSize : 0;
+ ZSTD_parameters const zparams = ZSTD_getParams(cLevel, refSrcSize, dictBufferSize);
+ ZSTD_customMem const cmem = { NULL, NULL, NULL };
+ U32 nbLoops = 0;
+ ZSTD_CDict* cdict = ZSTD_createCDict_advanced(dictBuffer, dictBufferSize, zparams, cmem);
if (cdict==NULL) EXM_THROW(1, "ZSTD_createCDict() allocation failure");
do {
U32 blockNb;