line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::BitMatrix; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
530
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
199
|
|
4
|
8
|
|
|
8
|
|
34
|
use warnings; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
6641
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# $SIG{__DIE__ } = \&Graph::__carp_confess; |
7
|
|
|
|
|
|
|
# $SIG{__WARN__} = \&Graph::__carp_confess; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _E () { 3 } # Graph::_E() |
10
|
|
|
|
|
|
|
sub _i () { 3 } # Index to path. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
78
|
|
|
78
|
1
|
202
|
my ($class, $g, %opt) = @_; |
14
|
78
|
|
|
|
|
273
|
my @V = $g->vertices; |
15
|
78
|
|
|
|
|
141
|
my $V = @V; |
16
|
78
|
|
|
|
|
280
|
my $Z = "\0" x (($V + 7) / 8); |
17
|
78
|
|
|
|
|
129
|
my %V; @V{ @V } = 0 .. $#V; |
|
78
|
|
|
|
|
391
|
|
18
|
78
|
|
|
|
|
416
|
my $bm = bless [ [ ( $Z ) x $V ], \%V ], $class; |
19
|
78
|
|
|
|
|
172
|
my $bm0 = $bm->[0]; |
20
|
78
|
|
|
|
|
143
|
my $connect_edges = delete $opt{connect_edges}; |
21
|
78
|
50
|
|
|
|
200
|
$connect_edges = 1 unless defined $connect_edges; |
22
|
78
|
|
|
|
|
153
|
my $transpose = delete $opt{transpose}; |
23
|
78
|
|
|
|
|
221
|
Graph::_opt_unknown(\%opt); |
24
|
77
|
50
|
|
|
|
186
|
return $bm if !$connect_edges; |
25
|
|
|
|
|
|
|
# for (my $i = 0; $i <= $#V; $i++) { |
26
|
|
|
|
|
|
|
# my $u = $V[$i]; |
27
|
|
|
|
|
|
|
# for (my $j = 0; $j <= $#V; $j++) { |
28
|
|
|
|
|
|
|
# vec($bm0->[$i], $j, 1) = 1 if $g->has_edge($u, $V[$j]); |
29
|
|
|
|
|
|
|
# } |
30
|
|
|
|
|
|
|
# } |
31
|
77
|
|
|
|
|
263
|
my $undirected = $g->is_undirected; |
32
|
77
|
|
|
|
|
311
|
for my $e ($g->edges) { |
33
|
702
|
|
|
|
|
1398
|
my ($i0, $j0) = map $V{$_}, @$e; |
34
|
702
|
100
|
|
|
|
1051
|
($j0, $i0) = ($i0, $j0) if $transpose; |
35
|
702
|
|
|
|
|
1201
|
vec($bm0->[$i0], $j0, 1) = 1; |
36
|
702
|
100
|
|
|
|
1353
|
vec($bm0->[$j0], $i0, 1) = 1 if $undirected; |
37
|
|
|
|
|
|
|
} |
38
|
77
|
|
|
|
|
362
|
$bm; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub stringify { |
42
|
3
|
|
|
3
|
0
|
7
|
my ($m) = @_; |
43
|
3
|
|
|
|
|
5
|
my @V = sort keys %{ $m->[1] }; |
|
3
|
|
|
|
|
20
|
|
44
|
3
|
|
|
|
|
27
|
my $top = join ' ', map sprintf('%4s', $_), 'to:', @V; |
45
|
3
|
|
|
|
|
13
|
my @indices = map $m->[1]{$_}, @V; |
46
|
3
|
|
|
|
|
5
|
my @rows; |
47
|
3
|
|
|
|
|
8
|
for my $n (@V) { |
48
|
16
|
|
|
|
|
69
|
my @vals = $m->get_row($n, @V); |
49
|
16
|
50
|
|
|
|
128
|
push @rows, join ' ', map sprintf('%4s', defined()?$_:''), $n, @vals; |
50
|
|
|
|
|
|
|
} |
51
|
3
|
|
|
|
|
48
|
join '', map "$_\n", $top, @rows; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
1
|
3
|
sub set { push @_, 1; goto &_get_set } |
|
1
|
|
|
|
|
4
|
|
55
|
1
|
|
|
1
|
1
|
3
|
sub unset { push @_, 0; goto &_get_set } |
|
1
|
|
|
|
|
4
|
|
56
|
13063
|
|
|
13063
|
1
|
16917
|
sub get { push @_, undef; goto &_get_set } |
|
13063
|
|
|
|
|
23372
|
|
57
|
|
|
|
|
|
|
sub _get_set { |
58
|
13065
|
|
|
13065
|
|
14451
|
my $val = pop; |
59
|
13065
|
|
|
|
|
18053
|
my ($m, $u, $v) = @_; |
60
|
13065
|
|
|
|
|
16958
|
my ($m0, $m1) = @$m[0, 1]; |
61
|
13065
|
100
|
|
|
|
35048
|
return if grep !defined, my ($i, $j) = @$m1{ $u, $v }; |
62
|
13064
|
100
|
|
|
|
32301
|
defined $val ? vec($m0->[$i], $j, 1) = $val : vec($m0->[$i], $j, 1); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _set_row { |
66
|
2
|
|
|
2
|
|
4
|
my $val = pop; |
67
|
2
|
|
|
|
|
5
|
my ($m, $u) = splice @_, 0, 2; |
68
|
2
|
|
|
|
|
5
|
my ($m0, $m1) = @$m[0, 1]; |
69
|
2
|
50
|
|
|
|
6
|
return unless defined(my $i = $m1->{ $u }); |
70
|
2
|
|
|
|
|
14
|
vec($m0->[$i], $_, 1) = $val for grep defined, @$m1{ @_ }; |
71
|
|
|
|
|
|
|
} |
72
|
1
|
|
|
1
|
1
|
3
|
sub set_row { push @_, 1; goto &_set_row } |
|
1
|
|
|
|
|
5
|
|
73
|
1
|
|
|
1
|
1
|
4
|
sub unset_row { push @_, 0; goto &_set_row } |
|
1
|
|
|
|
|
3
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_row { |
76
|
22
|
|
|
22
|
1
|
43
|
my ($m, $u) = splice @_, 0, 2; |
77
|
22
|
|
|
|
|
33
|
my ($m0, $m1) = @$m[0, 1]; |
78
|
22
|
50
|
|
|
|
44
|
return () x @_ unless defined(my $i = $m1->{ $u }); |
79
|
22
|
100
|
|
|
|
189
|
map defined() ? (vec($m0->[$i], $_, 1) ? 1 : 0) : undef, @$m1{ @_ }; |
|
|
50
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub vertices { |
83
|
3
|
|
|
3
|
1
|
778
|
keys %{ $_[0]->[1] }; |
|
3
|
|
|
|
|
28
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |