Algorithm-Combinatorics
view release on metacpan or search on metacpan
Combinatorics.pm view on Meta::CPAN
If C<$k> is less than zero no tuple exists. Thus, the very first call to
the iterator's C<next()> method returns C<undef>, and a call in list
context returns the empty list. (See L</DIAGNOSTICS>.)
=item *
If C<$k> is zero we have one tuple, the empty tuple. This is a different
case than the former: when C<$k> is negative there are no tuples at all,
when C<$k> is zero there is one tuple. The rationale for this behaviour
is the same rationale for n choose 0 = 1: the empty tuple is a subset of
C<@data> with C<$k = 0> elements, so it complies with the definition.
=item *
If C<$k> is greater than the size of C<@data>, and we are calling a
subroutine that does not generate tuples with repetitions, no tuple
exists. Thus, the very first call to the iterator's C<next()> method
returns C<undef>, and a call in list context returns the empty
list. (See L</DIAGNOSTICS>.)
=back
In addition, since 0.05 empty C<@data>s are supported as well.
=head1 EXPORT
Algorithm::Combinatorics exports nothing by default. Each of the subroutines can be exported on demand, as in
use Algorithm::Combinatorics qw(combinations);
and the tag C<all> exports them all:
use Algorithm::Combinatorics qw(:all);
=head1 DIAGNOSTICS
=head2 Warnings
The following warnings may be issued:
=over
=item Useless use of %s in void context
A subroutine was called in void context.
=item Parameter k is negative
A subroutine was called with a negative k.
=item Parameter k is greater than the size of data
A subroutine that does not generate tuples with repetitions was called with a k greater than the size of data.
=back
=head2 Errors
The following errors may be thrown:
=over
=item Missing parameter data
A subroutine was called with no parameters.
=item Missing parameter k
A subroutine that requires a second parameter k was called without one.
=item Parameter data is not an arrayref
The first parameter is not an arrayref (tested with "reftype()" from Scalar::Util.)
=back
=head1 DEPENDENCIES
Algorithm::Combinatorics is known to run under perl 5.6.2. The
distribution uses L<Test::More> and L<FindBin> for testing,
L<Scalar::Util> for C<reftype()>, and L<XSLoader> for XS.
=head1 BUGS
Please report any bugs or feature requests to
C<bug-algorithm-combinatorics@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-Combinatorics>.
=head1 SEE ALSO
L<Math::Combinatorics> is a pure Perl module that offers similar features.
L<List::PowerSet> offers a fast pure-Perl generator of power sets that
Algorithm::Combinatorics copies and translates to XS.
=head1 BENCHMARKS
There are some benchmarks in the F<benchmarks> directory of the distribution.
=head1 REFERENCES
[1] Donald E. Knuth, I<The Art of Computer Programming, Volume 4, Fascicle 2: Generating All Tuples and Permutations>. Addison Wesley Professional, 2005. ISBN 0201853930.
[2] Donald E. Knuth, I<The Art of Computer Programming, Volume 4, Fascicle 3: Generating All Combinations and Partitions>. Addison Wesley Professional, 2005. ISBN 0201853949.
[3] Michael Orlov, I<Efficient Generation of Set Partitions>, L<http://www.informatik.uni-ulm.de/ni/Lehre/WS03/DMM/Software/partitions.pdf>.
=head1 AUTHOR
Xavier Noria (FXN), E<lt>fxn@cpan.orgE<gt>
=head1 COPYRIGHT & LICENSE
Copyright 2005-2012 Xavier Noria, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
( run in 0.486 second using v1.01-cache-2.11-cpan-adec679a428 )