Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
hic sunt leones
sub findMinCycles {
# hic sunt leones
# sorry for the terse code, I promise it works, no need to touch it :)
my ($self, $v, $g, $i, $s) = @_;
if (exists $i->{$v}) {
my @c = @{$s}[$i->{$v}..$#$s];
my $k = (sort { @{$g->{$c[$b]}}<=> @{$g->{$c[$a]}} } (0 .. $#c))[0];
push @c, $v;
local $" = ' -> ';
$self->error("Dependency cycle detected: @c");
$self->verbose("DEBUG: removing $c[$k] -> $c[$k+1]");
my $e = $g->{$c[$k]};
my $w = $c[$k+1];
for my $j (0 .. $#$e) {
if ($w eq $e->[$j]) {
splice @$e, $j, 1;
} elsif (defined $g->{$v}) {
push @$s, $v;
$i->{$v} = $#$s;
my @e = @{$g->{$v}};
foreach my $w (@e) {
$self->findMinCycles($w, $g, $i, $s);
delete $i->{$v};
pop @$s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.