File: gb_sets.html

package info (click to toggle)
erlang-doc-html 1%3A8.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 18,028 kB
  • ctags: 7,419
  • sloc: perl: 1,841; ansic: 323; erlang: 155
file content (198 lines) | stat: -rw-r--r-- 7,582 bytes parent folder | download
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
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>gb_sets</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>


<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>gb_sets</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
gb_sets</UL>
<H3>MODULE SUMMARY</H3>
<UL>
General Balanced Trees</UL>
<H3>DESCRIPTION</H3>
<UL>
<P> An implementation of ordered sets using Prof. Arne Andersson's
General Balanced Trees. This can be much more efficient than
using ordered lists, for larger sets, but depends on the
application. See notes below for details.
</UL>
<H3>Complexity note</H3>
<UL>
<P> The complexity on set operations is bounded by either O(|S|) or
O(|T| * log(|S|)), where S is the largest given set, depending
on which is fastest for any particular function call. For
operating on sets of almost equal size, this implementation is
about 3 times slower than using ordered-list sets directly. For
sets of very different sizes, however, this solution can be
arbitrarily much faster; in practical cases, often between 10
and 100 times. This implementation is particularly suited for
accumulating elements a few at a time, building up a large set
(more than 100-200 elements), and repeatedly testing for
membership in the current set.
<P> As with normal tree structures, lookup (membership testing),
insertion and deletion have logarithmic complexity.
</UL>
<H3>EXPORTS</H3>
<P><A NAME="empty%0"><STRONG><CODE>empty()</CODE></STRONG></A><BR>
<UL>
<P>      Returns new, empty set.
        <P>      Alias: new(), for compatibility with `sets'.
</UL>
<P><A NAME="is_empty%1"><STRONG><CODE>is_empty(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns 'true' if S is an empty set, and 'false' otherwise.
</UL>
<P><A NAME="size%1"><STRONG><CODE>size(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns the number of nodes in the set as an
         integer. Returns 0 (zero) if the set is empty.
</UL>
<P><A NAME="singleton%1"><STRONG><CODE>singleton(X)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a set containing only the element X.
</UL>
<P><A NAME="is_member%2"><STRONG><CODE>is_member(X, S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns `true' if element X is a member of set S, and
         `false' otherwise.
        <P>      Alias: is_element(), for compatibility with `sets'.
</UL>
<P><A NAME="insert%2"><STRONG><CODE>insert(X, S)</CODE></STRONG></A><BR>
<UL>
<P>      Inserts element X into set S, returns the new set. Assumes
         that the element is not present in S.
</UL>
<P><A NAME="add%2"><STRONG><CODE>add(X, S)</CODE></STRONG></A><BR>
<UL>
<P>      Adds element X to set S, returns the new set. If X is
         already an element in S, nothing is changed.
        <P>      Alias: add_element(), for compatibility with `sets'.
</UL>
<P><A NAME="delete%2"><STRONG><CODE>delete(X, S)</CODE></STRONG></A><BR>
<UL>
<P>      Removes element X from set S, returns new set. Assumes that
         the element exists in the set.
        <P>      Alias: del_element(), for compatibility with `sets'.
</UL>
<P><A NAME="balance%1"><STRONG><CODE>balance(S)</CODE></STRONG></A><BR>
<UL>
<P>      Rebalances the tree representation of S. Note that this is
         rarely necessary, but may be motivated when a large number
         of elements have been deleted from the tree without further
         insertions. Rebalancing could then be forced in order to
         minimise lookup times, since deletion only does not
         rebalance the tree.
</UL>
<P><A NAME="union%2"><STRONG><CODE>union(S1, S2)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a new set that contains each element that is in
         either S1 or S2 or both, and no other elements.
</UL>
<P><A NAME="union%1"><STRONG><CODE>union(Ss)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a new set that contains each element that is in at
         least one of the sets in the list Ss, and no other elements.
</UL>
<P><A NAME="intersection%2"><STRONG><CODE>intersection(S1, S2)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a new set that contains each element that is in both
         S1 and S2, and no other elements.
</UL>
<P><A NAME="intersection%1"><STRONG><CODE>intersection(Ss)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a new set that contains each element that is in all
         of the sets in the list Ss, and no other elements.
</UL>
<P><A NAME="difference%2"><STRONG><CODE>difference(S1, S2)</CODE></STRONG></A><BR>
<UL>
<P>      Returns a new set that contains each element in S1 that is
         not also in S2, and no other elements.
        <P>      Alias: subtract(), for compatibility with `sets'.
</UL>
<P><A NAME="is_subset%2"><STRONG><CODE>is_subset(S1, S2)</CODE></STRONG></A><BR>
<UL>
<P>      Returns `true' if each element in S1 is also a member of S2,
         and `false' otherwise.
</UL>
<P><A NAME="to_list%1"><STRONG><CODE>to_list(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns an ordered list of all elements in set S. The list
         never contains duplicates (of course).
</UL>
<P><A NAME="from_list%1"><STRONG><CODE>from_list(List)</CODE></STRONG></A><BR>
<UL>
<P>      Creates a set containing all elements in List, where List
         may be unordered and contain duplicates.
</UL>
<P><A NAME="from_ordset%1"><STRONG><CODE>from_ordset(L)</CODE></STRONG></A><BR>
<UL>
<P>      Turns an ordered-set list L into a set. The list must not
         contain duplicates.
</UL>
<P><A NAME="take_smallest%1"><STRONG><CODE>take_smallest(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns {X, S1}, where X is the smallest element in set S,
         and S1 is the set S with element X deleted. Assumes that the
         set S is nonempty.
</UL>
<P><A NAME="iterator%1"><STRONG><CODE>iterator(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns an iterator that can be used for traversing the
         entries of set S; see `next'. The implementation of this is
         very efficient; traversing the whole set using `next' is
         only slightly slower than getting the list of all elements
         using `to_list' and traversing that. The main advantage of
         the iterator approach is that it does not require the
         complete list of all elements to be built in memory at one
         time.
</UL>
<P><A NAME="next%1"><STRONG><CODE>next(T)</CODE></STRONG></A><BR>
<UL>
<P>      Returns {X, T1} where X is the smallest element referred to
         by the iterator T, and T1 is the new iterator to be used for
         traversing the remaining elements, or the atom `none' if no
         elements remain.
</UL>
<P><A NAME="filter%2"><STRONG><CODE>filter(P, S)</CODE></STRONG></A><BR>
<UL>
<P>      Filters set S using predicate function P. Included for
         compatibility with `sets'.
</UL>
<P><A NAME="fold%3"><STRONG><CODE>fold(F, A, S)</CODE></STRONG></A><BR>
<UL>
<P>      Folds function F over set S with A as the initial
         accumulator. Included for compatibility with `sets'.
</UL>
<P><A NAME="is_set%1"><STRONG><CODE>is_set(S)</CODE></STRONG></A><BR>
<UL>
<P>      Returns 'true' if S appears to be a set, and 'false'
         otherwise. Not recommended; included for compatibility with
         `sets'.
</UL>
<H3>SEE ALSO</H3>
<UL>
<P> <A HREF="gb_trees.html">gb_trees(3)</A>, 
<A HREF="ordsets.html">ordsets(3)</A>, 
<A HREF="sets.html">sets(3)</A>
</UL>
<H3>AUTHORS</H3>
<UL>
Richard Carlsson - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright &copy; 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>