line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Step;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
50802
|
use strict;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
82
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1737
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter;
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(step algorithm statistics end_algorithm);
|
10
|
|
|
|
|
|
|
our $VERSION = 0.02;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $algs = {};
|
13
|
|
|
|
|
|
|
my @algstack = ();
|
14
|
|
|
|
|
|
|
my $curralg;
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub algorithm {
|
17
|
1
|
|
|
1
|
1
|
13
|
my ($name, $desc) = @_;
|
18
|
1
|
50
|
|
|
|
5
|
if (!exists $algs->{$name}) {
|
19
|
1
|
|
|
|
|
4
|
$algs->{$name} = {};
|
20
|
1
|
|
|
|
|
5
|
$algs->{$name}->{desc} = $desc;
|
21
|
1
|
|
|
|
|
3
|
$algs->{$name}->{steps} = {};
|
22
|
|
|
|
|
|
|
}
|
23
|
1
|
|
|
|
|
3
|
push @algstack, $name;
|
24
|
1
|
|
|
|
|
3
|
$curralg = $name;
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub step {
|
28
|
40934
|
|
|
40934
|
1
|
154765
|
my @args = @_;
|
29
|
40934
|
|
|
|
|
44585
|
my $argc = @_;
|
30
|
40934
|
|
|
|
|
53622
|
my $refstep = $algs->{$curralg};
|
31
|
40934
|
|
|
|
|
59750
|
foreach (0 .. $argc-2) {
|
32
|
40934
|
50
|
|
|
|
84311
|
if (!exists $refstep->{steps}) {
|
33
|
0
|
|
|
|
|
0
|
$refstep->{steps} = {};
|
34
|
|
|
|
|
|
|
}
|
35
|
40934
|
|
|
|
|
47323
|
$refstep = $refstep->{steps};
|
36
|
40934
|
100
|
|
|
|
109208
|
if (!exists $refstep->{$args[$_]}) {
|
37
|
9
|
|
|
|
|
23
|
$refstep->{$args[$_]} = {};
|
38
|
9
|
|
|
|
|
85
|
$refstep->{$args[$_]}->{desc} = $args[$argc-1];
|
39
|
9
|
|
|
|
|
20
|
$refstep->{$args[$_]}->{count} = 0;
|
40
|
|
|
|
|
|
|
}
|
41
|
40934
|
|
|
|
|
91009
|
$refstep=$refstep->{$args[$_]};
|
42
|
|
|
|
|
|
|
}
|
43
|
40934
|
|
|
|
|
106412
|
$refstep->{count}++;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub statistics {
|
47
|
1
|
|
|
1
|
1
|
164
|
print "\nSTATISTICS\n\n";
|
48
|
1
|
|
|
|
|
4
|
foreach (keys %{$algs}) {
|
|
1
|
|
|
|
|
5
|
|
49
|
1
|
|
|
|
|
108
|
print "Algorithm $_: $algs->{$_}->{desc}\n";
|
50
|
1
|
|
|
|
|
4
|
my $name = $_;
|
51
|
1
|
|
|
|
|
2
|
foreach (sort keys %{$algs->{$name}->{steps}}) {
|
|
1
|
|
|
|
|
15
|
|
52
|
9
|
|
|
|
|
30
|
print_step($algs->{$name}->{steps}->{$_}, $_, 0);
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub print_step {
|
58
|
9
|
|
|
9
|
0
|
14
|
my ($step, $id, $indent) = @_;
|
59
|
9
|
|
|
|
|
11
|
my $i;
|
60
|
9
|
|
|
|
|
26
|
for ($i = 0; $i < $indent; $i++) {
|
61
|
0
|
|
|
|
|
0
|
print " ";
|
62
|
|
|
|
|
|
|
}
|
63
|
9
|
|
|
|
|
38
|
print pad_dots("STEP $id. $step->{desc} ", 72), " [$step->{count}]\n";
|
64
|
9
|
50
|
|
|
|
54
|
if (exists $step->{steps}) {
|
65
|
0
|
|
|
|
|
0
|
foreach (sort keys %{$step->{steps}}) {
|
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
print_step($step->{steps}->{$_}, "$id.$_", $indent+1);
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub pad_dots {
|
72
|
9
|
|
|
9
|
0
|
12
|
my ($s, $len) = @_;
|
73
|
9
|
50
|
|
|
|
21
|
return $s if $len <= (length $s);
|
74
|
9
|
|
|
|
|
997
|
return $s . "." x ($len - length $s);
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub end_algorithm {
|
78
|
1
|
|
|
1
|
1
|
17483
|
pop @algstack;
|
79
|
1
|
|
|
|
|
4
|
$curralg = pop @algstack;
|
80
|
1
|
|
|
|
|
18
|
push @algstack, $curralg;
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1;
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__
|