Sort::Topological - Topological Sort


Data-Match documentation  | view source Contained in the Data-Match distribution.

Index


NAME

Top

Sort::Topological - Topological Sort

SYNOPSIS

Top

  use Sort::Topological qw(toposort);
  my @result = toposort($item_direct_sub, @items);

DESCRIPTION

Top

Sort::Topological does a topological sort of an acyclical directed graph.

EXAMPLE

Top

  my %children = (
		  'a' => [ 'b', 'c' ],
		  'c' => [ 'x' ],
		  'b' => [ 'x' ],
		  'x' => [ 'y' ],
		  'y' => [ 'z' ],
		  'z' => [ ],
		  );
  sub children { @{$children{$_[0]} || []}; } 
  my @unsorted = ( 'z', 'a', 'x', 'c', 'b', 'y' );
  my @sorted = toposort(\&children, \@unsorted);




In the above example %children is the graph, &children($x) returns a list of targets of the directed graph from $x.

@sorted is sorted such that:

for any $x in @sorted:

i.e.: 'y' is not reachable by 'z', 'x' is not reachable by 'y' or 'z', and so on.

CAVEATS

Top

STATUS

Top

If you find this to be useful please contact the author. This is alpha software; all APIs, semantics and behavors are subject to change.

INTERFACE

Top

This section describes the external interface of this module.

VERSION

Top

Version 0.01, $Revision: 1.2 $.

AUTHOR

Top

Kurt A. Stephens <ks.perl@kurtstephens.com>

COPYRIGHT

Top

SEE ALSO

Top

>.


Data-Match documentation  | view source Contained in the Data-Match distribution.