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

Basic module for handling various index mapping algorithms. All functions in this module proxy to the respective index mapping implementation module.

Summary

Types

t()

A general struct that has index mapping data. Every index mapping implementation must contain this data.

Callbacks

Checks if an index mapping matches another index mapping.

Returns value after mapping.

Returns the lower bound the mapping can contain.

Returns the relative accuracy of the mapping.

Returns a Protobuf-able struct for the index mapping. Used for sending data to Datadog.

Takes a mapped value and returns the original value within the set accuracy.

Functions

Checks if an index mapping matches another index mapping.

Returns value after mapping.

Returns the lower bound the mapping can contain.

Returns the lower bound the mapping can contain.

Returns a Protobuf-able struct for the index mapping. Used for sending data to Datadog.

Takes a mapped value and returns the original value within the set accuracy.

Checks if the two values are within the tolerance given.

Types

@type t() :: %{
  __struct__: module(),
  gamma: float(),
  index_offset: float(),
  multiplier: float()
}

A general struct that has index mapping data. Every index mapping implementation must contain this data.

Callbacks

@callback equals(t(), t()) :: boolean()

Checks if an index mapping matches another index mapping.

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

Returns value after mapping.

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

Returns the lower bound the mapping can contain.

@callback relative_accuracy(t()) :: float()

Returns the relative accuracy of the mapping.

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

Returns a Protobuf-able struct for the index mapping. Used for sending data to Datadog.

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

Takes a mapped value and returns the original value within the set accuracy.

Functions

@spec equals(t(), t()) :: boolean()

Checks if an index mapping matches another index mapping.

iex> implementation_one = IndexMapping.Logarithmic.new(0.0000000000001)
...> implementation_two = IndexMapping.Logarithmic.new(0.0000000000002)
...> IndexMapping.equals(implementation_one, implementation_two)
true

iex> implementation_one = IndexMapping.Logarithmic.new(0.01)
...> implementation_two = IndexMapping.Logarithmic.new(0.00001)
...> IndexMapping.equals(implementation_one, implementation_two)
false
@spec index(t(), float()) :: integer()

Returns value after mapping.

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.index(index_mapping, 115)
237

iex> index_mapping = IndexMapping.Logarithmic.new(0.001)
...> IndexMapping.index(index_mapping, 12345678901234567890)
21979
Link to this function

lower_bound(self, index)

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

Returns the lower bound the mapping can contain.

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.lower_bound(index_mapping, 0)
1.0

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.lower_bound(index_mapping, 10)
1.2214109013609646
@spec relative_accuracy(t()) :: float()

Returns the lower bound the mapping can contain.

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.relative_accuracy(index_mapping)
0.009999999999999898
@spec to_proto(t()) :: struct()

Returns a Protobuf-able struct for the index mapping. Used for sending data to Datadog.

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.to_proto(index_mapping)
%Datadog.Sketch.Protobuf.IndexMapping{gamma: 1.02020202020202, interpolation: :NONE}
@spec value(t(), integer()) :: float()

Takes a mapped value and returns the original value within the set accuracy.

iex> index_mapping = IndexMapping.Logarithmic.new(0.01)
...> IndexMapping.value(index_mapping, 237)
115.59680764552533

iex> index_mapping = IndexMapping.Logarithmic.new(0.001)
...> IndexMapping.value(index_mapping, 21979)
1.23355147396003e19
Link to this function

within_tolerance(x, y, tolerance)

View Source
@spec within_tolerance(float(), float(), float()) :: bool()

Checks if the two values are within the tolerance given.

Examples

iex> IndexMapping.within_tolerance(90, 134, 50)
true

iex> IndexMapping.within_tolerance(0.00128, 0.00864, 0.01)
false