# `GorillaStream.Compression.Encoder.DeltaEncoding`
[🔗](https://github.com/awksedgreep/gorilla_stream/blob/main/lib/gorilla_stream/compression/encoder/delta_encoding.ex#L1)

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.

# `encode`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
