Class: RLZ4::BlockCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/rlz4/block_codec.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(dict: nil) ⇒ Object

Block-format LZ4 compression with a reusable scratch hash table.

Dict is passed once at construction time and baked into the codec: the dict is hashed into a pristine table exactly once in ‘.new`, and every subsequent `#compress` call restores that pristine state via a 16 KiB memcpy before running the block compressor. This amortises dict initialisation across the codec’s lifetime rather than paying ~3-5 µs per call to re-hash the dict.

‘#compress` mutates the scratch table; `#decompress` does not. Both live on the same class so callers hold one object per worker.

A BlockCodec must not cross Ractor boundaries. Per-Ractor codecs are the natural unit.

Parameters:

  • dict (Dictionary, String, nil) (defaults to: nil)

    dictionary bytes or a Dictionary value wrapping them. The id on a Dictionary is ignored (block format has no Dict_ID field); we only consult the bytes.



26
27
28
# File 'lib/rlz4/block_codec.rb', line 26

def self.new(dict: nil)
  _native_new(Dictionary === dict ? dict.bytes : dict)
end

Instance Method Details

#decompress(bytes, decompressed_size:) ⇒ Object



31
32
33
# File 'lib/rlz4/block_codec.rb', line 31

def decompress(bytes, decompressed_size:)
  _decompress(bytes, decompressed_size)
end