1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
27
<prepared>Robert Virding</prepared>
28
<responsible>Bjarne Dacker</responsible>
30
<approved>Bjarne Däcker</approved>
34
<file>sets.sgml</file>
37
<modulesummary>Functions for Set Manipulation</modulesummary>
39
<p>Sets are collections of elements with no duplicate elements.
40
The representation of a set is not defined.</p>
41
<p>This module provides exactly the same interface as the module
42
<c>ordsets</c> but with a defined representation. One difference is
43
that while this module considers two elements as different if they
44
do not match (<c>=:=</c>), <c>ordsets</c> considers two elements as
45
different if and only if they do not compare equal (<c>==</c>).</p>
49
<title>DATA TYPES</title>
52
as returned by new/0</code>
56
<name>new() -> Set</name>
57
<fsummary>Return an empty set</fsummary>
62
<p>Returns a new empty set.</p>
66
<name>is_set(Set) -> bool()</name>
67
<fsummary>Test for an <c>Set</c></fsummary>
72
<p>Returns <c>true</c> if <c>Set</c> is a set of
73
elements, otherwise <c>false</c>.</p>
77
<name>size(Set) -> int()</name>
78
<fsummary>Return the number of elements in a set</fsummary>
83
<p>Returns the number of elements in <c>Set</c>.</p>
87
<name>to_list(Set) -> List</name>
88
<fsummary>Convert an <c>Set</c>into a list</fsummary>
91
<v>List = [term()]</v>
94
<p>Returns the elements of <c>Set</c> as a list.</p>
98
<name>from_list(List) -> Set</name>
99
<fsummary>Convert a list into an <c>Set</c></fsummary>
101
<v>List = [term()]</v>
105
<p>Returns an set of the elements in <c>List</c>.</p>
109
<name>is_element(Element, Set) -> bool()</name>
110
<fsummary>Test for membership of an <c>Set</c></fsummary>
112
<v>Element = term()</v>
116
<p>Returns <c>true</c> if <c>Element</c> is an element of
117
<c>Set</c>, otherwise <c>false</c>.</p>
121
<name>add_element(Element, Set1) -> Set2</name>
122
<fsummary>Add an element to an <c>Set</c></fsummary>
124
<v>Element = term()</v>
125
<v>Set1 = Set2 = set()</v>
128
<p>Returns a new set formed from <c>Set1</c> with
129
<c>Element</c> inserted.</p>
133
<name>del_element(Element, Set1) -> Set2</name>
134
<fsummary>Remove an element from an <c>Set</c></fsummary>
136
<v>Element = term()</v>
137
<v>Set1 = Set2 = set()</v>
140
<p>Returns <c>Set1</c>, but with <c>Element</c> removed.</p>
144
<name>union(Set1, Set2) -> Set3</name>
145
<fsummary>Return the union of two <c>Sets</c></fsummary>
147
<v>Set1 = Set2 = Set3 = set()</v>
150
<p>Returns the merged (union) set of <c>Set1</c> and
155
<name>union(SetList) -> Set</name>
156
<fsummary>Return the union of a list of <c>Sets</c></fsummary>
158
<v>SetList = [set()]</v>
162
<p>Returns the merged (union) set of the list of sets.</p>
166
<name>intersection(Set1, Set2) -> Set3</name>
167
<fsummary>Return the intersection of two <c>Sets</c></fsummary>
169
<v>Set1 = Set2 = Set3 = set()</v>
172
<p>Returns the intersection of <c>Set1</c> and
177
<name>intersection(SetList) -> Set</name>
178
<fsummary>Return the intersection of a list of <c>Sets</c></fsummary>
180
<v>SetList = [set()]</v>
184
<p>Returns the intersection of the non-empty list of sets.</p>
188
<name>subtract(Set1, Set2) -> Set3</name>
189
<fsummary>Return the difference of two <c>Sets</c></fsummary>
191
<v>Set1 = Set2 = Set3 = set()</v>
194
<p>Returns only the elements of <c>Set1</c> which are not
195
also elements of <c>Set2</c>.</p>
199
<name>is_subset(Set1, Set2) -> bool()</name>
200
<fsummary>Test for subset</fsummary>
202
<v>Set1 = Set2 = set()</v>
205
<p>Returns <c>true</c> when every element of <c>Set</c>1 is
206
also a member of <c>Set2</c>, otherwise <c>false</c>.</p>
210
<name>fold(Function, Acc0, Set) -> Acc1</name>
211
<fsummary>Fold over set elements</fsummary>
213
<v>Function = fun (E, AccIn) -> AccOut</v>
214
<v>Acc0 = Acc1 = AccIn = AccOut = term()</v>
218
<p>Fold <c>Function</c> over every element in <c>Set</c>
219
returning the final value of the accumulator.</p>
223
<name>filter(Pred, Set1) -> Set2</name>
224
<fsummary>Filter set elements</fsummary>
226
<v>Pred = fun (E) -> bool()</v>
227
<v>Set1 = Set2 = set()</v>
230
<p>Filter elements in <c>Set1</c> with boolean function
237
<title>See Also</title>
238
<p><seealso marker="ordsets">ordsets(3)</seealso>,
239
<seealso marker="gb_sets">gb_sets(3)</seealso></p>