Skip to content

File syn_lz4.c

FileList > src > syntropic > util > syn_lz4.c

Go to the source code of this file

Implementation of Zero-Heap LZ4 Raw Block Compression & Decompression.

  • #include "syn_lz4.h"
  • #include <string.h>

Public Functions

Type Name
size_t syn_lz4_compress (SYN_Lz4 * ctx, const void * src, size_t src_size, void * dst, size_t dst_capacity)
Compress data buffer into LZ4 raw block format.
size_t syn_lz4_compress_bound (size_t input_size)
Calculate worst-case compressed output bound for a given input size.
size_t syn_lz4_decompress (const void * src, size_t src_size, void * dst, size_t dst_capacity)
Decompress LZ4 raw block buffer.
SYN_Status syn_lz4_init (SYN_Lz4 * ctx)
Initialize an LZ4 compression context.

Public Static Functions

Type Name
uint32_t lz4_hash4 (uint32_t val)
Hash 4 bytes into 12-bit hash index using Knuth multiplicative hash.
uint32_t lz4_read32 (const uint8_t * ptr)
Read 32-bit little-endian word from unaligned byte pointer.

Macros

Type Name
define LZ4_HASH_BITS 12U
define LZ4_MIN_MATCH 4U

Public Functions Documentation

function syn_lz4_compress

Compress data buffer into LZ4 raw block format.

size_t syn_lz4_compress (
    SYN_Lz4 * ctx,
    const void * src,
    size_t src_size,
    void * dst,
    size_t dst_capacity
) 

Parameters:

  • ctx Pointer to initialized LZ4 context.
  • src Source data buffer to compress.
  • src_size Source data size in bytes.
  • dst Destination buffer for compressed output.
  • dst_capacity Capacity of destination buffer in bytes.

Returns:

Number of compressed bytes written to dst, or 0 on error/overflow.


function syn_lz4_compress_bound

Calculate worst-case compressed output bound for a given input size.

size_t syn_lz4_compress_bound (
    size_t input_size
) 

Parameters:

  • input_size Uncompressed payload size in bytes.

Returns:

Maximum compressed buffer size required.


function syn_lz4_decompress

Decompress LZ4 raw block buffer.

size_t syn_lz4_decompress (
    const void * src,
    size_t src_size,
    void * dst,
    size_t dst_capacity
) 

Decompression is fully stateless and requires no context workspace.

Parameters:

  • src Compressed source buffer.
  • src_size Compressed source size in bytes.
  • dst Destination buffer for decompressed output.
  • dst_capacity Capacity of destination buffer in bytes.

Returns:

Number of decompressed bytes written to dst, or 0 on corruption/overflow.


function syn_lz4_init

Initialize an LZ4 compression context.

SYN_Status syn_lz4_init (
    SYN_Lz4 * ctx
) 

Parameters:

  • ctx Pointer to LZ4 context instance.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


Public Static Functions Documentation

function lz4_hash4

Hash 4 bytes into 12-bit hash index using Knuth multiplicative hash.

static inline uint32_t lz4_hash4 (
    uint32_t val
) 

Parameters:

  • val 32-bit integer word to hash.

Returns:

12-bit hash index (0..4095).


function lz4_read32

Read 32-bit little-endian word from unaligned byte pointer.

static inline uint32_t lz4_read32 (
    const uint8_t * ptr
) 

Parameters:

  • ptr Pointer to byte stream.

Returns:

32-bit unsigned integer value.


Macro Definition Documentation

define LZ4_HASH_BITS

#define LZ4_HASH_BITS `12U`

Log2 size of 4096-entry hash table


define LZ4_MIN_MATCH

#define LZ4_MIN_MATCH `4U`

Minimum byte match length for LZ4 compression



The documentation for this class was generated from the following file src/syntropic/util/syn_lz4.c