Created
May 30, 2011 16:43
-
-
Save wchristian/999138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vine_commit { | |
my ( $vines, $rev, $parents ) = @_; | |
my @graph_chars = map vine_character( $_, $rev ), @{$vines}; | |
my $is_tip = !grep { $_ eq 'C' } @graph_chars; | |
@graph_chars = insert_branch_tip_into_rightmost_empty_even_vine_slot( $rev, $vines, @graph_chars ) if $is_tip; | |
my $graph_line = join '', @graph_chars; | |
remove_trailing_blanks( $vines ); | |
# tree root | |
$graph_line =~ tr/C/r/ if !@$parents; | |
return $graph_line; | |
} | |
sub insert_branch_tip_into_rightmost_empty_even_vine_slot { | |
my ( $rev, $vines, @graph_chars ) = @_; | |
my @even_slots = grep !( $_ % 2 ), 0 .. $#graph_chars; | |
my @free_slots = grep $graph_chars[$_] eq ' ', @even_slots; | |
my $right_most_slot = 0; | |
$right_most_slot = $even_slots[-1] + 2 if @even_slots; | |
$right_most_slot = $free_slots[-1] if @free_slots; | |
$vines->[$right_most_slot] = $rev; | |
$graph_chars[$right_most_slot] = 't'; | |
$_ //= ' ' for @graph_chars; | |
return @graph_chars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment