ScoutApm.ScoredItemSet (scout_apm v2.0.0)
Copy MarkdownA capped set type that has a few rules on inclusion.
When you add an item, it must be a tuple of shape: {{:score, integer, key}, item}
Where the key uniquely identifies the item, as a string. The score is a unitless relative "value" of this item, and then the item itself can be any structure
Only the highest score of each key is kept, no duplicates, even if the set has "room" for it.
Only the highest scores will be kept when at capacity. Adding a new element may or may result in the new item evicting an old one, or being simply dropped, based on the comparison of the scores.
Summary
Types
@type key() :: String.t()
@type options() :: %{max_count: pos_integer()}
@type t() :: %ScoutApm.ScoredItemSet{ data: %{required(any()) => scored_item()}, options: options() }
Functions
@spec absorb(t(), scored_item()) :: t()
@spec new() :: t()
@spec set_max_count(t(), pos_integer()) :: t()
@spec size(t()) :: non_neg_integer()
@spec to_list(t()) :: [scored_item()]
@spec to_list(t(), :without_scores) :: [scored_item()]