-
I want to find all final nodes, which is all nodes which do not have out-going connection. I haven't found any in-built way at egui_node_graph to do this. What I found is a way to find a connection based on the
But with that approach, to find out for one specific node, whether it has no outgoing connections, I would have to iterate over all inputs of all nodes to query if they have a connection to that specific node, which is not very efficient. Is there a better way to do this ? If there is no good way to do this yet, I suggest we add that capability to egui_node_graph by maintaining a list of final nodes (which needs to be adapted each time a connection gets added or removed). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ah, I see. Doing this is a bit inconvenient with the current API because 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:
The difference between the two sets, gives you the set of disconnected output parameters. Because those are the the values no input points to. Then, you can use the first map you computed to project the list of output ids to a list of node ids (in doing so, you need to remove duplicates, collecting into a Set will handle that). |
Beta Was this translation helpful? Give feedback.
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:
HashMap<OutputId, NodeId>
, mapping outputs to nodes. You can do this iterating thenodes
field inside the graph.HashSet<OutputId>
, with all the output ids. This one is just thekeys()
of the previous map.HashSet<…