# `DdDataStreams.Sketch`
[🔗](https://github.com/rockneurotiko/dd_data_streams/blob/main/lib/dd_data_streams/sketch.ex#L1)

A DDSketch distribution: values are counted in logarithmically sized bins so
that a whole distribution serialises into a compact protobuf message.

Only what the datastreams wire format needs is implemented: `new/0`, `add/2`
and `to_proto/1`. The mapping is the one dd-trace-go v2.11.2 and
dd-trace-java 1.67.1 emit, gamma 1.015625 with index offset
1.8761281912861705; the mapping is self-describing in the payload (gamma and
offset travel with it). dd-trace-py uses offset 1338.5, so its bins do not
line up with Go/Java. The store is dense, so the encoded bin counts are
contiguous with empty bins written as zeros.

Values whose magnitude is too small to map count as zero, and negative values
are counted in a second store, indexed by their magnitude.

# `t`

```elixir
@type t() :: %DdDataStreams.Sketch{
  negative: %{optional(integer()) =&gt; float()},
  positive: %{optional(integer()) =&gt; float()},
  zero_count: float()
}
```

# `add`

```elixir
@spec add(t(), number()) :: t()
```

Adds `value` to the distribution and returns the updated distribution.

# `new`

```elixir
@spec new() :: t()
```

Returns an empty distribution.

# `to_proto`

```elixir
@spec to_proto(t()) :: binary()
```

Encodes the distribution as a protobuf `DDSketch` message.

---

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