c++zstdzstandard

Zstandart(zstd) - how use fucntion ZSTD_CCtx_setParameter


Tried to figure out how to restore values when using the ZSTD_CCtx setParameter function.

I understood only on the example of setting the compression level, like this for example:

cctx = ZSTD_createCCtx();

size_t ZSTD_CCtx_setParameter_ = ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 22);

 status_error = ZSTD_isError(ZSTD_CCtx_setParameter_);

if (status_error != 0)
{
    std::cout<<ZSTD_getErrorName(ZSTD_CCtx_setParameter_)<<std::endl;
    return 1;
}

In this case, everything is clear - the Enum "ZSTD_c_compressionLevel" parameter is passed to the function and the compression level is set to choose from from 0 to 22.

But here's an example:

ZSTD_c_enableLongDistanceMatching; //Enable long distance matching.


cctx = ZSTD_createCCtx();

size_t ZSTD_CCtx_setParameter_ = ZSTD_CCtx_setParameter(cctx, ZSTD_c_enableLongDistanceMatching, ???);

And how to Enable it then?? What value should I set then?? The description doesn't say anything about it.

Tell me please.


Solution

  • Use the source, Luke.

    Right above the documentation for the ZSTD_CCtx_setParameter function is the following:

    ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);

    All parameters must belong to an interval with lower and upper bounds, otherwise they will either trigger an error or be automatically clamped. @return : a structure, ZSTD_bounds, which contains
    - an error status field, which must be tested using ZSTD_isError()
    - lower and upper bounds, both inclusive

    And peering into the implementation of that function you can find the applicable lower and upper bounds:

        case ZSTD_c_enableLongDistanceMatching:
            bounds.lowerBound = (int)ZSTD_ps_auto;
            bounds.upperBound = (int)ZSTD_ps_disable;
            return bounds;
    

    In summary, the answer to your question is:

    ZSTD_CCtx_setParameter(cctx, ZSTD_c_enableLongDistanceMatching, (int)ZSTD_ps_enable);