-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be polished, but it looks bug-free to me.
if node.sname[-1] == ']': | ||
leaf_nodes.append(sn) | ||
else: | ||
for key in node.childs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for child in node.children.values():
traverse_tree(child, sn)
for key in node.childs: | ||
traverse_tree(node.childs[key], sn) | ||
traverse_tree(root, '') | ||
return leaf_nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm right, what this is doing is actually: finding all leaf nodes that ends with ]
. If so, there is a simpler way to do it:
all_names = [node.scopeName() for node in graph.nodes()]
all_names = list(filter(lambda x: x, all_names)) # filter out non-empty strings
all_names.sort()
leaf_nodes = []
for i, name in enumerate(all_names):
if (i + 1 >= len(all_names) or not all_names[i + 1].startswith(name)) and name.endswith("]"):
leaf_nodes.append(name)
return leaf_nodes
Since I didn't get enough context, I might be wrong...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I test both your functions, they can generate same results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ultmaster too complex, I am not sure whether the logic is correct or not...
No description provided.