1 package Graph
::AdjacencyMap
::Vertex
;
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.
9 # $SIG{__DIE__ } = sub { use Carp; confess };
10 # $SIG{__WARN__} = sub { use Carp; confess };
12 use Graph
::AdjacencyMap
qw(:flags :fields);
13 use base
'Graph::AdjacencyMap';
15 use Scalar
::Util
qw(weaken);
18 my ($class, $flags, $arity) = @_;
19 bless [ 0, $flags, $arity ], $class;
22 require overload
; # for de-overloading
27 my $id = pop if ($f & _MULTI
);
30 Carp
::confess
(sprintf "Graph::AdjacencyMap::Vertex: arguments %d expected 1", scalar @_);
33 $p = $m->[ _s
] ||= { };
37 my $q = ref $k && ($f & _REF
) && overload
::Method
($k, '""') ? overload
::StrVal
($k) : $k;
43 my ($m, $p, $l) = splice @_, 0, 3;
45 my $id = pop if ($f & _MULTI
);
46 unless (exists $p->[-1]->{ $l }) {
47 my $i = $m->_new_node( \
$p->[-1]->{ $l }, $id );
48 $m->[ _i
]->{ defined $i ?
$i : "" } = $_[0];
50 $m->_inc_node( \
$p->[-1]->{ $l }, $id );
57 my ($p, $k) = $m->__set_path( @_ );
58 return unless defined $p && defined $k;
59 my $l = defined $k->[-1] ?
$k->[-1] : "";
60 my $set = $m->__set_path_node( $p, $l, @_ );
70 "Graph::AdjacencyMap: arguments %d expected 1\n",
74 return unless defined $p;
78 my $q = ref $k && ($f & _REF
) && overload
::Method
($k, '""') ? overload
::StrVal
($k) : $k;
85 my ($p, $k) = $m->__has_path( @_ );
86 return unless defined $p && defined $k;
87 return exists $p->[-1]->{ defined $k->[-1] ?
$k->[-1] : "" };
90 sub has_path_by_multi_id
{
93 my ($e, $n) = $m->__get_path_node( @_ );
94 return undef unless $e;
95 return exists $n->[ _nm
]->{ $id };
101 my ($e, $n) = $m->__get_path_node( @_ );
102 return undef unless $e;
103 return ref $n ?
$n->[ _ni
] : $n;
106 sub _get_path_count
{
109 my ($e, $n) = $m->__get_path_node( @_ );
110 return 0 unless $e && defined $n;
112 ($f & _COUNT
) ?
$n->[ _nc
] :
113 ($f & _MULTI
) ?
scalar keys %{ $n->[ _nm
] } : 1;
118 if (@_ && ref $_[0] && @
{ $_[0] } != $m->[ _a
]) {
120 Carp
::confess
(sprintf "Graph::AdjacencyMap::Vertex: arguments %d expected %d",
121 scalar @
{ $_[0] }, $m->[ _a
]);
127 return defined $m->[ _i
] ?
$m->[ _i
]->{ $i } : undef;
133 my ($e, $n, $p, $k, $l) = $m->__get_path_node( @_ );
135 my $c = ($f & _COUNT
) ?
--$n->[ _nc
] : 0;
137 delete $m->[ _i
]->{ ref $n ?
$n->[ _ni
] : $n };
138 delete $p->[ -1 ]->{ $l };
143 sub del_path_by_multi_id
{
147 my ($e, $n, $p, $k, $l) = $m->__get_path_node( @_ );
149 delete $n->[ _nm
]->{ $id };
150 unless (keys %{ $n->[ _nm
] }) {
151 delete $m->[ _i
]->{ $n->[ _ni
] };
152 delete $p->[-1]->{ $l };
159 return map { [ $_ ] } values %{ $m->[ _i
] } if defined $m->[ _i
];
168 Graph::AdjacencyMap - create and a map of graph vertices or edges
176 B<This module is meant for internal use by the Graph module.>
178 =head2 Object Methods
184 Delete a Map path by ids.
186 =item del_path_by_multi_id($id)
188 Delete a Map path by a multi(vertex) id.
192 Return true if the Map has the path by ids, false if not.
194 =item has_path_by_multi_id($id)
196 Return true ifd the a Map has the path by a multi(vertex) id, false if not.
200 Return all the paths of the Map.
204 Set the path by @ids.
208 =head1 AUTHOR AND COPYRIGHT
210 Jarkko Hietaniemi F<jhi@iki.fi>
214 This module is licensed under the same terms as Perl itself.