mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Add support for negative levels in --adapt=min and --adapt=max"
This commit is contained in:
@ -354,6 +354,23 @@ static unsigned readU32FromChar(const char** stringPtr) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! readIntFromChar() :
|
||||||
|
* @return : signed integer value read from input in `char` format.
|
||||||
|
* allows and interprets K, KB, KiB, M, MB and MiB suffix.
|
||||||
|
* Will also modify `*stringPtr`, advancing it to position where it stopped reading.
|
||||||
|
* Note : function will exit() program if digit sequence overflows */
|
||||||
|
static int readIntFromChar(const char** stringPtr) {
|
||||||
|
static const char errorMsg[] = "error: numeric value overflows 32-bit int";
|
||||||
|
int sign = 1;
|
||||||
|
unsigned result;
|
||||||
|
if (**stringPtr=='-') {
|
||||||
|
(*stringPtr)++;
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
if (readU32FromCharChecked(stringPtr, &result)) { errorOut(errorMsg); }
|
||||||
|
return (int) result * sign;
|
||||||
|
}
|
||||||
|
|
||||||
/*! readSizeTFromCharChecked() :
|
/*! readSizeTFromCharChecked() :
|
||||||
* @return 0 if success, and store the result in *value.
|
* @return 0 if success, and store the result in *value.
|
||||||
* allows and interprets K, KB, KiB, M, MB and MiB suffix.
|
* allows and interprets K, KB, KiB, M, MB and MiB suffix.
|
||||||
@ -547,8 +564,8 @@ static ZDICT_fastCover_params_t defaultFastCoverParams(void)
|
|||||||
static unsigned parseAdaptParameters(const char* stringPtr, int* adaptMinPtr, int* adaptMaxPtr)
|
static unsigned parseAdaptParameters(const char* stringPtr, int* adaptMinPtr, int* adaptMaxPtr)
|
||||||
{
|
{
|
||||||
for ( ; ;) {
|
for ( ; ;) {
|
||||||
if (longCommandWArg(&stringPtr, "min=")) { *adaptMinPtr = (int)readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; }
|
if (longCommandWArg(&stringPtr, "min=")) { *adaptMinPtr = readIntFromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; }
|
||||||
if (longCommandWArg(&stringPtr, "max=")) { *adaptMaxPtr = (int)readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; }
|
if (longCommandWArg(&stringPtr, "max=")) { *adaptMaxPtr = readIntFromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; }
|
||||||
DISPLAYLEVEL(4, "invalid compression parameter \n");
|
DISPLAYLEVEL(4, "invalid compression parameter \n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1519,6 +1519,7 @@ then
|
|||||||
println "\n===> adaptive mode "
|
println "\n===> adaptive mode "
|
||||||
roundTripTest -g270000000 " --adapt"
|
roundTripTest -g270000000 " --adapt"
|
||||||
roundTripTest -g27000000 " --adapt=min=1,max=4"
|
roundTripTest -g27000000 " --adapt=min=1,max=4"
|
||||||
|
roundTripTest -g27000000 " --adapt=min=-2,max=-1"
|
||||||
println "===> test: --adapt must fail on incoherent bounds "
|
println "===> test: --adapt must fail on incoherent bounds "
|
||||||
datagen > tmp
|
datagen > tmp
|
||||||
zstd -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
|
zstd -f -vv --adapt=min=10,max=9 tmp && die "--adapt must fail on incoherent bounds"
|
||||||
|
Reference in New Issue
Block a user