Module: Zstd::Dictionary

Defined in:
ext/extzstd.c

Class Method Summary collapse

Class Method Details

.add_entropy_tables_from_buffer(dict, dict_capacity, sample) ⇒ Object



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'ext/extzstd.c', line 457

static VALUE
dict_s_add_entropy_tables_from_buffer(VALUE mod, VALUE dict, VALUE dict_capacity, VALUE sample)
{
    /*
     * size_t ZDICT_addEntropyTablesFromBuffer(
     *      void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
     *      const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
     */

    rb_check_type(dict, RUBY_T_STRING);
    rb_check_type(sample, RUBY_T_STRING);
    size_t capa = NUM2SIZET(dict_capacity);
    aux_str_modify_expand(dict, capa);
    size_t samplesize = RSTRING_LEN(sample);
    size_t s = ZDICT_addEntropyTablesFromBuffer(RSTRING_PTR(dict), RSTRING_LEN(dict), capa, RSTRING_PTR(sample), &samplesize, 1);
    extzstd_check_error(s);
    rb_str_set_len(dict, s);
    return dict;
}

.getid(dict) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'ext/extzstd.c', line 477

static VALUE
dict_s_getid(VALUE mod, VALUE dict)
{
    /*
     * ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize);
     */

    rb_check_type(dict, RUBY_T_STRING);
    const char *p;
    size_t psize;
    RSTRING_GETMEM(dict, p, psize);

    size_t s = ZDICT_getDictID(p, psize);
    extzstd_check_error(s);

    return SIZET2NUM(s);
}

.train_from_buffer(src, dict_capacity) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'ext/extzstd.c', line 439

static VALUE
dict_s_train_from_buffer(VALUE mod, VALUE src, VALUE dict_capacity)
{
    rb_check_type(src, RUBY_T_STRING);
    size_t capa = NUM2SIZET(dict_capacity);
    VALUE dict = rb_str_buf_new(capa);
    size_t srcsize = RSTRING_LEN(src);
    const ZDICT_legacy_params_t params = { 0 };
    size_t s = ZDICT_trainFromBuffer_legacy(RSTRING_PTR(dict), capa, RSTRING_PTR(src), &srcsize, 1, params);
    extzstd_check_error(s);
    rb_str_set_len(dict, s);
    return dict;
}