| Filename | /Users/ap13/perl5/lib/perl5/Graph/AdjacencyMap/Vertex.pm |
| Statements | Executed 10 statements in 1.01ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 12µs | 24µs | Graph::AdjacencyMap::Vertex::BEGIN@7 |
| 1 | 1 | 1 | 8µs | 60µs | Graph::AdjacencyMap::Vertex::BEGIN@13 |
| 1 | 1 | 1 | 8µs | 35µs | Graph::AdjacencyMap::Vertex::BEGIN@15 |
| 1 | 1 | 1 | 7µs | 216µs | Graph::AdjacencyMap::Vertex::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::__attr |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::__has_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::__set_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::__set_path_node |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::__strval |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::_get_id_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::_get_path_count |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::_get_path_id |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::_new |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::del_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::del_path_by_multi_id |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::has_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::has_path_by_multi_id |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::paths |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Vertex::set_path |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Graph::AdjacencyMap::Vertex; | ||||
| 2 | |||||
| 3 | # THIS IS INTERNAL IMPLEMENTATION ONLY, NOT TO BE USED DIRECTLY. | ||||
| 4 | # THE INTERFACE IS HARD TO USE AND GOING TO STAY THAT WAY AND | ||||
| 5 | # ALMOST GUARANTEED TO CHANGE OR GO AWAY IN FUTURE RELEASES. | ||||
| 6 | |||||
| 7 | 2 | 25µs | 2 | 36µs | # spent 24µs (12+12) within Graph::AdjacencyMap::Vertex::BEGIN@7 which was called:
# once (12µs+12µs) by Graph::AdjacencyMap::Light::BEGIN@15 at line 7 # spent 24µs making 1 call to Graph::AdjacencyMap::Vertex::BEGIN@7
# spent 12µs making 1 call to strict::import |
| 8 | |||||
| 9 | # $SIG{__DIE__ } = sub { use Carp; confess }; | ||||
| 10 | # $SIG{__WARN__} = sub { use Carp; confess }; | ||||
| 11 | |||||
| 12 | 2 | 26µs | 2 | 425µs | # spent 216µs (7+209) within Graph::AdjacencyMap::Vertex::BEGIN@12 which was called:
# once (7µs+209µs) by Graph::AdjacencyMap::Light::BEGIN@15 at line 12 # spent 216µs making 1 call to Graph::AdjacencyMap::Vertex::BEGIN@12
# spent 209µs making 1 call to Exporter::import |
| 13 | 2 | 25µs | 2 | 112µs | # spent 60µs (8+52) within Graph::AdjacencyMap::Vertex::BEGIN@13 which was called:
# once (8µs+52µs) by Graph::AdjacencyMap::Light::BEGIN@15 at line 13 # spent 60µs making 1 call to Graph::AdjacencyMap::Vertex::BEGIN@13
# spent 52µs making 1 call to base::import |
| 14 | |||||
| 15 | 2 | 922µs | 2 | 63µs | # spent 35µs (8+28) within Graph::AdjacencyMap::Vertex::BEGIN@15 which was called:
# once (8µs+28µs) by Graph::AdjacencyMap::Light::BEGIN@15 at line 15 # spent 35µs making 1 call to Graph::AdjacencyMap::Vertex::BEGIN@15
# spent 28µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | sub _new { | ||||
| 18 | my ($class, $flags, $arity) = @_; | ||||
| 19 | bless [ 0, $flags, $arity ], $class; | ||||
| 20 | } | ||||
| 21 | |||||
| 22 | 1 | 500ns | require overload; # for de-overloading | ||
| 23 | |||||
| 24 | sub __strval { | ||||
| 25 | my ($k, $f) = @_; | ||||
| 26 | ref $k && ($f & _REF) && | ||||
| 27 | (($f & _STR) ? !overload::Method($k, '""') : overload::Method($k, '""')) ? | ||||
| 28 | overload::StrVal($k) : $k; | ||||
| 29 | } | ||||
| 30 | |||||
| 31 | sub __set_path { | ||||
| 32 | my $m = shift; | ||||
| 33 | my $f = $m->[ _f ]; | ||||
| 34 | my $id = pop if ($f & _MULTI); | ||||
| 35 | if (@_ != 1) { | ||||
| 36 | require Carp; | ||||
| 37 | Carp::confess(sprintf "Graph::AdjacencyMap::Vertex: arguments %d expected 1", scalar @_); | ||||
| 38 | } | ||||
| 39 | my $p; | ||||
| 40 | $p = $m->[ _s ] ||= { }; | ||||
| 41 | my @p = $p; | ||||
| 42 | my @k; | ||||
| 43 | my $k = shift; | ||||
| 44 | my $q = __strval($k, $f); | ||||
| 45 | push @k, $q; | ||||
| 46 | return (\@p, \@k); | ||||
| 47 | } | ||||
| 48 | |||||
| 49 | sub __set_path_node { | ||||
| 50 | my ($m, $p, $l) = splice @_, 0, 3; | ||||
| 51 | my $f = $m->[ _f ]; | ||||
| 52 | my $id = pop if ($f & _MULTI); | ||||
| 53 | unless (exists $p->[-1]->{ $l }) { | ||||
| 54 | my $i = $m->_new_node( \$p->[-1]->{ $l }, $id ); | ||||
| 55 | $m->[ _i ]->{ defined $i ? $i : "" } = $_[0]; | ||||
| 56 | } else { | ||||
| 57 | $m->_inc_node( \$p->[-1]->{ $l }, $id ); | ||||
| 58 | } | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub set_path { | ||||
| 62 | my $m = shift; | ||||
| 63 | my $f = $m->[ _f ]; | ||||
| 64 | my ($p, $k) = $m->__set_path( @_ ); | ||||
| 65 | return unless defined $p && defined $k; | ||||
| 66 | my $l = defined $k->[-1] ? $k->[-1] : ""; | ||||
| 67 | my $set = $m->__set_path_node( $p, $l, @_ ); | ||||
| 68 | return $set; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | sub __has_path { | ||||
| 72 | my $m = shift; | ||||
| 73 | my $f = $m->[ _f ]; | ||||
| 74 | if (@_ != 1) { | ||||
| 75 | require Carp; | ||||
| 76 | Carp::confess(sprintf | ||||
| 77 | "Graph::AdjacencyMap: arguments %d expected 1\n", | ||||
| 78 | scalar @_); | ||||
| 79 | } | ||||
| 80 | my $p = $m->[ _s ]; | ||||
| 81 | return unless defined $p; | ||||
| 82 | my @p = $p; | ||||
| 83 | my @k; | ||||
| 84 | my $k = shift; | ||||
| 85 | my $q = __strval($k, $f); | ||||
| 86 | push @k, $q; | ||||
| 87 | return (\@p, \@k); | ||||
| 88 | } | ||||
| 89 | |||||
| 90 | sub has_path { | ||||
| 91 | my $m = shift; | ||||
| 92 | my ($p, $k) = $m->__has_path( @_ ); | ||||
| 93 | return unless defined $p && defined $k; | ||||
| 94 | return exists $p->[-1]->{ defined $k->[-1] ? $k->[-1] : "" }; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | sub has_path_by_multi_id { | ||||
| 98 | my $m = shift; | ||||
| 99 | my $id = pop; | ||||
| 100 | my ($e, $n) = $m->__get_path_node( @_ ); | ||||
| 101 | return undef unless $e; | ||||
| 102 | return exists $n->[ _nm ]->{ $id }; | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | sub _get_path_id { | ||||
| 106 | my $m = shift; | ||||
| 107 | my $f = $m->[ _f ]; | ||||
| 108 | my ($e, $n) = $m->__get_path_node( @_ ); | ||||
| 109 | return undef unless $e; | ||||
| 110 | return ref $n ? $n->[ _ni ] : $n; | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | sub _get_path_count { | ||||
| 114 | my $m = shift; | ||||
| 115 | my $f = $m->[ _f ]; | ||||
| 116 | my ($e, $n) = $m->__get_path_node( @_ ); | ||||
| 117 | return 0 unless $e && defined $n; | ||||
| 118 | return | ||||
| 119 | ($f & _COUNT) ? $n->[ _nc ] : | ||||
| 120 | ($f & _MULTI) ? scalar keys %{ $n->[ _nm ] } : 1; | ||||
| 121 | } | ||||
| 122 | |||||
| 123 | sub __attr { | ||||
| 124 | my $m = shift; | ||||
| 125 | if (@_ && ref $_[0] && @{ $_[0] } != $m->[ _a ]) { | ||||
| 126 | require Carp; | ||||
| 127 | Carp::confess(sprintf "Graph::AdjacencyMap::Vertex: arguments %d expected %d", | ||||
| 128 | scalar @{ $_[0] }, $m->[ _a ]); | ||||
| 129 | } | ||||
| 130 | } | ||||
| 131 | |||||
| 132 | sub _get_id_path { | ||||
| 133 | my ($m, $i) = @_; | ||||
| 134 | return defined $m->[ _i ] ? $m->[ _i ]->{ $i } : undef; | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | sub del_path { | ||||
| 138 | my $m = shift; | ||||
| 139 | my $f = $m->[ _f ]; | ||||
| 140 | my ($e, $n, $p, $k, $l) = $m->__get_path_node( @_ ); | ||||
| 141 | return unless $e; | ||||
| 142 | my $c = ($f & _COUNT) ? --$n->[ _nc ] : 0; | ||||
| 143 | if ($c == 0) { | ||||
| 144 | delete $m->[ _i ]->{ ref $n ? $n->[ _ni ] : $n }; | ||||
| 145 | delete $p->[ -1 ]->{ $l }; | ||||
| 146 | } | ||||
| 147 | return 1; | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | sub del_path_by_multi_id { | ||||
| 151 | my $m = shift; | ||||
| 152 | my $f = $m->[ _f ]; | ||||
| 153 | my $id = pop; | ||||
| 154 | my ($e, $n, $p, $k, $l) = $m->__get_path_node( @_ ); | ||||
| 155 | return unless $e; | ||||
| 156 | delete $n->[ _nm ]->{ $id }; | ||||
| 157 | unless (keys %{ $n->[ _nm ] }) { | ||||
| 158 | delete $m->[ _i ]->{ $n->[ _ni ] }; | ||||
| 159 | delete $p->[-1]->{ $l }; | ||||
| 160 | } | ||||
| 161 | return 1; | ||||
| 162 | } | ||||
| 163 | |||||
| 164 | sub paths { | ||||
| 165 | my $m = shift; | ||||
| 166 | return map { [ $_ ] } values %{ $m->[ _i ] } if defined $m->[ _i ]; | ||||
| 167 | wantarray ? ( ) : 0; | ||||
| 168 | } | ||||
| 169 | |||||
| 170 | 1 | 12µs | 1; | ||
| 171 | =pod | ||||
| 172 | |||||
| 173 | =head1 NAME | ||||
| 174 | |||||
| 175 | Graph::AdjacencyMap - create and a map of graph vertices or edges | ||||
| 176 | |||||
| 177 | =head1 SYNOPSIS | ||||
| 178 | |||||
| 179 | Internal. | ||||
| 180 | |||||
| 181 | =head1 DESCRIPTION | ||||
| 182 | |||||
| 183 | B<This module is meant for internal use by the Graph module.> | ||||
| 184 | |||||
| 185 | =head2 Object Methods | ||||
| 186 | |||||
| 187 | =over 4 | ||||
| 188 | |||||
| 189 | =item del_path(@id) | ||||
| 190 | |||||
| 191 | Delete a Map path by ids. | ||||
| 192 | |||||
| 193 | =item del_path_by_multi_id($id) | ||||
| 194 | |||||
| 195 | Delete a Map path by a multi(vertex) id. | ||||
| 196 | |||||
| 197 | =item has_path(@id) | ||||
| 198 | |||||
| 199 | Return true if the Map has the path by ids, false if not. | ||||
| 200 | |||||
| 201 | =item has_path_by_multi_id($id) | ||||
| 202 | |||||
| 203 | Return true ifd the a Map has the path by a multi(vertex) id, false if not. | ||||
| 204 | |||||
| 205 | =item paths | ||||
| 206 | |||||
| 207 | Return all the paths of the Map. | ||||
| 208 | |||||
| 209 | =item set_path(@id) | ||||
| 210 | |||||
| 211 | Set the path by @ids. | ||||
| 212 | |||||
| 213 | =back | ||||
| 214 | |||||
| 215 | =head1 AUTHOR AND COPYRIGHT | ||||
| 216 | |||||
| 217 | Jarkko Hietaniemi F<jhi@iki.fi> | ||||
| 218 | |||||
| 219 | =head1 LICENSE | ||||
| 220 | |||||
| 221 | This module is licensed under the same terms as Perl itself. | ||||
| 222 | |||||
| 223 | =cut |