Class: VibeZstd::CDict

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

Overview

Add helper method to CDict for creating matching DDict

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.estimate_memory(dict_size, level) ⇒ Object

CDict.estimate_memory(dict_size, level)



543
544
545
546
547
548
549
# File 'ext/vibe_zstd/dict.c', line 543

static VALUE
vibe_zstd_cdict_estimate_memory(VALUE self, VALUE dict_size, VALUE level) {
    size_t size = NUM2SIZET(dict_size);
    int lvl = NUM2INT(level);
    size_t estimate = ZSTD_estimateCDictSize(size, lvl);
    return SIZET2NUM(estimate);
}

Instance Method Details

#dict_idObject

CDict dict_id method - returns dictionary ID



59
60
61
62
63
64
65
66
67
68
# File 'ext/vibe_zstd/dict.c', line 59

static VALUE
vibe_zstd_cdict_dict_id(VALUE self) {
    vibe_zstd_cdict* cdict;
    TypedData_Get_Struct(self, vibe_zstd_cdict, &vibe_zstd_cdict_type, cdict);
    if (!cdict->cdict) {
        rb_raise(rb_eRuntimeError, "CDict not initialized");
    }
    unsigned dictID = ZSTD_getDictID_fromCDict(cdict->cdict);
    return UINT2NUM(dictID);
}

#sizeObject

CDict size method - returns the size in memory



47
48
49
50
51
52
53
54
55
56
# File 'ext/vibe_zstd/dict.c', line 47

static VALUE
vibe_zstd_cdict_size(VALUE self) {
    vibe_zstd_cdict* cdict;
    TypedData_Get_Struct(self, vibe_zstd_cdict, &vibe_zstd_cdict_type, cdict);
    if (!cdict->cdict) {
        rb_raise(rb_eRuntimeError, "CDict not initialized");
    }
    size_t size = ZSTD_sizeof_CDict(cdict->cdict);
    return SIZET2NUM(size);
}

#to_ddictDDict Also known as: ddict

Get or create a matching DDict from this CDict’s dictionary data The DDict is cached so it’s only created once

Returns:

  • (DDict)

    Decompression dictionary matching this compression dictionary



68
69
70
# File 'lib/vibe_zstd.rb', line 68

def to_ddict
  @ddict ||= DDict.new(@dict_data)
end