View Source Datadog.Sketch.IndexMapping.Logarithmic (Data Streams Ex v1.2.2)
LogarithmicMapping is an IndexMapping that is memory-optimal, that is to say that given a targeted relative accuracy, it requires the least number of indices to cover a given range of values. This is done by logarithmically mapping floating-point values to integers.
Note, since Erlang (and therefor Elixir) do math pretty differently than golang, this module does not contain a min or max indexable value. This follows in line with the Erlang philosophy of "let it crash" and simplifies our logic handling.
Summary
Functions
Checks if an index mapping matches another index mapping.
Returns value after mapping via logarithmic equation.
Returns the lower bound the mapping can contain.
Creates a new Logarithmic index mapping with the given accuracy.
Creates a new Logarithmic index mapping with the given gamma and index offset.
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.
Types
@type t() :: Datadog.Sketch.IndexMapping.t()
Functions
Checks if an index mapping matches another index mapping.
iex> implementation_one = Logarithmic.new(0.0000000000001)
...> implementation_two = Logarithmic.new(0.0000000000002)
...> Logarithmic.equals(implementation_one, implementation_two)
true
iex> implementation_one = Logarithmic.new(0.01)
...> implementation_two = Logarithmic.new(0.00001)
...> Logarithmic.equals(implementation_one, implementation_two)
false
Returns value after mapping via logarithmic equation.
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.index(index_mapping, 115)
237
iex> index_mapping = Logarithmic.new(0.001)
...> Logarithmic.index(index_mapping, 12345678901234567890)
21979
Returns the lower bound the mapping can contain.
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.lower_bound(index_mapping, 0)
1.0
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.lower_bound(index_mapping, 10)
1.2214109013609646
Creates a new Logarithmic index mapping with the given accuracy.
Examples
iex> Logarithmic.new(-1)
** (ArgumentError) The relative accuracy must be between 0, and 1.
iex> Logarithmic.new(0.01)
%Logarithmic{gamma: 1.02020202020202, multiplier: 49.99833328888678}
iex> Logarithmic.new(0.0001)
%Logarithmic{gamma: 1.0002000200020003, multiplier: 4999.999983331928}
Creates a new Logarithmic index mapping with the given gamma and index offset.
iex> Logarithmic.new(0.5, 0.0)
** (ArgumentError) Gamma must be greater than 1.
iex> Logarithmic.new(1.0002000200020003, 0.0)
%Logarithmic{gamma: 1.0002000200020003, multiplier: 4999.999983331928}
iex> Logarithmic.new(1.0002000200020003, 1.5)
%Logarithmic{gamma: 1.0002000200020003, index_offset: 1.5, multiplier: 4999.999983331928}
Returns the lower bound the mapping can contain.
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.relative_accuracy(index_mapping)
0.009999999999999898
Returns a Protobuf-able struct for the index mapping., Used for sending data to Datadog.
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.to_proto(index_mapping)
%Datadog.Sketch.Protobuf.IndexMapping{gamma: 1.02020202020202, interpolation: :NONE}
Takes a mapped value and returns the original value within the set accuracy.
iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.value(index_mapping, 237)
115.59680764552533
iex> index_mapping = Logarithmic.new(0.001)
...> Logarithmic.value(index_mapping, 21979)
1.23355147396003e19