View Source Datadog.Sketch.Store.Dense (Data Streams Ex v1.1.0)
The Dense store is a dynamically growing contiguous (non-sparse) store. The
number of bins are bound only by the size of the :array
that can be allocated.
Link to this section Summary
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.
Creates a new dense 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.
Link to this section Types
@type t() :: %Datadog.Sketch.Store.Dense{ bins: :array.array(), count: float(), max_index: integer(), min_index: integer(), offset: integer() }
Link to this section Functions
Adds a number to the store.
examples
Examples
iex> %Dense{} = Dense.add(Dense.new(), 100)
@spec add_bin(t(), Datadog.Sketch.Store.bin()) :: t()
Adds a bin type to the store.
examples
Examples
iex> %Dense{} = Dense.add_bin(Dense.new(), %{index: 100, count: 13.13})
@spec add_bins(t(), [Datadog.Sketch.Store.bin()]) :: t()
Adds multiple bin types to the store.
examples
Examples
iex> %Dense{} = Dense.add_bins(Dense.new(), [
...> %{index: 100, count: 13.13},
...> %{index: 20, count: 2342.4}
...> ])
Adds a number to the store count
number of times.
examples
Examples
iex> %Dense{} = Dense.add_with_count(Dense.new(), 100, 13.13)
iex> %Dense{} = Dense.add_with_count(Dense.new(), 987, 8.3e12)
@spec empty?(t()) :: bool()
Checks if the store has any information in it.
examples
Examples
iex> store = Dense.new()
...> Dense.empty?(store)
true
iex> store = Dense.add(Dense.new(), 754)
...> Dense.empty?(store)
false
Return the key for the value at rank.
examples
Examples
# Matches the golang implementation when no data is present.
iex> store = Dense.new()
...> Dense.key_at_rank(store, 0.0)
-134_217_729
# Verified matching to golang implementation
iex> store = Dense.add(Dense.new(), 128)
...> Dense.key_at_rank(store, 0.0)
128
# Verified matching to golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 12, count: 423.43},
...> %{index: 244, count: 1238.123},
...> %{index: 124, count: 2184.124}
...> ])
...> Dense.key_at_rank(store, 64.0)
12
Returns the maximum index of the store.
examples
Examples
iex> store = Dense.new()
...> Dense.max_index(store)
0
iex> store = Dense.add(Dense.new(), 128)
...> Dense.max_index(store)
128
# Verified against golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 4, count: 12.48},
...> %{index: 65, count: 12.48},
...> %{index: 37, count: 847.4}
...> ])
...> Dense.max_index(store)
65
Returns the minimum index of the store.
examples
Examples
iex> store = Dense.new()
...> Dense.min_index(store)
0
# Verified against golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 4, count: 12.48},
...> %{index: 65, count: 12.48},
...> %{index: 37, count: 847.4}
...> ])
...> Dense.min_index(store)
4
@spec new() :: t()
Creates a new dense store.
examples
Examples
iex> Dense.new()
%Dense{}
Maps over all values and multiplies by the given weight.
examples
Examples
# Verified matching to golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 4, count: 10.0},
...> %{index: 2, count: 20.0},
...> %{index: 6, count: 30.0}
...> ])
...> store = Dense.reweight(store, 2)
...> Dense.total_count(store)
120.0
@spec to_proto(t()) :: Datadog.Sketch.Protobuf.Store.t()
Returns a struct for Protobuf encoding. Used for sending data to Datadog.
examples
Examples
# Verified matching to golang implementation
iex> store = Dense.add(Dense.new(), 4)
...> Dense.to_proto(store)
%Datadog.Sketch.Protobuf.Store{
binCounts: [],
contiguousBinCounts: [1.0],
contiguousBinIndexOffset: 4
}
# Verified matching to golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 4, count: 12.48},
...> %{index: 65, count: 12.48},
...> %{index: 37, count: 847.4}
...> ])
...> Dense.to_proto(store)
%Datadog.Sketch.Protobuf.Store{
binCounts: [],
contiguousBinCounts: [12.48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 847.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12.48],
contiguousBinIndexOffset: 4
}
Returns the total amount of counts stored.
examples
Examples
iex> store = Dense.new()
...> Dense.total_count(store)
0.0
iex> store = Dense.add(Dense.new(), 754)
...> Dense.total_count(store)
1.0
iex> store = Dense.add_with_count(Dense.new(), 754, 42.42)
...> Dense.total_count(store)
42.42
# Verified against golang implementation
iex> store = Dense.add_bins(Dense.new(), [
...> %{index: 4, count: 12.48},
...> %{index: 65, count: 12.48},
...> %{index: 37, count: 847.4}
...> ])
...> Dense.total_count(store)
872.36