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



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'ext/extzstd.c', line 531

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



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'ext/extzstd.c', line 551

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



514
515
516
517
518
519
520
521
522
523
524
525
# File 'ext/extzstd.c', line 514

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);
    size_t s = ZDICT_trainFromBuffer(RSTRING_PTR(dict), capa, RSTRING_PTR(src), &srcsize, 1);
    extzstd_check_error(s);
    rb_str_set_len(dict, s);
    return dict;
}