Method: Zstd::Parameters#initialize

Defined in:
ext/extzstd.c

#initialize(preset_level = 1, srcsize_hint = 0, dictsize = 0, opts = {}) ⇒ Object

Initialize struct ZSTD_parameters of C layer.

preset_level = 1
srcsize_hint = 0
opts windowlog: nil
opts contentlog: nil
opts hashlog: nil
opts searchlog: nil
opts minmatch: nil
opts targetlength: nil
opts strategy: nil


258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'ext/extzstd.c', line 258

static VALUE
params_init(int argc, VALUE argv[], VALUE v)
{
    ZSTD_parameters *p = getparams(v);
    uint64_t sizehint;
    size_t dictsize;
    int level;
    VALUE opts = Qnil;

    argc = rb_scan_args(argc, argv, "03:", NULL, NULL, NULL, &opts);
    level = argc > 0 ? aux_num2int(argv[0], 0) : 0;
    sizehint = argc > 1 ? aux_num2int_u64(argv[1], 0) : 0;
    dictsize = argc > 2 ? aux_num2int_u64(argv[2], 0) : 0;

    *p = ZSTD_getParams(level, sizehint, dictsize);

    if (!NIL_P(opts)) {
#define SETUP_PARAM(var, opts, key, converter)                          \
        do {                                                            \
            VALUE tmp = rb_hash_lookup(opts, ID2SYM(rb_intern(key)));   \
            if (!NIL_P(tmp)) {                                          \
                var = converter(tmp);                                   \
            }                                                           \
        } while (0)                                                     \

        SETUP_PARAM(p->cParams.windowLog, opts, "windowlog", NUM2UINT);
        SETUP_PARAM(p->cParams.chainLog, opts, "chainlog", NUM2UINT);
        SETUP_PARAM(p->cParams.hashLog, opts, "hashlog", NUM2UINT);
        SETUP_PARAM(p->cParams.searchLog, opts, "searchlog", NUM2UINT);
        SETUP_PARAM(p->cParams.minMatch, opts, "minmatch", NUM2UINT);
        SETUP_PARAM(p->cParams.targetLength, opts, "targetlength", NUM2UINT);
        SETUP_PARAM(p->cParams.strategy, opts, "strategy", NUM2UINT);
        SETUP_PARAM(p->fParams.contentSizeFlag, opts, "contentsize", RTEST);
        SETUP_PARAM(p->fParams.checksumFlag, opts, "checksum", RTEST);
        SETUP_PARAM(p->fParams.noDictIDFlag, opts, "nodictid", RTEST);
#undef SETUP_PARAM
    }

    return v;
}