[Lemon-user] bug in iteration over nodes of FilterNodes?

Peter Ka peter_ka at ymail.com
Thu Aug 11 19:20:07 CEST 2011


Dear all,
I am quite new to the lemon community.

I've been trying to create a NodeFilter adapter to filter some of the  nodes, and then iterate through the remaining nodes. I've come across a bug which I simply can't understand and would appreciate your help. I use lemon 1.2.2 (stable).

When running the following code:

SmartGraph g;
for(int i = 0; i < 5; i++) { g.addNode(); }
SmartGraph::NodeMap<bool> filter(g, true);
FilterNodes<SmartGraph> *filtered_g = new FilterNodes<SmartGraph>(g, filter);
for(FilterNodes<SmartGraph>::NodeIt n(*filtered_g); n != INVALID; ++n)
    cout << "I am in node " << g.id(n) << endl;


I get the expected result. HOWEVER, when I replace the line that defines filtered_g with:
FilterNodes<SmartGraph> *filtered_g = foo(g);

with:
FilterNodes<SmartGraph>* foo(SmartGraph& g)
{
    SmartGraph::NodeMap<bool> filter(g, true);
    return new FilterNodes<SmartGraph>(g, filter);
}

I get unexpected results (sometimes segmentation errors, sometimes the iterator runs only on a subset of the vertices - depends on the input graph I generate).
Can someone please explain to me what's going on here? Shouldn't both pieces of code be completely equivalent?

Thanks much,
Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20110811/f5fe72d1/attachment.html>


More information about the Lemon-user mailing list