ddskerl behaviour (ddskerl v0.5.0)

View Source

DDSketch behaviour.

Summary

Types

A single non-empty bucket of a DDSketch.

Index identifying a bucket within a DDSketch.

DDSketch instance.

Options for the DDSketch.

Callbacks

Export all non-empty buckets of a DDSketch, in ascending order of value.

Fold over all non-empty buckets of a DDSketch, in ascending order of value.

Insert a value into the DDSketch.

Merge two DDSketch instances.

Create a new DDSketch instance.

Calculate the quantile of a DDSketch.

Get the sum number of elements in the DDSketch.

Get the total number of elements in the DDSketch.

Types

bucket()

-type bucket() ::
          #{index := bucket_index(),
            lower := float(),
            upper := float() | infinity,
            count := pos_integer()}.

A single non-empty bucket of a DDSketch.

count values were inserted into the bucket, and all of them fall within (lower, upper], with the exception of the zero bucket, for which both lower and upper are 0.0.

Note that the bounds are the ones the bucket is defined by, not the ones of the values actually inserted: for the smallest bucket of a saturated ddskerl_bound sketch, which collapses buckets on demand, lower is only a lower estimate.

bucket_index()

-type bucket_index() :: integer() | zero | underflow | overflow.

Index identifying a bucket within a DDSketch.

A regular bucket is identified by an integer I and covers the values in the interval (gamma^(I-1), gamma^I]. Values that cannot be indexed that way are accumulated in the following special buckets:

  • zero, for values of exactly zero, as log(0) is undefined;
  • underflow, for values too small for the smallest allocated bucket;
  • overflow, for values too large for the largest allocated bucket.

Which of the special buckets a given implementation uses depends on whether its buckets are preallocated, see bucket/0.

ddsketch()

DDSketch instance.

opts()

-type opts() :: #{atom() => dynamic()}.

Options for the DDSketch.

Callbacks

buckets/1

-callback buckets(ddsketch()) -> [bucket()].

Export all non-empty buckets of a DDSketch, in ascending order of value.

foldl/3

-callback foldl(ddsketch(), Fun, Acc0) -> Acc1
                   when
                       Fun :: fun((Bucket :: bucket(), AccIn :: term()) -> AccOut :: term()),
                       Acc0 :: term(),
                       Acc1 :: term().

Fold over all non-empty buckets of a DDSketch, in ascending order of value.

Empty buckets are never given to the folding function, hence preallocated implementations only export the buckets they actually used.

insert/2

-callback insert(ddsketch(), number()) -> ddsketch().

Insert a value into the DDSketch.

merge/2

-callback merge(ddsketch(), ddsketch()) -> ddsketch().

Merge two DDSketch instances.

new/1

-callback new(opts()) -> ddsketch().

Create a new DDSketch instance.

quantile/2

-callback quantile(ddsketch(), float()) -> float() | undefined.

Calculate the quantile of a DDSketch.

sum/1

-callback sum(ddsketch()) -> number().

Get the sum number of elements in the DDSketch.

total/1

-callback total(ddsketch()) -> non_neg_integer().

Get the total number of elements in the DDSketch.