-
Notifications
You must be signed in to change notification settings - Fork 7
/
Utils--Set.html
317 lines (262 loc) · 11.8 KB
/
Utils--Set.html
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Utils::Set - Indexed set : OpenKore source code documentation</title>
<link rel="stylesheet" type="text/css" href="openkore.css">
<link rel="stylesheet" type="text/css" href="highlight.css">
<!-- Fix broken PNG transparency for IE/Win5-6+ -->
<!--[if gte IE 5.5000]>
<script type="text/javascript" src="pngfix.js"></script>
<![endif]-->
</head>
<body>
<div id="title">OpenKore source code documentation</div>
<div id="navigation">
<ul>
<li><a href="http://www.openkore.com/">Main website</a></li>
<li><a href="index.html">Table of contents</a></li>
<li><b>Utils::Set</b></li>
</ul>
</div>
<div id="main">
<h1>Utils::Set - Indexed set</h1>
A set (as in mathematics) is a collection with no duplicate items.
The Set class implements an indexed set. Not only do items only occur
once, each item can be accessed by index. So a Set is essentially
an array with no duplicate items.
<p>
<h3>Usage</h3>
To manipulate a Set, use its methods. You can access items in a Set
just like you access items in an array reference:
<pre class="example">
<span class="hl kwc">my</span> <span class="hl kwb">$set</span> <span class="hl sym">=</span> new <span class="hl kwd">Set</span><span class="hl sym">();</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">add</span><span class="hl sym">(</span><span class="hl str">"hello"</span><span class="hl sym">);</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">add</span><span class="hl sym">(</span><span class="hl str">"world"</span><span class="hl sym">);</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">add</span><span class="hl sym">(</span><span class="hl str">"hello"</span><span class="hl sym">);</span> <span class="hl slc"># Has no effect. "hello" is already in the set.</span>
<span class="hl kwa">foreach</span> <span class="hl kwc">my</span> <span class="hl kwb">$item</span> <span class="hl sym">(</span>@<span class="hl sym">{</span><span class="hl kwb">$set</span><span class="hl sym">}) {</span>
<span class="hl kwd">do_something</span><span class="hl sym">(</span><span class="hl kwb">$item</span><span class="hl sym">);</span>
<span class="hl sym">}</span>
<span class="hl kwb">$set</span><span class="hl sym">->[</span><span class="hl num">0</span><span class="hl sym">];</span> <span class="hl slc"># "hello"</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">get</span><span class="hl sym">(</span><span class="hl num">0</span><span class="hl sym">);</span> <span class="hl slc"># "hello"</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">has</span><span class="hl sym">(</span><span class="hl str">"hello"</span><span class="hl sym">);</span> <span class="hl slc"># 1 (true)</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">has</span><span class="hl sym">(</span><span class="hl str">"foo"</span><span class="hl sym">);</span> <span class="hl slc"># undef (false)</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">remove</span><span class="hl sym">(</span><span class="hl str">"hello"</span><span class="hl sym">);</span>
<span class="hl kwb">$set</span><span class="hl sym">-></span><span class="hl kwd">has</span><span class="hl sym">(</span><span class="hl str">"hello"</span><span class="hl sym">);</span> <span class="hl slc"># undef (false)</span>
</pre>
<p>
However, <b>do not</b> manipulate a Set like it's an array. The
following will result in corruption of the Set:
<pre class="example">
delete <span class="hl kwb">$set</span><span class="hl sym">->[</span><span class="hl num">0</span><span class="hl sym">];</span>
@<span class="hl sym">{</span><span class="hl kwb">$set</span><span class="hl sym">} = ();</span>
splice @<span class="hl sym">{</span><span class="hl kwb">$set</span><span class="hl sym">},</span> <span class="hl num">1</span><span class="hl sym">,</span> <span class="hl num">1</span><span class="hl sym">;</span>
</pre>
<p>
<h3>How items are considered equal</h3>
Two items are considered equal if their strings are the same.
That is, <code>$a</code> and <code>$b</code> are considered equal if:
<pre class="example">
<span class="hl str">"$a"</span> <span class="hl kwa">eq</span> <span class="hl str">"$b"</span>
</pre>
<p><table class="functionIndex">
<tr><th colspan="3">Functions in this module</th></tr><tr onclick="location.href='#Set->new';">
<td class="return-type"><a href="Utils--Set.html">Set</a></td>
<td class="func"><a href="#Set->new">Set->new</a></td>
<td class="decl">([elements...])</td>
</tr><tr onclick="location.href='#$set->add';">
<td class="return-type">void</td>
<td class="func"><a href="#$set->add">$set->add</a></td>
<td class="decl">(item)</td>
</tr><tr onclick="location.href='#$set->clear';">
<td class="return-type">void</td>
<td class="func"><a href="#$set->clear">$set->clear</a></td>
<td class="decl">()</td>
</tr><tr onclick="location.href='#$set->deepCopy';">
<td class="return-type"><a href="Utils--Set.html">Set</a></td>
<td class="func"><a href="#$set->deepCopy">$set->deepCopy</a></td>
<td class="decl">()</td>
</tr><tr onclick="location.href='#$set->get';">
<td class="return-type"></td>
<td class="func"><a href="#$set->get">$set->get</a></td>
<td class="decl">(<span class="type">int</span> index)</td>
</tr><tr onclick="location.href='#$set->getArray';">
<td class="return-type">Array</td>
<td class="func"><a href="#$set->getArray">$set->getArray</a></td>
<td class="decl">()</td>
</tr><tr onclick="location.href='#$set->has';">
<td class="return-type">boolean</td>
<td class="func"><a href="#$set->has">$set->has</a></td>
<td class="decl">(item)</td>
</tr><tr onclick="location.href='#$set->remove';">
<td class="return-type">void</td>
<td class="func"><a href="#$set->remove">$set->remove</a></td>
<td class="decl">(item)</td>
</tr><tr onclick="location.href='#$set->size';">
<td class="return-type">int</td>
<td class="func"><a href="#$set->size">$set->size</a></td>
<td class="decl">()</td>
</tr>
</table>
<p><hr class="details_sep">
<h2>Details</h2>
<div class="details">
<p>
<div class="function"><a name="$set->add"></a>
<h3>$set->add</h3>
<dl>
<dt class="decl">
<span class="return-type"> void</span> <strong>$set->add</strong>(item)
</dt>
<dd>
<dl class="params_and_returns">
<dt class="requires"><strong>Requires:</strong></dt>
<dd class="requires">defined($item)</dd>
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures"><code>$self</code>->has($item)</dd>
</dl><p>
<div class="desc">Add <code>$item</code> to the set if it isn't already in the set.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->clear"></a>
<h3>$set->clear</h3>
<dl>
<dt class="decl">
<span class="return-type"> void</span> <strong>$set->clear</strong>()
</dt>
<dd>
<dl class="params_and_returns">
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures"><code>@{</code>$self} == 0</dd>
</dl><p>
<div class="desc">Remove all items in the set.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->deepCopy"></a>
<h3>$set->deepCopy</h3>
<dl>
<dt class="decl">
<span class="return-type"> <a href="Utils--Set.html">Set</a></span> <strong>$set->deepCopy</strong>()
</dt>
<dd>
<dl class="params_and_returns">
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures">defined(result)</dd>
</dl><p>
<div class="desc">Create a deep copy of this set. The items themselves are not copied.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->get"></a>
<h3>$set->get</h3>
<dl>
<dt class="decl">
<span class="return-type"> </span><strong>$set->get</strong>(<span class="type">int</span> index)
</dt>
<dd>
<dl class="params_and_returns">
<dt class="requires"><strong>Requires:</strong></dt>
<dd class="requires">0 <= $index < @{$set}</dd>
</dl><p>
<div class="desc">Returns the item at the specified index.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->getArray"></a>
<h3>$set->getArray</h3>
<dl>
<dt class="decl">
<span class="return-type"> Array</span> <strong>$set->getArray</strong>()
</dt>
<dd>
<dl class="params_and_returns">
<dt class="params"><strong>Parameters:</strong></dt>
<dd class="param"><code> for all $element in result</code> : defined($element)</dd>
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures"> defined(result)</dd>
</dl><p>
<div class="desc">Return the set's internal array. You must not manipulate this array.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->has"></a>
<h3>$set->has</h3>
<dl>
<dt class="decl">
<span class="return-type"> boolean</span> <strong>$set->has</strong>(item)
</dt>
<dd>
<div class="desc">Check whether <code>$item</code> is in the set.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->remove"></a>
<h3>$set->remove</h3>
<dl>
<dt class="decl">
<span class="return-type"> void</span> <strong>$set->remove</strong>(item)
</dt>
<dd>
<dl class="params_and_returns">
<dt class="requires"><strong>Requires:</strong></dt>
<dd class="requires">defined($item)</dd>
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures">!$self->has($item)</dd>
</dl><p>
<div class="desc">Removes <code>$item</code> from the set if it's there.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$set->size"></a>
<h3>$set->size</h3>
<dl>
<dt class="decl">
<span class="return-type"> int</span> <strong>$set->size</strong>()
</dt>
<dd>
<dl class="params_and_returns">
<dt class="ensures"><strong>Ensures:</strong></dt>
<dd class="ensures">result >= 0</dd>
</dl><p>
<div class="desc">Returns the number of elements in this set.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="Set->new"></a>
<h3>Set->new</h3>
<dl>
<dt class="decl">
<span class="return-type"> <a href="Utils--Set.html">Set</a></span> <strong>Set->new</strong>([elements...])
</dt>
<dd>
<dl class="params_and_returns">
<dt class="params"><strong>Parameters:</strong></dt>
<dd class="param"><code>elements</code> : The elements to add to this set.</dd>
</dl><p>
<div class="desc">Create a new Set, possibly with predefined elements.</div>
</dd>
</dl>
</div>
</div>
<p><hr><p>
<div id="footer">
<ul>
<li><a href="http://validator.w3.org/check?uri=referer" title="Valid HTML 4.01!"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a></li>
<li><a href="http://www.mozilla.com/" title="Get Firefox - Take Back the Web"><img width="104" height="32" src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox - Take Back the Web"></a></li>
<li><a href="http://www.mozilla.com/" title="If you were looking at this page in any browser but Microsoft Internet Explorer, it would look and run better and faster"><img width="45" height="45" src="http://linuxart.com/img/noIE-small.png" alt="If you were looking at this page in any browser but Microsoft Internet Explorer, it would look and run better and faster"></a></li>
</ul>
Last modified: Fri Nov 16 10:05:11 2012
</div>
</div>
</body>
</html>