ScoutApm.ScoredItemSet (scout_apm v2.0.0)

Copy Markdown

A 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

key()

@type key() :: String.t()

options()

@type options() :: %{max_count: pos_integer()}

score()

@type score() :: {:score, number(), key()}

scored_item()

@type scored_item() :: {score(), any()}

t()

@type t() :: %ScoutApm.ScoredItemSet{
  data: %{required(any()) => scored_item()},
  options: options()
}

Functions

absorb(set, scored_item)

@spec absorb(t(), scored_item()) :: t()

new()

@spec new() :: t()

set_max_count(set, max_count)

@spec set_max_count(t(), pos_integer()) :: t()

size(set)

@spec size(t()) :: non_neg_integer()

to_list(set)

@spec to_list(t()) :: [scored_item()]

to_list(set, atom)

@spec to_list(t(), :without_scores) :: [scored_item()]