aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/doc/src/ordsets.xml
blob: a20ab2d87914d7b7601ef0b9d2b58d22bffd0bcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2009</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      The contents of this file are subject to the Erlang Public License,
      Version 1.1, (the "License"); you may not use this file except in
      compliance with the License. You should have received a copy of the
      Erlang Public License along with this software. If not, it can be
      retrieved online at http://www.erlang.org/.
    
      Software distributed under the License is distributed on an "AS IS"
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
      the License for the specific language governing rights and limitations
      under the License.
    
    </legalnotice>

    <title>ordsets</title>
    <prepared>Robert Virding</prepared>
    <responsible>Bjarne Dacker</responsible>
    <docno>1</docno>
    <approved>Bjarne D&auml;cker</approved>
    <checked></checked>
    <date>99-07-27</date>
    <rev>A</rev>
    <file>ordsets.sgml</file>
  </header>
  <module>ordsets</module>
  <modulesummary>Functions for Manipulating Sets as Ordered Lists</modulesummary>
  <description>
    <p>Sets are collections of elements with no duplicate elements.
      An <c>ordset</c> 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.</p>
    <p>This module provides exactly the same interface as the module
      <c>sets</c> but with a defined representation. One difference is
      that while <c>sets</c> considers two elements as different if they
      do not match (<c>=:=</c>), this module considers two elements as
      different if and only if they do not compare equal (<c>==</c>).</p>
  </description>

  <section>
    <title>DATA TYPES</title>
    <code type="none">
