Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

What is the best way to find all final nodes ? #13

Answered by setzer22
rsaccon asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, I see. Doing this is a bit inconvenient with the current API because connections goes backwards. This is the most ergonomic way to build the compiler (which needs to traverse the graph in dependency order), but it makes it difficult to find final nodes.

I will work on a fix for this (I just filed an issue #14) In the meantime here's a a slightly inefficient way you can do this without any changes to the code. Basically, you need to create three data structures:

  • A HashMap<OutputId, NodeId>, mapping outputs to nodes. You can do this iterating the nodes field inside the graph.
  • A HashSet<OutputId>, with all the output ids. This one is just the keys() of the previous map.
  • Another HashSet<…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rsaccon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants