Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Object 3" | |
132 | .TH Object 3 "2003-09-02" "perl v5.8.0" "User Contributed Perl Documentation" | |
133 | .SH "NAME" | |
134 | Set::Object \- set of objects | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 2 | |
138 | \& use Set::Object; | |
139 | \& $set = Set::Object->new(); | |
140 | .Ve | |
141 | .SH "DESCRIPTION" | |
142 | .IX Header "DESCRIPTION" | |
143 | This modules implements a set of objects, that is, an unordered | |
144 | collection of objects without duplication. | |
145 | .SH "CLASS METHODS" | |
146 | .IX Header "CLASS METHODS" | |
147 | .Sh "new( [\fIlist\fP] )" | |
148 | .IX Subsection "new( [list] )" | |
149 | Return a new \f(CW\*(C`Set::Object\*(C'\fR containing the elements passed in \fIlist\fR. | |
150 | The elements must be objects. | |
151 | .SH "INSTANCE METHODS" | |
152 | .IX Header "INSTANCE METHODS" | |
153 | .Sh "insert( [\fIlist\fP] )" | |
154 | .IX Subsection "insert( [list] )" | |
155 | Add objects to the \f(CW\*(C`Set::Object\*(C'\fR. | |
156 | Adding the same object several times is not an error, | |
157 | but any \f(CW\*(C`Set::Object\*(C'\fR will contain at most one occurence of the | |
158 | same object. | |
159 | Returns the number of elements that were actually added. | |
160 | .Sh "includes( [\fIlist\fP] )" | |
161 | .IX Subsection "includes( [list] )" | |
162 | Return \f(CW\*(C`true\*(C'\fR if all the objects in \fIlist\fR are members of the \f(CW\*(C`Set::Object\*(C'\fR. | |
163 | \&\fIlist\fR may be empty, in which case \f(CW\*(C`true\*(C'\fR is returned. | |
164 | .Sh "members" | |
165 | .IX Subsection "members" | |
166 | Return the objects contained in the \f(CW\*(C`Set::Object\*(C'\fR. | |
167 | .Sh "size" | |
168 | .IX Subsection "size" | |
169 | Return the number of elements in the \f(CW\*(C`Set::Object\*(C'\fR. | |
170 | .Sh "remove( [\fIlist\fP] )" | |
171 | .IX Subsection "remove( [list] )" | |
172 | Remove objects from a \f(CW\*(C`Set::Object\*(C'\fR. | |
173 | Removing the same object more than once, or removing an object | |
174 | absent from the \f(CW\*(C`Set::Object\*(C'\fR is not an error. | |
175 | Returns the number of elements that were actually removed. | |
176 | .Sh "clear" | |
177 | .IX Subsection "clear" | |
178 | Empty this \f(CW\*(C`Set::Object\*(C'\fR. | |
179 | .Sh "as_string" | |
180 | .IX Subsection "as_string" | |
181 | Return a textual Smalltalk-ish representation of the \f(CW\*(C`Set::Object\*(C'\fR. | |
182 | Also available as overloaded operator "". | |
183 | .Sh "intersection( [\fIlist\fP] )" | |
184 | .IX Subsection "intersection( [list] )" | |
185 | Return a new \f(CW\*(C`Set::Object\*(C'\fR containing the intersection of the | |
186 | \&\f(CW\*(C`Set::Object\*(C'\fRs passed as arguments. | |
187 | Also available as overloaded operator *. | |
188 | .Sh "union( [\fIlist\fP] )" | |
189 | .IX Subsection "union( [list] )" | |
190 | Return a new \f(CW\*(C`Set::Object\*(C'\fR containing the union of the | |
191 | \&\f(CW\*(C`Set::Object\*(C'\fRs passed as arguments. | |
192 | Also available as overloaded operator +. | |
193 | .Sh "subset( \fIset\fP )" | |
194 | .IX Subsection "subset( set )" | |
195 | Return \f(CW\*(C`true\*(C'\fR if this \f(CW\*(C`Set::Object\*(C'\fR is a subset of \fIset\fR. | |
196 | Also available as operator <=. | |
197 | .Sh "proper_subset( \fIset\fP )" | |
198 | .IX Subsection "proper_subset( set )" | |
199 | Return \f(CW\*(C`true\*(C'\fR if this \f(CW\*(C`Set::Object\*(C'\fR is a proper subset of \fIset\fR | |
200 | Also available as operator <. | |
201 | .Sh "superset( \fIset\fP )" | |
202 | .IX Subsection "superset( set )" | |
203 | Return \f(CW\*(C`true\*(C'\fR if this \f(CW\*(C`Set::Object\*(C'\fR is a superset of \fIset\fR. | |
204 | Also available as operator >=. | |
205 | .Sh "proper_superset( \fIset\fP )" | |
206 | .IX Subsection "proper_superset( set )" | |
207 | Return \f(CW\*(C`true\*(C'\fR if this \f(CW\*(C`Set::Object\*(C'\fR is a proper superset of \fIset\fR | |
208 | Also available as operator >. | |
209 | .SH "FUNCTIONS" | |
210 | .IX Header "FUNCTIONS" | |
211 | The following functions are defined by the Set::Object \s-1XS\s0 code for | |
212 | convenience; they are largely identical to the versions in the | |
213 | Scalar::Util module, but there are a couple that provide functions not | |
214 | catered to by that module. | |
215 | .IP "\fBblessed\fR" 4 | |
216 | .IX Item "blessed" | |
217 | Returns a true value if the passed reference (\s-1RV\s0) is blessed. See | |
218 | also Acme::Holy. | |
219 | .IP "\fBreftype\fR" 4 | |
220 | .IX Item "reftype" | |
221 | A bit like the perl built-in \f(CW\*(C`ref\*(C'\fR function, but returns the \fItype\fR | |
222 | of reference; ie, if the reference is blessed then it returns what | |
223 | \&\f(CW\*(C`ref\*(C'\fR would have if it were not blessed. Useful for \*(L"seeing through\*(R" | |
224 | blessed references. | |
225 | .IP "\fBrefaddr\fR" 4 | |
226 | .IX Item "refaddr" | |
227 | Returns the memory address of a scalar. \fBWarning\fR: this is \fInot\fR | |
228 | guaranteed to be unique for scalars created in a program; memory might | |
229 | get re\-used! | |
230 | .IP "\fBis_int\fR, \fBis_string\fR, \fBis_double\fR" 4 | |
231 | .IX Item "is_int, is_string, is_double" | |
232 | A quick way of checking the three bits on scalars \- \s-1IOK\s0 (is_int), \s-1NOK\s0 | |
233 | (is_double) and \s-1POK\s0 (is_string). Note that the exact behaviour of | |
234 | when these bits get set is not defined by the perl \s-1API\s0. | |
235 | .Sp | |
236 | This function returns the \*(L"p\*(R" versions of the macro (SvIOKp, etc); use | |
237 | with caution. | |
238 | .IP "\fBis_overloaded\fR" 4 | |
239 | .IX Item "is_overloaded" | |
240 | A quick way to check if an object has overload magic on it. | |
241 | .IP "\fBish_int\fR" 4 | |
242 | .IX Item "ish_int" | |
243 | This function returns true, if the value it is passed looks like it | |
244 | \&\fIalready is\fR a representation of an \fIinteger\fR. This is so that you | |
245 | can decide whether the value passed is a hash key or an array | |
246 | index... <devious grin>. | |
247 | .IP "\fBis_key\fR" 4 | |
248 | .IX Item "is_key" | |
249 | This function returns true, if the value it is passed looks more like | |
250 | an \fIindex\fR to a collection than a \fIvalue\fR of a collection. | |
251 | .Sp | |
252 | But wait, you say \- Set::Object has no indices, one of the fundamental | |
253 | properties of a Set is that it is an \fIunordered collection\fR. Which | |
254 | means \fIno indices\fR. Stay tuned for the answer. | |
255 | .SH "INSTALLATION" | |
256 | .IX Header "INSTALLATION" | |
257 | This module is partly written in C, so you'll need a C compiler to | |
258 | install it. Use the familiar sequence: | |
259 | .PP | |
260 | .Vb 4 | |
261 | \& perl Makefile.PL | |
262 | \& make | |
263 | \& make test | |
264 | \& make install | |
265 | .Ve | |
266 | .PP | |
267 | This module was developed on Windows \s-1NT\s0 4.0, using the Visual \*(C+ | |
268 | compiler with Service Pack 2. It was also tested on \s-1AIX\s0 using \s-1IBM\s0's | |
269 | xlc compiler. | |
270 | .SH "PERFORMANCE" | |
271 | .IX Header "PERFORMANCE" | |
272 | The following benchmark compares \f(CW\*(C`Set::Object\*(C'\fR with using a hash to | |
273 | emulate a set-like collection: | |
274 | .PP | |
275 | .Vb 1 | |
276 | \& use Set::Object; | |
277 | .Ve | |
278 | .PP | |
279 | .Vb 2 | |
280 | \& package Obj; | |
281 | \& sub new { bless { } } | |
282 | .Ve | |
283 | .PP | |
284 | .Vb 1 | |
285 | \& @els = map { Obj->new() } 1..1000; | |
286 | .Ve | |
287 | .PP | |
288 | .Vb 1 | |
289 | \& require Benchmark; | |
290 | .Ve | |
291 | .PP | |
292 | .Vb 5 | |
293 | \& Benchmark::timethese(100, { | |
294 | \& 'Control' => sub { }, | |
295 | \& 'H insert' => sub { my %h = (); @h{@els} = @els; }, | |
296 | \& 'S insert' => sub { my $s = Set::Object->new(); $s->insert(@els) }, | |
297 | \& } ); | |
298 | .Ve | |
299 | .PP | |
300 | .Vb 2 | |
301 | \& %gh = (); | |
302 | \& @gh{@els} = @els; | |
303 | .Ve | |
304 | .PP | |
305 | .Vb 2 | |
306 | \& $gs = Set::Object->new(@els); | |
307 | \& $el = $els[33]; | |
308 | .Ve | |
309 | .PP | |
310 | .Vb 4 | |
311 | \& Benchmark::timethese(100_000, { | |
312 | \& 'H lookup' => sub { exists $gh{33} }, | |
313 | \& 'S lookup' => sub { $gs->includes($el) } | |
314 | \& } ); | |
315 | .Ve | |
316 | .PP | |
317 | On my computer the results are: | |
318 | .PP | |
319 | .Vb 8 | |
320 | \& Benchmark: timing 100 iterations of Control, H insert, S insert... | |
321 | \& Control: 0 secs ( 0.01 usr 0.00 sys = 0.01 cpu) | |
322 | \& (warning: too few iterations for a reliable count) | |
323 | \& H insert: 68 secs (67.81 usr 0.00 sys = 67.81 cpu) | |
324 | \& S insert: 9 secs ( 8.81 usr 0.00 sys = 8.81 cpu) | |
325 | \& Benchmark: timing 100000 iterations of H lookup, S lookup... | |
326 | \& H lookup: 7 secs ( 7.14 usr 0.00 sys = 7.14 cpu) | |
327 | \& S lookup: 6 secs ( 5.94 usr 0.00 sys = 5.94 cpu) | |
328 | .Ve | |
329 | .SH "AUTHOR" | |
330 | .IX Header "AUTHOR" | |
331 | Original Set::Object module by Jean-Louis Leroy, <jll@skynet.be> | |
332 | .SH "LICENCE" | |
333 | .IX Header "LICENCE" | |
334 | Copyright (c) 1998\-1999, Jean-Louis Leroy. All Rights Reserved. | |
335 | This module is free software. It may be used, redistributed | |
336 | and/or modified under the terms of the Perl Artistic License | |
337 | .PP | |
338 | Portions Copyright (c) 2003, Sam Vilain. All Rights Reserved. | |
339 | This module is free software. It may be used, redistributed | |
340 | and/or modified under the terms of the Perl Artistic License | |
341 | .SH "SEE ALSO" | |
342 | .IX Header "SEE ALSO" | |
343 | \&\fIperl\fR\|(1), \fIperltie\fR\|(1), overload.pm |