View Source Datadog.Sketch.Store behaviour (Data Streams Ex v1.2.2)

Different stores use different data structures and techniques to store data. Each with unique trade offs and memory usage. All functions in this module proxy to the respective index mapping implementation module.

All stores implement the Enumerable protocol to iterate over all stored data easily.

Summary

Types

A concise way to specify an index and count in one arg.

t()

A basic struct. This is used to keep tight type definitions. Each store implements this struct differently.

Callbacks

Adds a number to the store.

Adds a bin type to the store.

Adds multiple bin types to the store.

Adds a number to the store count number of times.

Checks if the store has any information in it.

Return the key for the value at rank.

Returns the maximum index of the store.

Returns the minimum index of the store.

Maps over all values and multiplies by the given weight.

Returns a struct for Protobuf encoding. Used for sending data to Datadog.

Returns the total amount of counts stored.

Functions

Adds a number to the store.

Adds a bin type to the store.

Adds multiple bin types to the store.

Adds a number to the store count number of times.

Checks if the store has any information in it.

Return the key for the value at rank.

Returns the maximum index of the store.

Returns the minimum index of the store.

Maps over all values and multiplies by the given weight.

Returns a struct for Protobuf encoding. Used for sending data to Datadog.

Returns the total amount of counts stored.

Types

@type bin() :: %{index: integer(), count: float()}

A concise way to specify an index and count in one arg.

@type t() :: struct()

A basic struct. This is used to keep tight type definitions. Each store implements this struct differently.

Callbacks

@callback add(t(), integer()) :: t()

Adds a number to the store.

@callback add_bin(t(), bin()) :: t()

Adds a bin type to the store.

@callback add_bins(t(), [bin()]) :: t()

Adds multiple bin types to the store.

Link to this callback

add_with_count(t, integer, float)

View Source
@callback add_with_count(t(), integer(), float()) :: t()

Adds a number to the store count number of times.

@callback empty?(t()) :: bool()

Checks if the store has any information in it.

@callback key_at_rank(t(), float()) :: integer()

Return the key for the value at rank.

@callback max_index(t()) :: integer()

Returns the maximum index of the store.

@callback min_index(t()) :: integer()

Returns the minimum index of the store.

@callback reweight(t(), float()) :: t()

Maps over all values and multiplies by the given weight.

@callback to_proto(t()) :: struct()

Returns a struct for Protobuf encoding. Used for sending data to Datadog.

@callback total_count(t()) :: float()

Returns the total amount of counts stored.

Functions

@spec add(t(), integer()) :: t()

Adds a number to the store.

Examples

iex> %Store.Dense{} = Store.add(Store.Dense.new(), 100)
@spec add_bin(t(), bin()) :: t()

Adds a bin type to the store.

Examples

iex> %Store.Dense{} = Store.add_bin(Store.Dense.new(), %{index: 100, count: 13.13})
@spec add_bins(t(), [bin()]) :: t()

Adds multiple bin types to the store.

Examples

  iex> %Store.Dense{} = Store.add_bins(Store.Dense.new(), [
  ...>   %{index: 100, count: 13.13},
  ...>   %{index: 20, count: 2342.4}
  ...> ])
Link to this function

add_with_count(self, index, count)

View Source
@spec add_with_count(t(), integer(), float()) :: t()

Adds a number to the store count number of times.

Examples

iex> %Store.Dense{} = Store.add_with_count(Store.Dense.new(), 100, 13.13)

iex> %Store.Dense{} = Store.add_with_count(Store.Dense.new(), 987, 8.3e12)
@spec empty?(t()) :: bool()

Checks if the store has any information in it.

Examples

iex> store = Store.Dense.new()
...> Store.empty?(store)
true

iex> store = Store.add(Store.Dense.new(), 754)
...> Store.empty?(store)
false
@spec key_at_rank(t(), float()) :: integer()

Return the key for the value at rank.

Examples

  iex> store = Store.add(Store.Dense.new(), 128)
  ...> Store.key_at_rank(store, 0.0)
  128
@spec max_index(t()) :: integer()

Returns the maximum index of the store.

Examples

  iex> store = Store.Dense.new()
  ...> Store.max_index(store)
  0
@spec min_index(t()) :: integer()

Returns the minimum index of the store.

Examples

iex> store = Store.Dense.new()
...> Store.min_index(store)
0
@spec reweight(t(), float()) :: t()

Maps over all values and multiplies by the given weight.

Examples

  iex> store = Store.add_bins(Store.Dense.new(), [
  ...>   %{index: 4, count: 10.0},
  ...>   %{index: 2, count: 20.0},
  ...>   %{index: 6, count: 30.0}
  ...> ])
  ...> store = Store.reweight(store, 2)
  ...> Store.total_count(store)
  120.0
@spec to_proto(t()) :: struct()

Returns a struct for Protobuf encoding. Used for sending data to Datadog.

Examples

  iex> %Datadog.Sketch.Protobuf.Store{} = Store.to_proto(Store.Dense.new())
@spec total_count(t()) :: float()

Returns the total amount of counts stored.

Examples

iex> store = Store.Dense.new()
...> Store.total_count(store)
0.0

iex> store = Store.add_with_count(Store.Dense.new(), 754, 42.42)
...> Store.total_count(store)
42.42