From: Brandon L Black Date: Wed, 8 Nov 2006 06:08:40 +0000 (+0000) Subject: line break X-Git-Tag: 0.06~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=657499e77c1d2963b9b61371a4bfedf8000e714c;p=gitmo%2FAlgorithm-C3.git line break --- diff --git a/lib/Algorithm/C3.pm b/lib/Algorithm/C3.pm index be88dc5..3c75335 100644 --- a/lib/Algorithm/C3.pm +++ b/lib/Algorithm/C3.pm @@ -54,30 +54,37 @@ sub merge { # http://www.python.org/2.3/mro.html :) # Initial set (make sure everything is copied - it will be modded) - my @seqs = map { [@$_] } (@$recurse_mergeout, $current_parents); - - # Construct the tail-checking hash - my %tails; - foreach my $seq (@seqs) { - $tails{$_}++ for (@$seq[1..$#$seq]); + my (@seqs, %tails); + for my $d (@$recurse_mergeout, $current_parents){ + if(@$d){ + push @seqs, [@$d]; + # Construct the tail-checking hash + $tails{$_}++ for (@$d[1..$#$d]); + } } my @res = ( $current_root ); while (1) { - my $cand; - my $winner; + my ($cand, $winner); + my $j = 0; foreach (@seqs) { - next if !@$_; - if(!$winner) { # looking for a winner - $cand = $_->[0]; # seq head is candidate - next if $tails{$cand}; # he loses if in %tails - push @res => $winner = $cand; + $j++; + if(!@$_){ + splice @seqs, $j, 1; + next; + } + + if(!$winner){ + next if $tails{ $cand = $_->[0] }; + push(@res, $winner = $cand); } + if($_->[0] eq $winner) { shift @$_; # strip off our winner - $tails{$_->[0]}-- if @$_; # keep %tails sane + $tails{ $_->[0] }-- if @$_; # keep %tails sane } } + last if !$cand; die q{Inconsistent hierarchy found while merging '} . $current_root . qq{':\n\t} @@ -310,3 +317,4 @@ This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut + diff --git a/t/009_dbic_merge.t b/t/009_dbic_merge.t index 10354e9..65637c8 100644 --- a/t/009_dbic_merge.t +++ b/t/009_dbic_merge.t @@ -57,7 +57,8 @@ The xx:: prefixes are just to be sure these bogus declarations never stomp on re our @ISA = qw/ xx::DBIx::Class::Relationship::HasMany xx::DBIx::Class::Relationship::HasOne - xx::DBIx::Class::Relationship::BelongsTo xx::DBIx::Class::Relationship::ManyToMany + xx::DBIx::Class::Relationship::BelongsTo + xx::DBIx::Class::Relationship::ManyToMany /; package xx::DBIx::Class::Relationship::ProxyMethods;