Set::SortedArray - sets stored as sorted arrays
Version 0.02
use Set::SortedArray; my $S = Set::SortedArray->new( qw/ d b c a e /); my $T = Set::SortedArray->new_presorted( qw/ b c e f g / ); print $S->as_string, "\n"; print $S, "\n"; $U = $S->union($T); $I = $S->intersection($T); $D = $S->difference($T); $E = $S->symmetric_difference($T); $A = $S->asymmetric_difference($T); $V = $S->unique($T); $U = $S + $T; # union $I = $S * $T; # intersection $D = $S - $T; # difference $E = $S % $T; # symmetric_difference $V = $S / $T; # unique $eq = $S->is_equal($T); $dj = $S->is_disjoint($T); $ps = $S->is_proper_subset($T); $pS = $S->is_proper_superset($T); $is = $S->is_subset($T); $iS = $S->is_superset($T); $eq = $S == $T; # equal $dj = $S != $T; # disjoint $ps = $S < $T; # is_proper_subset $pS = $S > $T; # is_proper_superset $is = $S <= $T; # is_subset $iS = $S >= $T; # is_superset # amalgam of a few of the above $cmp = $S->compare($T); $cmp = $S <=> $T;
Create a set that is stored as a sorted array. Modification is currently unsupported.
$set = Set::SortedArray->new(); $set = Set::SortedArray->new(@members);
$set = Set::SortedArray->new_presorted(@members);
Quicker than new, but doesn't sort data.
Currently unsupported. Inserting or deleting would take O(n) time.
print $S->as_string, "\n"; print $S, "\n";
Set::SortedArray->as_string_callback(sub { ... });
$U = $S->union($T); $U = $S->union($T, $V); $U = $S + $T; $U = $S + $T + $V; # inefficient
$U = $S->merge($T); $U = $S + $T;
Special case of union where only two sets are considered. "+" is actually overloaded to merge, not union. Named merge since this is essentially the "merge" step of a mergesort.
$I = $S->intersection($T); $I = $S->intersection($T, $U); $I = $S * $T; $I = $S * $T * $U; # inefficient
$I = $S->binary_intersection($T); $I = $S * $T;
Special case of intersection where only two sets are considered. "*" is actually overloaded to binary_intersection, not intersection.
$D = $S->difference($T); $D = $S - $T;
$E = $S->symmetric_difference($T); $E = $S % $T;
$A = $S->asymmetric_difference($T);
Returns [ $S - $T, $T - $S ], but more efficiently.
$V = $S->unique($T); $V = $S / $T;
$eq = $S->is_equal($T); $eq = $S == $T;
$dj = $S->is_disjoint($T); $dj = $S != $T;
$ps = $S->is_proper_subset($T); $ps = $S < $T;
$pS = $S->is_proper_superset($T); $pS = $S > $T;
$is = $S->is_subset($T); $is = $S <= $T;
$iS = $S->is_superset($T); $iS = $S >= $T;
$cmp = $S->compare($T); $cmp = $S <=> $T;
compare returns:
compare
0 if $S == $T 1 if $S > $T -1 if $S < $T () otherwise
"Kevin Galinsky", kgalinsky plus cpan at gmail dot com
kgalinsky plus cpan at gmail dot com
Please report any bugs or feature requests to bug-set-sortedarray at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Set-SortedArray. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-set-sortedarray at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Set::SortedArray
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-SortedArray
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Set-SortedArray
CPAN Ratings
http://cpanratings.perl.org/d/Set-SortedArray
Search CPAN
http://search.cpan.org/dist/Set-SortedArray/
Copyright 2011-2012 "Kevin Galinsky".
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Set::SortedArray, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Set::SortedArray
CPAN shell
perl -MCPAN -e shell install Set::SortedArray
For more information on module installation, please visit the detailed CPAN module installation guide.