[Lemon-user] is there a way to write a subgraph?
Kovács Péter
kpeter at inf.elte.hu
Fri Dec 30 21:47:27 CET 2016
Hi All,
Thanks for the corrections. I'm terribly sorry for the stupid mistake.
So I suggest passing references, but of course, not for local variables. :)
Péter
> FilterNodes<ListDigraph>& get_subgraph(void)
> {
> FilterNodes<ListDigraph> subgraph;
> ...
> return g;
> }
>
> This is a bad idea as it creates a reference to a temporary variable. I
> think the real problem is that the FilterNodes is initiated with a local
> map, which is destroyed when the execution leaves the function scope.
>
> Balazs
>
> On Fri, Dec 30, 2016 at 9:17 PM, Kovács Péter <kpeter at inf.elte.hu
> <mailto:kpeter at inf.elte.hu>> wrote:
>
> Hi John,
>
> You should avoid passing graphs (and other large data structures) as
> values between functions. Use references or pointers instead. For
> example:
>
> FilterNodes<ListDigraph>& get_subgraph(void)
> {
> FilterNodes<ListDigraph> subgraph;
> ...
> return g;
> }
>
> Note the '&' sign in the return type of the function. (If its
> meaning is not clear, read some C++ tutorials about references and
> pointers.)
>
> Regards,
> Péter
>
>
>
> Péter,
>
> It turns out that the issue I am having is related to trying to
> return
> a FilterNodes<ListDigraph> issue from a function. If
> the FilterNodes<ListDigraph> object is local I can iterate
> through the
> nodes as expected. If the object is returned from a function i.e.
>
> FilterNodes<ListDigraph> get_subgraph(void)
> {
> }
>
> void another_function()
> {
> auto x = get_subgraph();
>
> for (FilterNodes<ListDigraph>::NodeIt n(x); n != INVALID; ++n)
> ...
> }
>
> I get an exception when trying to iterate through the nodes.
>
> John
>
>
>
>
> On Thu, Dec 29, 2016 at 5:28 PM, Kovács Péter
> <kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>
> <mailto:kpeter at inf.elte.hu <mailto:kpeter at inf.elte.hu>>> wrote:
>
> Hi John,
>
> What kind of write method are you looking for? Could you
> send a code
> snippet that works for the graph, but does not apply to the
> subgraph?
>
> Regards,
> Péter
>
>
> I have a subgraph as follows:
>
> FilterNodes<ListDigraph> sub(*graph, filter);
>
> There doesn't appear to be a write method for the
> subgraph as
> there is
> for the graph.
>
> Suggestions?
>
>
> --
> John Lagerquist
> Chief Engineer
> RallyTronics LLC
> 801-866-5981
>
>
>
>
> _______________________________________________
> Lemon-user mailing list
> Lemon-user at lemon.cs.elte.hu
> <mailto:Lemon-user at lemon.cs.elte.hu>
> <mailto:Lemon-user at lemon.cs.elte.hu
> <mailto:Lemon-user at lemon.cs.elte.hu>>
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>
> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>>
>
>
>
>
>
> --
> John Lagerquist
> Chief Engineer
> RallyTronics LLC
> 801-866-5981
>
>
>
> _______________________________________________
> Lemon-user mailing list
> Lemon-user at lemon.cs.elte.hu <mailto:Lemon-user at lemon.cs.elte.hu>
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
> <http://lemon.cs.elte.hu/mailman/listinfo/lemon-user>
>
>
More information about the Lemon-user
mailing list