[Lemon-user] is there a way to write a subgraph?

Balázs Dezső deba.mf at gmail.com
Fri Dec 30 21:32:21 CET 2016


>
> 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> 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>> 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>
>>         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
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20161230/aa5705f4/attachment-0001.html>


More information about the Lemon-user mailing list