NAME

Set::SortedArray - sets stored as sorted arrays

VERSION

Version 0.02

SYNOPSIS

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;

DESCRIPTION

Create a set that is stored as a sorted array. Modification is currently unsupported.

CONSTRUCTORS

new

$set = Set::SortedArray->new();
$set = Set::SortedArray->new(@members);

new_presorted

$set = Set::SortedArray->new_presorted(@members);

Quicker than new, but doesn't sort data.

MODIFYING

Currently unsupported. Inserting or deleting would take O(n) time.

DISPLAYING

as_string

print $S->as_string, "\n";
print $S, "\n";

as_string_callback

Set::SortedArray->as_string_callback(sub { ... });

QUERYING

members

size

DERIVING

union

$U = $S->union($T);
$U = $S->union($T, $V);
$U = $S + $T;
$U = $S + $T + $V; # inefficient

merge

$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.

intersection

$I = $S->intersection($T);
$I = $S->intersection($T, $U);
$I = $S * $T;
$I = $S * $T * $U; # inefficient

binary_intersection

$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.

difference

$D = $S->difference($T);
$D = $S - $T;

symmetric_difference

$E = $S->symmetric_difference($T);
$E = $S % $T;

asymmetric_difference

$A = $S->asymmetric_difference($T);

Returns [ $S - $T, $T - $S ], but more efficiently.

unique

$V = $S->unique($T);
$V = $S / $T;

COMPARING

is_equal

$eq = $S->is_equal($T);
$eq = $S == $T;

is_disjoint

$dj = $S->is_disjoint($T);
$dj = $S != $T;

is_proper_subset

$ps = $S->is_proper_subset($T);
$ps = $S < $T;

is_proper_superset

$pS = $S->is_proper_superset($T);
$pS = $S > $T;

is_subset

$is = $S->is_subset($T);
$is = $S <= $T;

is_superset

$iS = $S->is_superset($T);
$iS = $S >= $T;

compare

$cmp = $S->compare($T);
$cmp = $S <=> $T;

compare returns:

0  if $S == $T
1  if $S > $T
-1 if $S < $T
() otherwise

AUTHOR

"Kevin Galinsky", kgalinsky plus cpan at gmail dot com

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Set::SortedArray

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

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.