List of ancestor paths for a given node

6 views
Skip to first unread message

etorreborre

unread,
Feb 13, 2017, 10:23:40 AM2/13/17
to kiama
Hi Tony,

I would like to write a method to get a list of all ancestor paths for a given node in a DAG.

I can see that there some nice new machinery for attributes and relations in Kiama 2.0 but I am not sure exactly where to start.

I would like a method with such a signature:

 // collect all the nodes of type T
 // and return for each distinct node (given the system hash code) 
 // a list of all ancestor paths to the root of the graph
 def ancestorPaths[T : ClassTag, G](graph: G): Map[T, List[List[Any]]] = ???

 - do I need first to traverse the graph to build a Relation? 
 - can we use attributes for this?
 - since there's no Attributable anymore, should I build a Tree first?

Thanks,

Eric.

etorreborre

unread,
Feb 25, 2017, 2:25:24 AM2/25/17
to kiama
Actually I found my answer:

 - create a relation with Relation.fromOneStep where the step is Tree.Children
 - inverse the relation
 - recursively build the path from images of nodes in the relation

This is actually super straightforward and a great improvement over Kiama 1!

Tony Sloane

unread,
Mar 5, 2017, 7:23:11 PM3/5/17
to kiama
Hi Eric,

Sorry for the long delay in responding. Unfortunately, Kiama has not made it to the top of my stack much recently. Hopefully that is now changing and I will have more time now…

I’m glad you found a solution and that it was easy in the end. It’s good to see that the APIs are useful beyond what we designed them for.

You will probably want to update to the next version 2.1.0 when it comes out (hopefully soon). It’s got some non-trivial speedups in the Relation and Tree implementations. The APIs change a bit too but I don’t think it should affect what you are doing too much.

cheers,
Tony
--
You received this message because you are subscribed to the Google Groups "kiama" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kiama+un...@googlegroups.com.
To post to this group, send email to ki...@googlegroups.com.
Visit this group at https://groups.google.com/group/kiama.
For more options, visit https://groups.google.com/d/optout.

etorreborre

unread,
Mar 7, 2017, 3:04:46 AM3/7/17
to kiama
Thanks Tony, please post a message here when 2.1.0 is ready and I will update.
Reply all
Reply to author
Forward
0 new messages