One9.Ms (oMultiset v0.1.1)
Operations on simple non-struct multiplicity maps ("multisets", t/1
).
"Non-well-formed" multisets include some entries for absent elements (%{"damn" => 0}
),
and may be accepted for certain operations for convenience.
Summary
Functions
Return the cardinality of a multiset.
Determine the multiplicity of an element in a multiset.
Create a well-formed multiset from any (finite) Enumerable of {t:term/0, t:non_neg_integer/0}
tuples.
Create a well-formed multiset from any (finite) Enumerable of values.
Determine whether a value is present at all in a multiset.
Determine whether the first multiset is a (non-strict) subset of the second.
Convert a multiset into a List of unique elements.
Return the cardinality of the support of a multiset.
Convert a multiset into a complete List of elements (including repeats).
Return the union of two multisets.
Types
@type t0(value) :: Enumerable.t({value, non_neg_integer()})
@type t(value) :: %{optional(value) => pos_integer()}
@type t_lax(value) :: %{optional(value) => non_neg_integer()}
Functions
@spec at(t0(e), non_neg_integer()) :: e when e: term()
@spec count(t_lax()) :: non_neg_integer()
Return the cardinality of a multiset.
Input may be non-well-formed.
See also support_count/1
.
@spec count_element(t_lax(), term()) :: non_neg_integer()
Determine the multiplicity of an element in a multiset.
Input may be non-well-formed.
Create a well-formed multiset from any (finite) Enumerable of {t:term/0, t:non_neg_integer/0}
tuples.
Duplicate entries for the same element are accepted, and will be folded in additively.
Usage
iex> One9.Ms.from_counts([a: 2, b: 1, c: 10, c: 0, a: 1])
%{a: 3, b: 1, c: 10}
iex> One9.Ms.from_counts(%{a: 2, b: 1, c: 0})
%{a: 2, b: 1}
Create a well-formed multiset from any (finite) Enumerable of values.
Usage
iex> One9.Ms.from_elements([:a, :a, :b, :c])
%{a: 2, b: 1, c: 1}
Determine whether a value is present at all in a multiset.
Input must be well-formed.
See also count_element/2
.
@spec slice(t(e)) :: {size :: non_neg_integer(), :gb_trees.tree( start_index :: non_neg_integer(), {e, chunk_size :: non_neg_integer()} )} when e: term()
@spec slice(t(e)) :: :gb_trees.tree( start_index :: non_neg_integer(), {e, chunk_size :: non_neg_integer()} ) when e: term()
Determine whether the first multiset is a (non-strict) subset of the second.
First operand must be well-formed.
Convert a multiset into a List of unique elements.
Input must be well-formed.
@spec support_count(t()) :: non_neg_integer()
Return the cardinality of the support of a multiset.
Argument must be well-formed.
See also count/1
.
@spec take(t(e), e1, non_neg_integer()) :: {t(e), [e1]} when e: term(), e1: term()
@spec to_enumerable(t(e)) :: Enumerable.t(e) when e: term()
Convert a multiset into a complete List of elements (including repeats).
Input may be non-well-formed.
Return the union of two multisets.
Either/both operands may be non-well-formed. Result will be well-formed whenever both operands are well-formed.