8 GetOptions \
our %Conf, qw(help|h nodes|n=s initial=s@ debug=s except=s@);
12 run with -n filename containing nodes data produced by --nodes
13 of graphfuncs.pl. Will print initial set sizes for all functions
14 by default, or use -initial <fname>, possibly many times, to
15 specify the initial set. -except <fname> introduces a function to
16 ignore, can iterate. -debug <fname> is a function to print more
17 information about as components are computed.
22 our $nodes = YAML
::LoadFile
($Conf{nodes
}) or
23 die "can't load nodes data: $!";
27 $ignoring{$_} = 1 && print "Ignoring: $_\n" for (@
{$Conf{except
}});
29 if (+$Conf{initial
}) {
30 print "Initial set: " . join(' ', @
{$Conf{initial
}}) . "\n";
31 doUnion
(@
{$Conf{initial
}});
35 print "$_: " . union
({$_=>1}, $_) . "\n";
41 my %ccset = map { $_ => 1 } @_;
42 union
(\
%ccset, $_) for keys %ccset;
43 print "doUnion: initial set size is " . scalar(keys %ccset) . "\n";
45 print "\nFinding candidates.\n\n";
48 #while (my $new = candidates(\%ccset)) {
49 # union(\%ccset, $new);
55 my $oldsize = keys %$set;
56 my $debug = $new eq ($Conf{debug
}||="");
58 return 0 if $ignoring{$new};
60 my $size = scalar(keys %$set) - 1; # to force one run even if $new is in
62 while (scalar(keys %$set) > $size) {
64 for my $f (keys %$set) {
65 for my $t (@
{$nodes->{$f}}) {
66 next if $set->{$t} or $ignoring{$t};
67 print "unionising $new: adding $t on account of $f\n" if $Conf{verbose
} or $Conf{debug
} eq $new;
72 #print ::Y({post=>{set=>$set, new=>$new}});
73 print "union: while adding $new, entered with $oldsize, leaving with $size\n"
74 if $Conf{verbose
} or $Conf{debug
} eq $new;
75 return $size - $oldsize; # new member count
81 for my $cand (keys %$nodes) {
82 #print "trying: $cand\n";
83 next if exists $ccset->{$cand} or $ignoring{$cand};
84 #print "passed: $cand\n";
85 $cands{$cand} = [ scalar @
{$nodes->{$cand}},
86 # total callees for func
87 , union
(Storable
::dclone
($ccset), $cand)]; # new contributions
88 #print "$cand: totall $cands{$cand}[0] $cands{$cand}[1]\n";
91 # print ten best candidates
92 print_cand
($_, $cands{$_}) for
93 sort {score
(@
{$cands{$b}}) <=> score
(@
{$cands{$a}})}
97 # return list of newly selected functions
101 my ($cand, $data) = @_;
102 my ($total, $new) = @
$data;
103 printf "$cand: %s ($total total, $new new)\n", score
($total, $new);
107 my ($total, $new) = @_;
108 return 0 if $total == $new;
109 ($total - $new) / $total;
112 #sub clone { Load(Dump($_[0])) }
113 sub ::Y
{ require YAML
; YAML
::Dump
(@_) }
114 sub ::YY
{ require Carp
; Carp
::confess
(::Y
(@_)) }