ordsets (stdlib v3.15.2)
Sets are collections of elements with no duplicate elements. An ordset
is a representation of a set, where an ordered list is used to store the elements of the set. An ordered list is more efficient than an unordered list. Elements are ordered according to the Erlang term order.
This module provides the same interface as the sets(3)
module but with a defined representation. One difference is that while sets
considers two elements as different if they do not match (=:=
), this module considers two elements as different if and only if they do not compare equal (==
).
See Also
Link to this section Summary
Functions
Returns a new ordered set formed from Ordset1
with Element
inserted.
Returns Ordset1
, but with Element
removed.
Filters elements in Ordset1
with boolean function Pred
.
Folds Function
over every element in Ordset
and returns the final value of the accumulator.
Returns an ordered set of the elements in List
.
Returns the intersection of the non-empty list of sets.
Returns the intersection of Ordset1
and Ordset2
.
Returns true
if Ordset1
and Ordset2
are disjoint (have no elements in common), otherwise false
.
Returns true
if Element
is an element of Ordset
, otherwise false
.
Returns true
if Ordset
is an empty set, otherwise false
.
Returns true
if Ordset
is an ordered set of elements, otherwise false
.
Returns true
when every element of Ordset1
is also a member of Ordset2
, otherwise false
.
Returns a new empty ordered set.
Returns the number of elements in Ordset
.
Returns only the elements of Ordset1
that are not also elements of Ordset2
.
Returns the elements of Ordset
as a list.
Returns the merged (union) set of the list of sets.
Returns the merged (union) set of Ordset1
and Ordset2
.
Link to this section Types
-type ordset(Arg1) :: term().
Specs
ordset(T) :: [T].
As returned by new/0
.
Link to this section Functions
add_element/2
Specs
add_element(Element, Ordset1) -> Ordset2 when Element :: E, Ordset1 :: ordset(T), Ordset2 :: ordset(T | E).
Returns a new ordered set formed from Ordset1
with Element
inserted.
del_element/2
Specs
del_element(Element, Ordset1) -> Ordset2 when Element :: term(), Ordset1 :: ordset(T), Ordset2 :: ordset(T).
Returns Ordset1
, but with Element
removed.
filter/2
Specs
filter(Pred, Ordset1) -> Ordset2 when Pred :: fun((Element :: T) -> boolean()), Ordset1 :: ordset(T), Ordset2 :: ordset(T).
Filters elements in Ordset1
with boolean function Pred
.
fold/3
Specs
fold(Function, Acc0, Ordset) -> Acc1 when Function :: fun((Element :: T, AccIn :: term()) -> AccOut :: term()), Ordset :: ordset(T), Acc0 :: term(), Acc1 :: term().
Folds Function
over every element in Ordset
and returns the final value of the accumulator.
from_list/1
Specs
from_list(List) -> Ordset when List :: [T], Ordset :: ordset(T).
Returns an ordered set of the elements in List
.
intersection/1
Specs
Returns the intersection of the non-empty list of sets.
intersection/2
Specs
intersection(Ordset1, Ordset2) -> Ordset3 when Ordset1 :: ordset(_), Ordset2 :: ordset(_), Ordset3 :: ordset(_).
Returns the intersection of Ordset1
and Ordset2
.
is_disjoint/2
Specs
Returns true
if Ordset1
and Ordset2
are disjoint (have no elements in common), otherwise false
.
is_element/2
Specs
is_element(Element, Ordset) -> boolean() when Element :: term(), Ordset :: ordset(_).
Returns true
if Element
is an element of Ordset
, otherwise false
.
Specs
is_empty(Ordset) -> boolean() when Ordset :: ordset(_).
Returns true
if Ordset
is an empty set, otherwise false
.
is_set/1
Specs
is_set(Ordset) -> boolean() when Ordset :: term().
Returns true
if Ordset
is an ordered set of elements, otherwise false
.
is_subset/2
Specs
Returns true
when every element of Ordset1
is also a member of Ordset2
, otherwise false
.
new/0
Specs
new() -> [].
Returns a new empty ordered set.
size/1
Specs
size(Ordset) -> non_neg_integer() when Ordset :: ordset(_).
Returns the number of elements in Ordset
.
subtract/2
Specs
subtract(Ordset1, Ordset2) -> Ordset3 when Ordset1 :: ordset(_), Ordset2 :: ordset(_), Ordset3 :: ordset(_).
Returns only the elements of Ordset1
that are not also elements of Ordset2
.
to_list/1
Specs
to_list(Ordset) -> List when Ordset :: ordset(T), List :: [T].
Returns the elements of Ordset
as a list.
union/1
Specs
Returns the merged (union) set of the list of sets.
union/2
Specs
union(Ordset1, Ordset2) -> Ordset3 when Ordset1 :: ordset(T1), Ordset2 :: ordset(T2), Ordset3 :: ordset(T1 | T2).
Returns the merged (union) set of Ordset1
and Ordset2
.