Logos.SortedSet (Logos v0.2.0)

Copy Markdown

A Logos sorted set: (sorted-set ...) / (sorted-set-by cmp ...).

Logos.SortedMap's exact counterpart, minus the value half of each entry -- see that module's moduledoc for the full reasoning (sorted association list, cmp a plain 2-arity Elixir function built once by Logos.Primitives, genuine new runtime value type with its own type-of tag :sorted-set, content-equal to a hash-set with the same elements, prints as #{...} in sorted order with no dedicated reader syntax).

Summary

Functions

Number of elements.

Returns a new sorted set with elem removed (a no-op if absent).

True if elem is a member.

Builds a sorted set from elems and comparator cmp.

Returns a new sorted set with elem added (a no-op if already present).

Converts to a plain Elixir list, in sorted order.

Types

cmp_fn()

@type cmp_fn() :: (term(), term() -> :lt | :eq | :gt)

t()

@type t() :: %Logos.SortedSet{cmp: cmp_fn(), entries: [term()]}

Functions

count(sorted_set)

@spec count(t()) :: non_neg_integer()

Number of elements.

delete(s, elem)

@spec delete(t(), term()) :: t()

Returns a new sorted set with elem removed (a no-op if absent).

member?(sorted_set, elem)

@spec member?(t(), term()) :: boolean()

True if elem is a member.

new(elems, cmp)

@spec new([term()], cmp_fn()) :: t()

Builds a sorted set from elems and comparator cmp.

put(s, elem)

@spec put(t(), term()) :: t()

Returns a new sorted set with elem added (a no-op if already present).

to_list(sorted_set)

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

Converts to a plain Elixir list, in sorted order.