Skip to main content

Module double_delta

Module double_delta 

Source
Expand description

DoubleDelta codec for timestamp columns.

Timestamps are monotonically increasing with near-constant intervals (e.g., every 10s). DoubleDelta encodes the difference-of-differences:

value[0]              → stored raw (8 bytes)
delta[0] = v[1]-v[0]  → stored raw (8 bytes)
dod[i]   = delta[i] - delta[i-1]  → bit-packed (usually 0 → 1 bit)

For constant-rate timestamps, all delta-of-deltas are 0, achieving ~1 bit per sample after the header. 4x better than Gorilla for timestamp columns.

Wire format:

[4 bytes] sample count (LE u32)
[8 bytes] first value (LE i64)
[8 bytes] first delta (LE i64)  — only present if count >= 2
[N bytes] bitstream of delta-of-deltas — only present if count >= 3

DoD bit-packing uses the same bucket scheme as Gorilla timestamps:

  • 0 → dod == 0
  • 10 + 7 bits → dod in [-63, 64]
  • 110 + 9 bits → dod in [-255, 256]
  • 1110 + 12 bits → dod in [-2047, 2048]
  • 1111 + 64 bits → arbitrary dod

Structs§

DoubleDeltaDecoder
Streaming DoubleDelta decoder. Wraps the batch decode() function.
DoubleDeltaEncoder
Streaming DoubleDelta encoder. Accumulates values and produces compressed bytes on finish().

Functions§

decode
Decode DoubleDelta-compressed bytes back to i64 values.
encode
Encode a slice of i64 values using DoubleDelta compression.