1sets(3)                    Erlang Module Definition                    sets(3)
2
3
4

NAME

6       sets - Functions for set manipulation.
7

DESCRIPTION

9       Sets are collections of elements with no duplicate elements.
10
11       The data representing a set as used by this module is to be regarded as
12       opaque by other modules. In abstract terms,  the  representation  is  a
13       composite  type  of  existing Erlang terms. See note on data types. Any
14       code assuming knowledge of the format is running on thin ice.
15
16       This module provides the same interface as the  ordsets(3)  module  but
17       with  an  undefined  representation.  One difference is that while this
18       module considers two elements as different if they do not match  (=:=),
19       ordsets  considers two elements as different if and only if they do not
20       compare equal (==).
21
22       Erlang/OTP 24.0 introduced a new internal representation for sets which
23       is more performant. Developers can use this new representation by pass‐
24       ing  the  {version,  2}  flag  to  new/1  and  from_list/2,   such   as
25       sets:new([{version,  2}]).  This new representation will become the de‐
26       fault in future Erlang/OTP versions. Functions that work on  two  sets,
27       such as union/2 and similar, will work with sets of different versions.
28       In such cases, there is no guarantee about the version of the  returned
29       set.  Explicit  conversion  from  the old version to the new one can be
30       done with sets:from_list(sets:to_list(Old), [{version,2}]).
31

DATA TYPES

33       set(Element)
34
35              As returned by new/0.
36
37       set() = set(term())
38

EXPORTS

40       add_element(Element, Set1) -> Set2
41
42              Types:
43
44                 Set1 = Set2 = set(Element)
45
46              Returns a new set formed from Set1 with Element inserted.
47
48       del_element(Element, Set1) -> Set2
49
50              Types:
51
52                 Set1 = Set2 = set(Element)
53
54              Returns Set1, but with Element removed.
55
56       filter(Pred, Set1) -> Set2
57
58              Types:
59
60                 Pred = fun((Element) -> boolean())
61                 Set1 = Set2 = set(Element)
62
63              Filters elements in Set1 with boolean function Pred.
64
65       fold(Function, Acc0, Set) -> Acc1
66
67              Types:
68
69                 Function = fun((Element, AccIn) -> AccOut)
70                 Set = set(Element)
71                 Acc0 = Acc1 = AccIn = AccOut = Acc
72
73              Folds Function over every element in Set and returns  the  final
74              value of the accumulator. The evaluation order is undefined.
75
76       from_list(List) -> Set
77
78              Types:
79
80                 List = [Element]
81                 Set = set(Element)
82
83              Returns a set of the elements in List.
84
85       from_list(List, Opts :: [{version, 1..2}]) -> Set
86
87              Types:
88
89                 List = [Element]
90                 Set = set(Element)
91
92              Returns a set of the elements in List at the given version.
93
94       intersection(SetList) -> Set
95
96              Types:
97
98                 SetList = [set(Element), ...]
99                 Set = set(Element)
100
101              Returns the intersection of the non-empty list of sets.
102
103       intersection(Set1, Set2) -> Set3
104
105              Types:
106
107                 Set1 = Set2 = Set3 = set(Element)
108
109              Returns the intersection of Set1 and Set2.
110
111       is_disjoint(Set1, Set2) -> boolean()
112
113              Types:
114
115                 Set1 = Set2 = set(Element)
116
117              Returns  true if Set1 and Set2 are disjoint (have no elements in
118              common), otherwise false.
119
120       is_element(Element, Set) -> boolean()
121
122              Types:
123
124                 Set = set(Element)
125
126              Returns true if Element is an element of Set, otherwise false.
127
128       is_empty(Set) -> boolean()
129
130              Types:
131
132                 Set = set()
133
134              Returns true if Set is an empty set, otherwise false.
135
136       is_set(Set) -> boolean()
137
138              Types:
139
140                 Set = term()
141
142              Returns true if Set appears to be a set of  elements,  otherwise
143              false.  Note  that  the test is shallow and will return true for
144              any term that coincides with the possible representations  of  a
145              set. See also note on data types.
146
147       is_subset(Set1, Set2) -> boolean()
148
149              Types:
150
151                 Set1 = Set2 = set(Element)
152
153              Returns  true  when  every  element  of Set1 is also a member of
154              Set2, otherwise false.
155
156       new() -> set()
157
158              Returns a new empty set.
159
160       new(Opts :: [{version, 1..2}]) -> set()
161
162              Returns a new empty set at the given version.
163
164       size(Set) -> integer() >= 0
165
166              Types:
167
168                 Set = set()
169
170              Returns the number of elements in Set.
171
172       subtract(Set1, Set2) -> Set3
173
174              Types:
175
176                 Set1 = Set2 = Set3 = set(Element)
177
178              Returns only the elements of Set1 that are not also elements  of
179              Set2.
180
181       to_list(Set) -> List
182
183              Types:
184
185                 Set = set(Element)
186                 List = [Element]
187
188              Returns the elements of Set as a list. The order of the returned
189              elements is undefined.
190
191       union(SetList) -> Set
192
193              Types:
194
195                 SetList = [set(Element)]
196                 Set = set(Element)
197
198              Returns the merged (union) set of the list of sets.
199
200       union(Set1, Set2) -> Set3
201
202              Types:
203
204                 Set1 = Set2 = Set3 = set(Element)
205
206              Returns the merged (union) set of Set1 and Set2.
207

SEE ALSO

209       gb_sets(3), ordsets(3)
210
211
212
213Ericsson AB                       stdlib 4.2                           sets(3)
Impressum