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


250
251
252
253
254
255
256
257
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
# File 'ext/extzstd.c', line 250

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



331
332
333
334
335
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
# File 'ext/extzstd.c', line 331

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



288
289
290
291
292
293
294
295
296
297
# File 'ext/extzstd.c', line 288

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



296
297
298
299
300
# File 'lib/extzstd.rb', line 296

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

#pretty_print(q) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/extzstd.rb', line 302

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.