GorillaStream.Compression.Gorilla.Encoder (gorilla_stream v3.0.1)

Copy Markdown View Source

Main encoder for the Gorilla compression algorithm.

This module coordinates the compression pipeline:

  1. Separates timestamps and values from the input stream
  2. Applies delta-of-delta encoding to timestamps
  3. Applies XOR-based compression to values
  4. Packs both bitstreams together
  5. Adds metadata header

The Gorilla algorithm is specifically designed for time series data with regularly spaced timestamps and slowly changing floating-point values.

Summary

Functions

Encodes a stream of {timestamp, float} tuples using the Gorilla compression algorithm.

Pure-Elixir encode, used as fallback when NIF is unavailable.

Estimates the compression ratio for given data without full compression.

Returns true if the native NIF encoder is available.

Functions

encode(data, opts \\ [])

Encodes a stream of {timestamp, float} tuples using the Gorilla compression algorithm.

This is an optimized implementation that skips some validation checks for better performance. Input data is assumed to be valid {timestamp, float} tuples.

Parameters

  • data: List of {timestamp, float} tuples

Returns

  • {:ok, encoded_data}: When encoding is successful
  • {:error, reason}: When encoding fails

encode_elixir(data, opts)

Pure-Elixir encode, used as fallback when NIF is unavailable.

estimate_compression_ratio(data)

Estimates the compression ratio for given data without full compression.

This is useful for determining if Gorilla compression would be beneficial for a particular dataset.

Parameters

  • data: List of {timestamp, float} tuples

Returns

  • {:ok, estimated_ratio}: Estimated compression ratio (compressed_size / original_size)
  • {:error, reason}: If estimation fails

nif_available?()

Returns true if the native NIF encoder is available.