Flavio S. Glock wrote:
I'm not sure if it fills all requirements, but see also:
Set::Infinite
http://search.cpan.org/~fglock/Set-Infinite-0.61/lib/Set/Infinite.pm
- Flavio S. Glock
I've been giving further study to Set::Infinite. I concede that I may
not understand the documentation correctly, but it doesn't appear to DWIM.
My hunch is that the closest thing in Set::Infinite to what the proposed
Set::Gapfillers does would be the 'minus' method. Using some numbers
taken from that method's example in the docs, I would call
Set::Gapfillers as follows:
$gf = Set::Gapfillers->new(
lower => 7,
upper => 20,
sets => [
[ 1, 4 ],
[ 8, 12 ],
],
);
$neededref = $gf->segments_needed();
$gapfillref = $gf->gapfillers();
$allsegref = $gf->all_segments();
$Data::Dumper::Indent = 0;
print "\n\nSet::Gapfillers::segments_needed\n";
print Dumper ($neededref);
print "\n\nSet::Gapfillers::gapfillers\n";
print Dumper ($gapfillref);
print "\n\nSet::Gapfillers::all_segments\n";
print Dumper ($allsegref);
print "\n";
... and I would get these results:
Set::Gapfillers::segments_needed
$VAR1 = [[7,7],[8,12],[13,20]];
Set::Gapfillers::gapfillers
$VAR1 = [[7,7],[13,20]];
Set::Gapfillers::all_segments
$VAR1 = [[7,7],[8,12],[13,20]];
Now let's plug the same numbers into Set::Infinite::minus:
$set1 = new Set::Infinite( [ 1, 4 ], [ 8, 12 ] );
$set2 = new Set::Infinite( [ 7, 20 ] );
print "\nSet::Infinite::minus\n";
print $set1->minus( $set2 );
I get these results:
Set::Infinite::minus
[1..4]
... which may be what this method is intended to do, but it's not what I
was looking for when I wrote Set::Gapfillers.
On Perlmonks (http://perlmonks.org/?node_id=539355), davidrw suggested
an approach which, with the same numbers as above plugged in, would look
like this:
$lists = Set::Infinite->new([1,4], [8,12]);
print "\n\nSet::Infinite::minus a la Perlmonks\n";
print Set::Infinite->new([7,20])->minus($lists);
... which gives these results:
Set::Infinite::minus a la Perlmonks
[7..8),(12..20]
... which is *also* not what I want either.
So it appears that, at the very least, Set::Gapfillers and Set::Infinite
are solving different problems ... which implies that there is room for
both on CPAN (though I'm leaning to renaming it Set::Integer::Gapfillers
to emphasize that integers are the only thing it's intended to work with).
Jim Keenan