Class: Zstd::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/extzstd.rb,
ext/extzstd.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#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 searchlength: nil
opts targetlength: nil
opts strategy: nil


336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'ext/extzstd.c', line 336

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.searchLength, opts, "searchlength", NUM2UINT);
        SETUP_PARAM(p->cParams.targetLength, opts, "targetlength", NUM2UINT);
        SETUP_PARAM(p->cParams.strategy, opts, "strategy", NUM2UINT);
#undef SETUP_PARAM
    }

    return v;
}

Class Method Details

.preset(argv[], mod) ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/extzstd.c', line 417

static VALUE
params_s_get_preset(int argc, VALUE argv[], VALUE mod)
{
    int level;
    uint64_t sizehint;
    size_t dictsize;

    switch (argc) {
    case 0:
        level = 0;
        sizehint = 0;
        dictsize = 0;
        break;
    case 1:
        level = NUM2INT(argv[0]);
        sizehint = 0;
        dictsize = 0;
        break;
    case 2:
        level = NUM2INT(argv[0]);
        sizehint = NUM2ULL(argv[1]);
        dictsize = 0;
        break;
    case 3:
        level = NUM2INT(argv[0]);
        sizehint = NUM2ULL(argv[1]);
        dictsize = NUM2SIZET(argv[2]);
        break;
    default:
        rb_error_arity(argc, 0, 3);
    }

    ZSTD_parameters *p;
    VALUE v = TypedData_Make_Struct(mod, ZSTD_parameters, &params_type, p);
    *p = ZSTD_getParams(level, sizehint, dictsize);
    return v;
}

Instance Method Details

#chainlogObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#chainlog=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#hashlogObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#hashlog=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#initialize_copy(src) ⇒ Object



374
375
376
377
378
379
380
381
382
383
# File 'ext/extzstd.c', line 374

static VALUE
params_init_copy(VALUE params, VALUE src)
{
    ZSTD_parameters *a = getparams(params);
    ZSTD_parameters *b = getparams(src);
    rb_check_frozen(params);
    rb_obj_infect(params, src);
    memcpy(a, b, sizeof(*a));
    return params;
}

#inspectObject



249
250
251
252
253
# File 'lib/extzstd.rb', line 249

def inspect
  "#<#{self.class} windowlog=#{windowlog}, chainlog=#{chainlog}, " \
    "hashlog=#{hashlog}, searchlog=#{searchlog}, " \
    "searchlength=#{searchlength}, strategy=#{strategy}>"
end

#pretty_print(q) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/extzstd.rb', line 255

def pretty_print(q)
  q.group(2, "#<#{self.class}") do
    q.breakable " "
    q.text "windowlog=#{windowlog},"
    q.breakable " "
    q.text "chainlog=#{chainlog},"
    q.breakable " "
    q.text "hashlog=#{hashlog},"
    q.breakable " "
    q.text "searchlog=#{searchlog},"
    q.breakable " "
    q.text "searchlength=#{searchlength},"
    q.breakable " "
    q.text "targetlength=#{targetlength},"
    q.breakable " "
    q.text "strategy=#{strategy}>"
  end
end

#searchlengthObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#searchlength=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#searchlogObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#searchlog=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#strategyObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#strategy=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#targetlengthObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#targetlength=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.

#windowlogObject

Get/Set any field from/to struct ZSTD_parameters of C layer.

#windowlog=Object

Get/Set any field from/to struct ZSTD_parameters of C layer.