ActivePerl Documentation
|
NAMESet::Object - set of objects
SUPPORTED PLATFORMS
SYNOPSISuse Set::Object; $set = Set::Object->new();
DESCRIPTIONThis modules implements a set of objects, that is, an unordered collection of objects without duplication.
CLASS METHODS
new( [list] )Return a new
INSTANCE METHODS
insert( [list] )Add objects to the
includes( [list] )Return
membersReturn the objects contained in the
sizeReturn the number of elements in the
remove( [list] )Remove objects from a
clearEmpty this
as_stringReturn a textual Smalltalk-ish representation of the
intersection( [list] )Return a new
union( [list] )Return a new
subset( set )Return
proper_subset( set )Return
superset( set )Return
proper_superset( set )Return
INSTALLATIONThis module is partly written in C, so you'll need a C compiler to install it. Use the familiar sequence: perl Makefile.PL make make test make install This module was developed on Windows NT 4.0, using the Visual C++ compiler with Service Pack 2. It was also tested on AIX using IBM's xlc compiler.
PERFORMANCEThe following benchmark compares use Set::Object;
package Obj;
sub new { bless { } }
@els = map { Obj->new() } 1..1000;
require Benchmark;
Benchmark::timethese(100, {
'Control' => sub { },
'H insert' => sub { my %h = (); @h{@els} = @els; },
'S insert' => sub { my $s = Set::Object->new(); $s->insert(@els) },
} );
%gh = ();
@gh{@els} = @els;
$gs = Set::Object->new(@els); $el = $els[33];
Benchmark::timethese(100_000, {
'H lookup' => sub { exists $gh{33} },
'S lookup' => sub { $gs->includes($el) }
} );
On my computer the results are:
Benchmark: timing 100 iterations of Control, H insert, S insert...
Control: 0 secs ( 0.01 usr 0.00 sys = 0.01 cpu)
(warning: too few iterations for a reliable count)
H insert: 68 secs (67.81 usr 0.00 sys = 67.81 cpu)
S insert: 9 secs ( 8.81 usr 0.00 sys = 8.81 cpu)
Benchmark: timing 100000 iterations of H lookup, S lookup...
H lookup: 7 secs ( 7.14 usr 0.00 sys = 7.14 cpu)
S lookup: 6 secs ( 5.94 usr 0.00 sys = 5.94 cpu)
AUTHORJean-Louis Leroy, jll@skynet.be
LICENCECopyright (c) 1998-1999, Jean-Louis Leroy. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License
SEE ALSOperl(1). overload.pm
|