Filename | /Users/ap13/perl5/lib/perl5/Graph/AdjacencyMatrix.pm |
Statements | Executed 11 statements in 911µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 965µs | 987µs | BEGIN@5 | Graph::AdjacencyMatrix::
1 | 1 | 1 | 394µs | 443µs | BEGIN@6 | Graph::AdjacencyMatrix::
1 | 1 | 1 | 18µs | 128µs | BEGIN@8 | Graph::AdjacencyMatrix::
1 | 1 | 1 | 13µs | 333µs | BEGIN@10 | Graph::AdjacencyMatrix::
1 | 1 | 1 | 12µs | 23µs | BEGIN@3 | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | adjacency_matrix | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | distance | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | distance_matrix | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | is_adjacent | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | new | Graph::AdjacencyMatrix::
0 | 0 | 0 | 0s | 0s | vertices | Graph::AdjacencyMatrix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Graph::AdjacencyMatrix; | ||||
2 | |||||
3 | 2 | 27µs | 2 | 35µs | # spent 23µs (12+12) within Graph::AdjacencyMatrix::BEGIN@3 which was called:
# once (12µs+12µs) by Graph::TransitiveClosure::Matrix::BEGIN@5 at line 3 # spent 23µs making 1 call to Graph::AdjacencyMatrix::BEGIN@3
# spent 12µs making 1 call to strict::import |
4 | |||||
5 | 2 | 126µs | 1 | 987µs | # spent 987µs (965+22) within Graph::AdjacencyMatrix::BEGIN@5 which was called:
# once (965µs+22µs) by Graph::TransitiveClosure::Matrix::BEGIN@5 at line 5 # spent 987µs making 1 call to Graph::AdjacencyMatrix::BEGIN@5 |
6 | 2 | 176µs | 1 | 443µs | # spent 443µs (394+48) within Graph::AdjacencyMatrix::BEGIN@6 which was called:
# once (394µs+48µs) by Graph::TransitiveClosure::Matrix::BEGIN@5 at line 6 # spent 443µs making 1 call to Graph::AdjacencyMatrix::BEGIN@6 |
7 | |||||
8 | 2 | 50µs | 2 | 238µs | # spent 128µs (18+110) within Graph::AdjacencyMatrix::BEGIN@8 which was called:
# once (18µs+110µs) by Graph::TransitiveClosure::Matrix::BEGIN@5 at line 8 # spent 128µs making 1 call to Graph::AdjacencyMatrix::BEGIN@8
# spent 110µs making 1 call to base::import |
9 | |||||
10 | 2 | 526µs | 2 | 653µs | # spent 333µs (13+320) within Graph::AdjacencyMatrix::BEGIN@10 which was called:
# once (13µs+320µs) by Graph::TransitiveClosure::Matrix::BEGIN@5 at line 10 # spent 333µs making 1 call to Graph::AdjacencyMatrix::BEGIN@10
# spent 320µs making 1 call to Exporter::import |
11 | |||||
12 | sub _V () { 2 } # Graph::_V | ||||
13 | sub _E () { 3 } # Graph::_E | ||||
14 | |||||
15 | sub new { | ||||
16 | my ($class, $g, %opt) = @_; | ||||
17 | my $n; | ||||
18 | my @V = $g->vertices; | ||||
19 | my $want_distance; | ||||
20 | if (exists $opt{distance_matrix}) { | ||||
21 | $want_distance = $opt{distance_matrix}; | ||||
22 | delete $opt{distance_matrix}; | ||||
23 | } | ||||
24 | my $d = Graph::_defattr(); | ||||
25 | if (exists $opt{attribute_name}) { | ||||
26 | $d = $opt{attribute_name}; | ||||
27 | $want_distance++; | ||||
28 | } | ||||
29 | delete $opt{attribute_name}; | ||||
30 | my $want_transitive = 0; | ||||
31 | if (exists $opt{is_transitive}) { | ||||
32 | $want_transitive = $opt{is_transitive}; | ||||
33 | delete $opt{is_transitive}; | ||||
34 | } | ||||
35 | Graph::_opt_unknown(\%opt); | ||||
36 | if ($want_distance) { | ||||
37 | $n = Graph::Matrix->new($g); | ||||
38 | for my $v (@V) { $n->set($v, $v, 0) } | ||||
39 | } | ||||
40 | my $m = Graph::BitMatrix->new($g, connect_edges => $want_distance); | ||||
41 | if ($want_distance) { | ||||
42 | # for my $u (@V) { | ||||
43 | # for my $v (@V) { | ||||
44 | # if ($g->has_edge($u, $v)) { | ||||
45 | # $n->set($u, $v, | ||||
46 | # $g->get_edge_attribute($u, $v, $d)); | ||||
47 | # } | ||||
48 | # } | ||||
49 | # } | ||||
50 | my $Vi = $g->[_V]->[_i]; | ||||
51 | my $Ei = $g->[_E]->[_i]; | ||||
52 | my %V; @V{ @V } = 0 .. $#V; | ||||
53 | my $n0 = $n->[0]; | ||||
54 | my $n1 = $n->[1]; | ||||
55 | if ($g->is_undirected) { | ||||
56 | for my $e (keys %{ $Ei }) { | ||||
57 | my ($i0, $j0) = @{ $Ei->{ $e } }; | ||||
58 | my $i1 = $V{ $Vi->{ $i0 } }; | ||||
59 | my $j1 = $V{ $Vi->{ $j0 } }; | ||||
60 | my $u = $V[ $i1 ]; | ||||
61 | my $v = $V[ $j1 ]; | ||||
62 | $n0->[ $i1 ]->[ $j1 ] = | ||||
63 | $g->get_edge_attribute($u, $v, $d); | ||||
64 | $n0->[ $j1 ]->[ $i1 ] = | ||||
65 | $g->get_edge_attribute($v, $u, $d); | ||||
66 | } | ||||
67 | } else { | ||||
68 | for my $e (keys %{ $Ei }) { | ||||
69 | my ($i0, $j0) = @{ $Ei->{ $e } }; | ||||
70 | my $i1 = $V{ $Vi->{ $i0 } }; | ||||
71 | my $j1 = $V{ $Vi->{ $j0 } }; | ||||
72 | my $u = $V[ $i1 ]; | ||||
73 | my $v = $V[ $j1 ]; | ||||
74 | $n0->[ $i1 ]->[ $j1 ] = | ||||
75 | $g->get_edge_attribute($u, $v, $d); | ||||
76 | } | ||||
77 | } | ||||
78 | } | ||||
79 | bless [ $m, $n, [ @V ] ], $class; | ||||
80 | } | ||||
81 | |||||
82 | sub adjacency_matrix { | ||||
83 | my $am = shift; | ||||
84 | $am->[0]; | ||||
85 | } | ||||
86 | |||||
87 | sub distance_matrix { | ||||
88 | my $am = shift; | ||||
89 | $am->[1]; | ||||
90 | } | ||||
91 | |||||
92 | sub vertices { | ||||
93 | my $am = shift; | ||||
94 | @{ $am->[2] }; | ||||
95 | } | ||||
96 | |||||
97 | sub is_adjacent { | ||||
98 | my ($m, $u, $v) = @_; | ||||
99 | $m->[0]->get($u, $v) ? 1 : 0; | ||||
100 | } | ||||
101 | |||||
102 | sub distance { | ||||
103 | my ($m, $u, $v) = @_; | ||||
104 | defined $m->[1] ? $m->[1]->get($u, $v) : undef; | ||||
105 | } | ||||
106 | |||||
107 | 1 | 6µs | 1; | ||
108 | __END__ |