# View Source Datadog.Sketch.IndexMapping.Logarithmic(Data Streams Ex v1.1.0)

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.

# Link to this section 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.

# t()

View Source
`@type t() :: Datadog.Sketch.IndexMapping.t()`

# equals(map1, map2)

View Source
`@spec equals(t(), t()) :: boolean()`

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``````

# index(map, value)

View Source
`@spec index(t(), float()) :: integer()`

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``````

# lower_bound(map, index)

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

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``````

# new(relative_accuracy)

View Source
`@spec new(float()) :: t() | no_return()`

Creates a new Logarithmic index mapping with the given accuracy.

## examples 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}``````

# new(gamma, index_offset)

View Source
`@spec new(float(), float()) :: t() | no_return()`

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}``````

# relative_accuracy(map)

View Source
`@spec relative_accuracy(t()) :: float()`

Returns the lower bound the mapping can contain.

``````iex> index_mapping = Logarithmic.new(0.01)
...> Logarithmic.relative_accuracy(index_mapping)
0.009999999999999898``````

# to_proto(self)

View Source
`@spec to_proto(t()) :: struct()`

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)

# value(self, index)

View Source
`@spec value(t(), integer()) :: float()`

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``````