NAME
Acme::Partitioner - Iterated partition refinement.
SYNOPSIS
use Acme::Partitioner;
my $p = Acme::Partitioner->using(@states);
my $partitioner =
$p->once_by(sub { $dfa->is_accepting($_) })
->then_by(sub {
join " ", map { $p->partition_of($_) }
$dfa->transitions_from($_)
});
while ($partitioning->refine) {
say "Still partitioning, got "
. $p->size . " partitions so far";
}
DESCRIPTION
This module provides a simple interface to partition items of a set into smaller sets based on criteria supplied by the caller. One step in the refinement process extracts keys from the elements and groups elements based on all of them. Criteria can be based on assignments to partitions based on previous refinements, in which case multiple refinements are necessary before the process stabilises.
METHODS
- Acme::Partitioner->using(@items)
-
Constructor, takes a list of items to be partitioned into clusters.
- once_by($sub)
-
Constructs an object that
refine
can be called on; takes a sub routine that is expected to return a grouping key when called with an item from the input list as argument. The sub will be called only during the first refinement and not during later refinements. Can also be called on objects returned byonce_by
. - then_by($sub)
-
Similar to
once_by
but the sub routine will always be called during refinement. - refine
-
Refines the partitions. Returns a true value if further refinement has been achieved, false if the number of partitions stayed the same throughout refinement.
- partition_of($item)
-
Numeric partition identifier for the supplied item.
- items_in($partition)
-
Returns a list of all items in the supplied partition;
- size()
-
Returns the current number of partitions.
- all_partitions
-
Returns a list of lists of all partitions.
EXPORTS
None.
SEE ALSO
AUTHOR / COPYRIGHT / LICENSE
Copyright (c) 2014 Bjoern Hoehrmann <bjoern@hoehrmann.de>.
This module is licensed under the same terms as Perl itself.