line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::BitMatrix; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
608
|
use strict; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
228
|
|
4
|
8
|
|
|
8
|
|
40
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
7612
|
|
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
|
213
|
my ($class, $g, %opt) = @_; |
14
|
78
|
|
|
|
|
272
|
my @V = $g->vertices; |
15
|
78
|
|
|
|
|
156
|
my $V = @V; |
16
|
78
|
|
|
|
|
270
|
my $Z = "\0" x (($V + 7) / 8); |
17
|
78
|
|
|
|
|
117
|
my %V; @V{ @V } = 0 .. $#V; |
|
78
|
|
|
|
|
386
|
|
18
|
78
|
|
|
|
|
408
|
my $bm = bless [ [ ( $Z ) x $V ], \%V ], $class; |
19
|
78
|
|
|
|
|
184
|
my $bm0 = $bm->[0]; |
20
|
78
|
|
|
|
|
157
|
my $connect_edges = delete $opt{connect_edges}; |
21
|
78
|
50
|
|
|
|
183
|
$connect_edges = 1 unless defined $connect_edges; |
22
|
78
|
|
|
|
|
118
|
my $transpose = delete $opt{transpose}; |
23
|
78
|
|
|
|
|
228
|
Graph::_opt_unknown(\%opt); |
24
|
77
|
50
|
|
|
|
180
|
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
|
|
|
|
|
221
|
my $undirected = $g->is_undirected; |
32
|
77
|
|
|
|
|
278
|
for my $e ($g->edges) { |
33
|
707
|
|
|
|
|
1666
|
my ($i0, $j0) = map $V{$_}, @$e; |
34
|
707
|
100
|
|
|
|
1279
|
($j0, $i0) = ($i0, $j0) if $transpose; |
35
|
707
|
|
|
|
|
1384
|
vec($bm0->[$i0], $j0, 1) = 1; |
36
|
707
|
100
|
|
|
|
1537
|
vec($bm0->[$j0], $i0, 1) = 1 if $undirected; |
37
|
|
|
|
|
|
|
} |
38
|
77
|
|
|
|
|
432
|
$bm; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub stringify { |
42
|
3
|
|
|
3
|
0
|
17
|
my ($m) = @_; |
43
|
3
|
|
|
|
|
5
|
my @V = sort keys %{ $m->[1] }; |
|
3
|
|
|
|
|
25
|
|
44
|
3
|
|
|
|
|
38
|
my $top = join ' ', map sprintf('%4s', $_), 'to:', @V; |
45
|
3
|
|
|
|
|
18
|
my @indices = map $m->[1]{$_}, @V; |
46
|
3
|
|
|
|
|
7
|
my @rows; |
47
|
3
|
|
|
|
|
8
|
for my $n (@V) { |
48
|
16
|
|
|
|
|
40
|
my @vals = $m->get_row($n, @V); |
49
|
16
|
50
|
|
|
|
187
|
push @rows, join ' ', map sprintf('%4s', defined()?$_:''), $n, @vals; |
50
|
|
|
|
|
|
|
} |
51
|
3
|
|
|
|
|
39
|
join '', map "$_\n", $top, @rows; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
1
|
4
|
sub set { push @_, 1; goto &_get_set } |
|
1
|
|
|
|
|
4
|
|
55
|
1
|
|
|
1
|
1
|
4
|
sub unset { push @_, 0; goto &_get_set } |
|
1
|
|
|
|
|
4
|
|
56
|
13663
|
|
|
13663
|
1
|
20931
|
sub get { push @_, undef; goto &_get_set } |
|
13663
|
|
|
|
|
26878
|
|
57
|
|
|
|
|
|
|
sub _get_set { |
58
|
13665
|
|
|
13665
|
|
18072
|
my $val = pop; |
59
|
13665
|
|
|
|
|
22300
|
my ($m, $u, $v) = @_; |
60
|
13665
|
|
|
|
|
22219
|
my ($m0, $m1) = @$m[0, 1]; |
61
|
13665
|
100
|
|
|
|
39243
|
return if grep !defined, my ($i, $j) = @$m1{ $u, $v }; |
62
|
13664
|
100
|
|
|
|
38693
|
defined $val ? vec($m0->[$i], $j, 1) = $val : vec($m0->[$i], $j, 1); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _set_row { |
66
|
2
|
|
|
2
|
|
5
|
my $val = pop; |
67
|
2
|
|
|
|
|
7
|
my ($m, $u) = splice @_, 0, 2; |
68
|
2
|
|
|
|
|
7
|
my ($m0, $m1) = @$m[0, 1]; |
69
|
2
|
50
|
|
|
|
7
|
return unless defined(my $i = $m1->{ $u }); |
70
|
2
|
|
|
|
|
18
|
vec($m0->[$i], $_, 1) = $val for grep defined, @$m1{ @_ }; |
71
|
|
|
|
|
|
|
} |
72
|
1
|
|
|
1
|
1
|
4
|
sub set_row { push @_, 1; goto &_set_row } |
|
1
|
|
|
|
|
5
|
|
73
|
1
|
|
|
1
|
1
|
3
|
sub unset_row { push @_, 0; goto &_set_row } |
|
1
|
|
|
|
|
4
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_row { |
76
|
22
|
|
|
22
|
1
|
54
|
my ($m, $u) = splice @_, 0, 2; |
77
|
22
|
|
|
|
|
41
|
my ($m0, $m1) = @$m[0, 1]; |
78
|
22
|
50
|
|
|
|
49
|
return () x @_ unless defined(my $i = $m1->{ $u }); |
79
|
22
|
100
|
|
|
|
199
|
map defined() ? (vec($m0->[$i], $_, 1) ? 1 : 0) : undef, @$m1{ @_ }; |
|
|
50
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub vertices { |
83
|
3
|
|
|
3
|
1
|
1408
|
keys %{ $_[0]->[1] }; |
|
3
|
|
|
|
|
42
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |