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

Copy Markdown View Source

Delta-of-delta encoding for timestamps as used in the Gorilla compression algorithm.

The algorithm works as follows:

  1. Store the first timestamp as-is (64 bits)
  2. Store the delta between the second and first timestamp (variable length)
  3. For subsequent timestamps, compute delta-of-delta and encode with variable length:
    • If delta-of-delta is 0: store single bit '0'
    • If delta-of-delta fits in [-63, 64]: store '10' + 7 bits
    • If delta-of-delta fits in [-255, 256]: store '110' + 9 bits
    • If delta-of-delta fits in [-2047, 2048]: store '1110' + 12 bits
    • Otherwise: store '1111' + 32 bits

This encoding is highly efficient for regularly spaced time series data.

Summary

Functions

Encodes a list of timestamps using delta-of-delta compression.

Functions

encode(timestamps)

Encodes a list of timestamps using delta-of-delta compression.

Parameters

  • timestamps: List of integer timestamps

Returns

  • {encoded_bits, metadata}: Tuple containing the encoded bits as binary and metadata