From 411053488657c93d1230882c2d299135f54ddf6b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 27 Jul 2016 15:09:11 +0200 Subject: [PATCH] ZSTD_maxCLevel() is promoted to "stable" API (#254, by @FrancescAlted) --- lib/compress/zstd_compress.c | 2 +- lib/dictBuilder/zdict.c | 4 ++-- lib/dictBuilder/zdict.h | 2 +- lib/zstd.h | 6 +++--- programs/paramgrill.c | 10 +++++----- programs/zstdcli.c | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 7ba7f8235..a2b61f676 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2767,7 +2767,7 @@ ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, #define ZSTD_DEFAULT_CLEVEL 1 #define ZSTD_MAX_CLEVEL 22 -unsigned ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } +int ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { { /* "default" */ diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 8713b02e9..d77f7ad9a 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -85,7 +85,7 @@ #define PRIME2 2246822519U #define MINRATIO 4 -static const U32 g_compressionLevel_default = 5; +static const int g_compressionLevel_default = 5; static const U32 g_selectivity_default = 9; static const size_t g_provision_entropySize = 200; static const size_t g_min_fast_dictContent = 192; @@ -841,7 +841,7 @@ size_t ZDICT_addEntropyTablesFromBuffer_advanced(void* dictBuffer, size_t dictCo ZDICT_params_t params) { size_t hSize; - unsigned const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel; + int const compressionLevel = (params.compressionLevel <= 0) ? g_compressionLevel_default : params.compressionLevel; /* dictionary header */ MEM_writeLE32(dictBuffer, ZSTD_DICT_MAGIC); diff --git a/lib/dictBuilder/zdict.h b/lib/dictBuilder/zdict.h index b96b828f7..599e8fb59 100644 --- a/lib/dictBuilder/zdict.h +++ b/lib/dictBuilder/zdict.h @@ -86,7 +86,7 @@ const char* ZDICT_getErrorName(size_t errorCode); typedef struct { unsigned selectivityLevel; /* 0 means default; larger => bigger selection => larger dictionary */ - unsigned compressionLevel; /* 0 means default; target a specific zstd compression level */ + int compressionLevel; /* 0 means default; target a specific zstd compression level */ unsigned notificationLevel; /* Write to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */ unsigned dictID; /* 0 means auto mode (32-bits random value); other : force dictID value */ unsigned reserved[2]; /* space for future parameters */ diff --git a/lib/zstd.h b/lib/zstd.h index e459f6259..e819eda62 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -93,8 +93,10 @@ unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, const void* src, size_t compressedSize); + /*====== Helper functions ======*/ -ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */ +ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ +ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ @@ -264,8 +266,6 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictS * Gives the amount of memory used by a given ZSTD_CCtx */ ZSTDLIB_API size_t ZSTD_sizeofCCtx(const ZSTD_CCtx* cctx); -ZSTDLIB_API unsigned ZSTD_maxCLevel (void); - /*! ZSTD_getParams() : * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`. * All fields of `ZSTD_frameParameters` are set to default (0) */ diff --git a/programs/paramgrill.c b/programs/paramgrill.c index 04a55c876..9348a40f9 100644 --- a/programs/paramgrill.c +++ b/programs/paramgrill.c @@ -340,7 +340,7 @@ typedef struct { static void BMK_printWinners2(FILE* f, const winnerInfo_t* winners, size_t srcSize) { - unsigned cLevel; + int cLevel; fprintf(f, "\n /* Proposed configurations : */ \n"); fprintf(f, " /* W, C, H, S, L, T, strat */ \n"); @@ -364,7 +364,7 @@ static int BMK_seed(winnerInfo_t* winners, const ZSTD_compressionParameters para { BMK_result_t testResult; int better = 0; - unsigned cLevel; + int cLevel; BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, params); @@ -618,9 +618,9 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize) } /* establish speed objectives (relative to level 1) */ - { unsigned u; - for (u=2; u<=ZSTD_maxCLevel(); u++) - g_cSpeedTarget[u] = (g_cSpeedTarget[u-1] * 25) / 32; + { int i; + for (i=2; i<=ZSTD_maxCLevel(); i++) + g_cSpeedTarget[i] = (g_cSpeedTarget[i-1] * 25) / 32; } /* populate initial solution */ diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 30e0d01b7..466823222 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -90,7 +90,7 @@ static const char* g_defaultDictName = "dictionary"; static const unsigned g_defaultMaxDictSize = 110 KB; -static const unsigned g_defaultDictCLevel = 5; +static const int g_defaultDictCLevel = 5; static const unsigned g_defaultSelectivityLevel = 9; @@ -216,8 +216,8 @@ int main(int argCount, const char** argv) nextArgumentIsMaxDict=0, nextArgumentIsDictID=0, nextArgumentIsFile=0; - unsigned cLevel = ZSTDCLI_CLEVEL_DEFAULT; - unsigned cLevelLast = 1; + int cLevel = ZSTDCLI_CLEVEL_DEFAULT; + int cLevelLast = 1; unsigned recursive = 0; const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ unsigned filenameIdx = 0; @@ -227,7 +227,7 @@ int main(int argCount, const char** argv) char* dynNameSpace = NULL; unsigned maxDictSize = g_defaultMaxDictSize; unsigned dictID = 0; - unsigned dictCLevel = g_defaultDictCLevel; + int dictCLevel = g_defaultDictCLevel; unsigned dictSelect = g_defaultSelectivityLevel; #ifdef UTIL_HAS_CREATEFILELIST const char** fileNamesTable = NULL;