1sets(3) Erlang Module Definition sets(3)
2
3
4
6 sets - Functions for set manipulation.
7
9 Sets are collections of elements with no duplicate elements. The repre‐
10 sentation of a set is undefined.
11
12 This module provides the same interface as the ordsets(3) module but
13 with an undefined representation. One difference is that while this
14 module considers two elements as different if they do not match (=:=),
15 ordsets considers two elements as different if and only if they do not
16 compare equal (==).
17
18 Erlang/OTP 24.0 introduced a new internal representation for sets which
19 is more performant. Developers can use this new representation by pass‐
20 ing the {version, 2} flag to new/1 and from_list/2, such as
21 sets:new([{version, 2}]). This new representation will become the de‐
22 fault in future Erlang/OTP versions. Functions that work on two sets,
23 such as union/2 and similar, will work with sets of different versions.
24 In such cases, there is no guarantee about the version of the returned
25 set. Explicit conversion from the old version to the new one can be
26 done with sets:from_list(sets:to_list(Old), [{version,2}]).
27
29 set(Element)
30
31 As returned by new/0.
32
33 set() = set(term())
34
36 add_element(Element, Set1) -> Set2
37
38 Types:
39
40 Set1 = Set2 = set(Element)
41
42 Returns a new set formed from Set1 with Element inserted.
43
44 del_element(Element, Set1) -> Set2
45
46 Types:
47
48 Set1 = Set2 = set(Element)
49
50 Returns Set1, but with Element removed.
51
52 filter(Pred, Set1) -> Set2
53
54 Types:
55
56 Pred = fun((Element) -> boolean())
57 Set1 = Set2 = set(Element)
58
59 Filters elements in Set1 with boolean function Pred.
60
61 fold(Function, Acc0, Set) -> Acc1
62
63 Types:
64
65 Function = fun((Element, AccIn) -> AccOut)
66 Set = set(Element)
67 Acc0 = Acc1 = AccIn = AccOut = Acc
68
69 Folds Function over every element in Set and returns the final
70 value of the accumulator. The evaluation order is undefined.
71
72 from_list(List) -> Set
73
74 Types:
75
76 List = [Element]
77 Set = set(Element)
78
79 Returns a set of the elements in List.
80
81 from_list(List, Opts :: [{version, 1..2}]) -> Set
82
83 Types:
84
85 List = [Element]
86 Set = set(Element)
87
88 Returns a set of the elements in List at the given version.
89
90 intersection(SetList) -> Set
91
92 Types:
93
94 SetList = [set(Element), ...]
95 Set = set(Element)
96
97 Returns the intersection of the non-empty list of sets.
98
99 intersection(Set1, Set2) -> Set3
100
101 Types:
102
103 Set1 = Set2 = Set3 = set(Element)
104
105 Returns the intersection of Set1 and Set2.
106
107 is_disjoint(Set1, Set2) -> boolean()
108
109 Types:
110
111 Set1 = Set2 = set(Element)
112
113 Returns true if Set1 and Set2 are disjoint (have no elements in
114 common), otherwise false.
115
116 is_element(Element, Set) -> boolean()
117
118 Types:
119
120 Set = set(Element)
121
122 Returns true if Element is an element of Set, otherwise false.
123
124 is_empty(Set) -> boolean()
125
126 Types:
127
128 Set = set()
129
130 Returns true if Set is an empty set, otherwise false.
131
132 is_set(Set) -> boolean()
133
134 Types:
135
136 Set = term()
137
138 Returns true if Set is a set of elements, otherwise false.
139
140 is_subset(Set1, Set2) -> boolean()
141
142 Types:
143
144 Set1 = Set2 = set(Element)
145
146 Returns true when every element of Set1 is also a member of
147 Set2, otherwise false.
148
149 new() -> set()
150
151 Returns a new empty set.
152
153 new(Opts :: [{version, 1..2}]) -> set()
154
155 Returns a new empty set at the given version.
156
157 size(Set) -> integer() >= 0
158
159 Types:
160
161 Set = set()
162
163 Returns the number of elements in Set.
164
165 subtract(Set1, Set2) -> Set3
166
167 Types:
168
169 Set1 = Set2 = Set3 = set(Element)
170
171 Returns only the elements of Set1 that are not also elements of
172 Set2.
173
174 to_list(Set) -> List
175
176 Types:
177
178 Set = set(Element)
179 List = [Element]
180
181 Returns the elements of Set as a list. The order of the returned
182 elements is undefined.
183
184 union(SetList) -> Set
185
186 Types:
187
188 SetList = [set(Element)]
189 Set = set(Element)
190
191 Returns the merged (union) set of the list of sets.
192
193 union(Set1, Set2) -> Set3
194
195 Types:
196
197 Set1 = Set2 = Set3 = set(Element)
198
199 Returns the merged (union) set of Set1 and Set2.
200
202 gb_sets(3), ordsets(3)
203
204
205
206Ericsson AB stdlib 3.16.1 sets(3)