|
NAMESet::Partition - Enumerate all arrangements of a set in fixed subsetsVERSIONThis document describes version 0.03 of Set::Partition, released 2006-10-11.SYNOPSISuse Set::Partition; my $s = Set::Partition->new( list => [qw(a b c d e)], partition => [2, 3], ); while (my $p = $s->next) { print join( ' ', map { "(@$_)" } @$p ), $/; } # produces (a b) (c d e) (a c) (b d e) (a d) (b c e) (a e) (b c d) (b c) (a d e) (b d) (a c e) (b e) (a c d) (c d) (a b e) (c e) (a b d) (d e) (a b c) # or with a hash my $s = Set::Partition->new( list => { b => 'bat', c => 'cat', d => 'dog' }, partition => [2, 1], ); while (my $p = $s->next) { ... } DESCRIPTION"Set::Partition" takes a list or hash of elements and a list numbers that represent the sizes of the partitions into which the list of elements should be arranged.The resulting object can then be used as an iterator which returns a reference to an array of lists, that represents the original list arranged according to the given partitioning. All possible arrangements are returned, and the object returns "undef" when the entire combination space has been exhausted. METHODS
DIAGNOSTICSsum of partitions (%d) exceeds available elements (%d)A list of partition sizes (for instance, 2, 3, 4) was given, along with a list to partition (for instance, containing 8 elements), however, the number of elements required to fill the different partitions (9) exceeds the number available in the source list (8).NOTESThe order within a set is unimportant, thus, if(a b) (c d) is produced, then the following arrangement will never be encountered: (a b) (d c) On the other hand, the order of the sets is important, which means that the following arrangement will be encountered: (c d) (a b) SEE ALSO
BUGSUsing a partition of length 0 is valid, although you get back an "undef", rather than an empty array. This could be construed as a bug.Please report all bugs at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-Partition|rt.cpan.org> Make sure you include the output from the following two commands: perl -MSet::Partition -le 'print Set::Partition::VERSION' perl -V ACKNOWLEDGEMENTSKen Williams suggested the possibility to use a hash as a source for partitioning.AUTHORDavid Landgren, copyright (C) 2006. All rights reserved.http://www.landgren.net/perl/ If you (find a) use this module, I'd love to hear about it. If you want to be informed of updates, send me a note. You know my first name, you know my domain. Can you guess my e-mail address? LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |