| Filename | /Users/ap13/perl5/lib/perl5/Graph/TransitiveClosure.pm |
| Statements | Executed 7 statements in 504µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.50ms | 4.19ms | Graph::TransitiveClosure::BEGIN@10 |
| 1 | 1 | 1 | 12µs | 25µs | Graph::TransitiveClosure::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 68µs | Graph::TransitiveClosure::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Graph::TransitiveClosure::_G |
| 0 | 0 | 0 | 0s | 0s | Graph::TransitiveClosure::is_transitive |
| 0 | 0 | 0 | 0s | 0s | Graph::TransitiveClosure::new |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Graph::TransitiveClosure; | ||||
| 2 | |||||
| 3 | 2 | 26µs | 2 | 38µs | # spent 25µs (12+13) within Graph::TransitiveClosure::BEGIN@3 which was called:
# once (12µs+13µs) by Graph::BEGIN@32 at line 3 # spent 25µs making 1 call to Graph::TransitiveClosure::BEGIN@3
# spent 13µs making 1 call to strict::import |
| 4 | |||||
| 5 | # COMMENT THESE OUT FOR TESTING AND PRODUCTION. | ||||
| 6 | # $SIG{__DIE__ } = sub { use Carp; confess }; | ||||
| 7 | # $SIG{__WARN__} = sub { use Carp; confess }; | ||||
| 8 | |||||
| 9 | 2 | 30µs | 2 | 127µs | # spent 68µs (9+59) within Graph::TransitiveClosure::BEGIN@9 which was called:
# once (9µs+59µs) by Graph::BEGIN@32 at line 9 # spent 68µs making 1 call to Graph::TransitiveClosure::BEGIN@9
# spent 59µs making 1 call to base::import |
| 10 | 2 | 444µs | 1 | 4.19ms | # spent 4.19ms (1.50+2.69) within Graph::TransitiveClosure::BEGIN@10 which was called:
# once (1.50ms+2.69ms) by Graph::BEGIN@32 at line 10 # spent 4.19ms making 1 call to Graph::TransitiveClosure::BEGIN@10 |
| 11 | |||||
| 12 | sub _G () { Graph::_G() } | ||||
| 13 | |||||
| 14 | sub new { | ||||
| 15 | my ($class, $g, %opt) = @_; | ||||
| 16 | $g->expect_non_multiedged; | ||||
| 17 | %opt = (path_vertices => 1) unless %opt; | ||||
| 18 | my $attr = Graph::_defattr(); | ||||
| 19 | if (exists $opt{ attribute_name }) { | ||||
| 20 | $attr = $opt{ attribute_name }; | ||||
| 21 | # No delete $opt{ attribute_name } since we need to pass it on. | ||||
| 22 | } | ||||
| 23 | $opt{ reflexive } = 1 unless exists $opt{ reflexive }; | ||||
| 24 | my $tcm = $g->new( $opt{ reflexive } ? | ||||
| 25 | ( vertices => [ $g->vertices ] ) : ( ) ); | ||||
| 26 | my $tcg = $g->get_graph_attribute('_tcg'); | ||||
| 27 | if (defined $tcg && $tcg->[ 0 ] == $g->[ _G ]) { | ||||
| 28 | $tcg = $tcg->[ 1 ]; | ||||
| 29 | } else { | ||||
| 30 | $tcg = Graph::TransitiveClosure::Matrix->new($g, %opt); | ||||
| 31 | $g->set_graph_attribute('_tcg', [ $g->[ _G ], $tcg ]); | ||||
| 32 | } | ||||
| 33 | my $tcg00 = $tcg->[0]->[0]; | ||||
| 34 | my $tcg11 = $tcg->[1]->[1]; | ||||
| 35 | for my $u ($tcg->vertices) { | ||||
| 36 | my $tcg00i = $tcg00->[ $tcg11->{ $u } ]; | ||||
| 37 | for my $v ($tcg->vertices) { | ||||
| 38 | next if $u eq $v && ! $opt{ reflexive }; | ||||
| 39 | my $j = $tcg11->{ $v }; | ||||
| 40 | if ( | ||||
| 41 | # $tcg->is_transitive($u, $v) | ||||
| 42 | # $tcg->[0]->get($u, $v) | ||||
| 43 | vec($tcg00i, $j, 1) | ||||
| 44 | ) { | ||||
| 45 | my $val = $g->_get_edge_attribute($u, $v, $attr); | ||||
| 46 | $tcm->_set_edge_attribute($u, $v, $attr, | ||||
| 47 | defined $val ? $val : | ||||
| 48 | $u eq $v ? | ||||
| 49 | 0 : 1); | ||||
| 50 | } | ||||
| 51 | } | ||||
| 52 | } | ||||
| 53 | $tcm->set_graph_attribute('_tcm', $tcg); | ||||
| 54 | bless $tcm, $class; | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub is_transitive { | ||||
| 58 | my $g = shift; | ||||
| 59 | Graph::TransitiveClosure::Matrix::is_transitive($g); | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | 1 | 4µs | 1; | ||
| 63 | __END__ |