ordered_set()
  as returned by new/0</code>
  </section>
  <funcs>
    <func>
      <name>new() -> Ordset</name>
      <fsummary>Return an empty set</fsummary>
      <type>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Returns a new empty ordered set.</p>
      </desc>
    </func>
    <func>
      <name>is_set(Ordset) -> bool()</name>
      <fsummary>Test for an <c>Ordset</c></fsummary>
      <type>
        <v>Ordset = term()</v>
      </type>
      <desc>
        <p>Returns <c>true</c> if <c>Ordset</c> is an ordered set of
          elements, otherwise <c>false</c>.</p>
      </desc>
    </func>
    <func>
      <name>size(Ordset) -> int()</name>
      <fsummary>Return the number of elements in a set</fsummary>
      <type>
        <v>Ordset = term()</v>
      </type>
      <desc>
        <p>Returns the number of elements in <c>Ordset</c>.</p>
      </desc>
    </func>
    <func>
      <name>to_list(Ordset) -> List</name>
      <fsummary>Convert an <c>Ordset</c>into a list</fsummary>
      <type>
        <v>Ordset = ordered_set()</v>
        <v>List = [term()]</v>
      </type>
      <desc>
        <p>Returns the elements of <c>Ordset</c> as a list.</p>
      </desc>
    </func>
    <func>
      <name>from_list(List) -> Ordset</name>
      <fsummary>Convert a list into an <c>Ordset</c></fsummary>
      <type>
        <v>List = [term()]</v>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Returns an ordered set of the elements in <c>List</c>.</p>
      </desc>
    </func>
    <func>
      <name>is_element(Element, Ordset) -> bool()</name>
      <fsummary>Test for membership of an <c>Ordset</c></fsummary>
      <type>
        <v>Element = term()</v>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Returns <c>true</c> if <c>Element</c> is an element of
          <c>Ordset</c>, otherwise <c>false</c>.</p>
      </desc>
    </func>
    <func>
      <name>add_element(Element, Ordset1) -> Ordset2</name>
      <fsummary>Add an element to an <c>Ordset</c></fsummary>
      <type>
        <v>Element = term()</v>
        <v>Ordset1 = Ordset2 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns a new ordered set formed from <c>Ordset1</c> with
          <c>Element</c> inserted.</p>
      </desc>
    </func>
    <func>
      <name>del_element(Element, Ordset1) -> Ordset2</name>
      <fsummary>Remove an element from an <c>Ordset</c></fsummary>
      <type>
        <v>Element = term()</v>
        <v>Ordset1 = Ordset2 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns <c>Ordset1</c>, but with <c>Element</c> removed.</p>
      </desc>
    </func>
    <func>
      <name>union(Ordset1, Ordset2) -> Ordset3</name>
      <fsummary>Return the union of two <c>Ordsets</c></fsummary>
      <type>
        <v>Ordset1 = Ordset2 = Ordset3 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns the merged (union) set of <c>Ordset1</c> and
          <c>Ordset2</c>.</p>
      </desc>
    </func>
    <func>
      <name>union(OrdsetList) -> Ordset</name>
      <fsummary>Return the union of a list of <c>Ordsets</c></fsummary>
      <type>
        <v>OrdsetList = [ordered_set()]</v>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Returns the merged (union) set of the list of sets.</p>
      </desc>
    </func>
    <func>
      <name>intersection(Ordset1, Ordset2) -> Ordset3</name>
      <fsummary>Return the intersection of two <c>Ordsets</c></fsummary>
      <type>
        <v>Ordset1 = Ordset2 = Ordset3 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns the intersection of <c>Ordset1</c> and
          <c>Ordset2</c>.</p>
      </desc>
    </func>
    <func>
      <name>intersection(OrdsetList) -> Ordset</name>
      <fsummary>Return the intersection of a list of <c>Ordsets</c></fsummary>
      <type>
        <v>OrdsetList = [ordered_set()]</v>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Returns the intersection of the non-empty list of sets.</p>
      </desc>
    </func>
    <func>
      <name>is_disjoint(Ordset1, Ordset2) -> bool()</name>
      <fsummary>Check whether two <c>Ordsets</c> are disjoint</fsummary>
      <type>
        <v>Ordset1 = Ordset2 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns <c>true</c> if <c>Ordset1</c> and
          <c>Ordset2</c> are disjoint (have no elements in common),
	  and <c>false</c> otherwise.</p>
      </desc>
    </func>
    <func>
      <name>subtract(Ordset1, Ordset2) -> Ordset3</name>
      <fsummary>Return the difference of two <c>Ordsets</c></fsummary>
      <type>
        <v>Ordset1 = Ordset2 = Ordset3 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns only the elements of <c>Ordset1</c> which are not
          also elements of <c>Ordset2</c>.</p>
      </desc>
    </func>
    <func>
      <name>is_subset(Ordset1, Ordset2) -> bool()</name>
      <fsummary>Test for subset</fsummary>
      <type>
        <v>Ordset1 = Ordset2 = ordered_set()</v>
      </type>
      <desc>
        <p>Returns <c>true</c> when every element of <c>Ordset</c>1 is
          also a member of <c>Ordset2</c>, otherwise <c>false</c>.</p>
      </desc>
    </func>
    <func>
      <name>fold(Function, Acc0, Ordset) -> Acc1</name>
      <fsummary>Fold over set elements</fsummary>
      <type>
        <v>Function = fun (E, AccIn) -> AccOut</v>
        <v>Acc0 = Acc1 = AccIn = AccOut = term()</v>
        <v>Ordset = ordered_set()</v>
      </type>
      <desc>
        <p>Fold <c>Function</c> over every element in <c>Ordset</c>
          returning the final value of the accumulator.</p>
      </desc>
    </func>
    <func>
      <name>filter(Pred, Ordset1) -> Set2</name>
      <fsummary>Filter set elements</fsummary>
      <type>
        <v>Pred = fun (E) -> bool()</v>
        <v>Set1 = Set2 = ordered_set()</v>
      </type>
      <desc>
        <p>Filter elements in <c>Set1</c> with boolean function
          <c>Fun</c>.</p>
      </desc>
    </func>
  </funcs>

  <section>
    <title>See Also</title>
    <p><seealso marker="gb_sets">gb_sets(3)</seealso>,
      <seealso marker="sets">sets(3)</seealso></p>
  </section>
</erlref>