Skip to content

dfs traversal: simplify edges in reverse mode#33481

Merged
tgamblin merged 1 commit intospack:developfrom
haampie:fix/flip-edges
Oct 26, 2022
Merged

dfs traversal: simplify edges in reverse mode#33481
tgamblin merged 1 commit intospack:developfrom
haampie:fix/flip-edges

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Oct 24, 2022

In the dfs code, flip edges so that parent always means from and
spec means to in the direction of traversal. This makes it slightly
easier to write generic/composable code. For example when using visitors
where one visitor reverses direction, and another only cares about
accepting particular edges or not depending on whether the to node
is seen before, it would be good if the second visitor didn't have to
know whether the order was changed or not.

As far as I can see, we never use traverse_edges(direction="parents"), we
only ever use traverse(direction="parents") which yields nodes not edges. So
should be fine to flip those edges.

This change should help unify the code of #33406, since we can then
reuse ReverseVisitor / CoverNodesVisitor / CoverEdgesVisitor in
DFS and BFS.

In the dfs code, flip edges so that `parent` means `from` and
`spec` means `to` in the direction of traversal. This makes it slightly
easier to write generic/composable code. For example when using visitors
where one visitor reverses direction, and another only cares about
accepting particular edges or not depending on whether the target node
is seen before, it would be good if the second visitor didn't have to
know whether the order was changed or not.
@spackbot-app spackbot-app bot added the core PR affects Spack core functionality label Oct 24, 2022
@haampie haampie requested a review from tgamblin October 24, 2022 10:33
@tgamblin
Copy link
Copy Markdown
Member

LGTM -- this simplifies the traversal cases quite a bit.

@tgamblin tgamblin merged commit d039744 into spack:develop Oct 26, 2022
@haampie haampie deleted the fix/flip-edges branch October 26, 2022 08:16
becker33 pushed a commit to RikkiButler20/spack that referenced this pull request Nov 2, 2022
In the dfs code, flip edges so that `parent` means `from` and
`spec` means `to` in the direction of traversal. This makes it slightly
easier to write generic/composable code. For example when using visitors
where one visitor reverses direction, and another only cares about
accepting particular edges or not depending on whether the target node
is seen before, it would be good if the second visitor didn't have to
know whether the order was changed or not.
charmoniumQ pushed a commit to charmoniumQ/spack that referenced this pull request Nov 19, 2022
In the dfs code, flip edges so that `parent` means `from` and
`spec` means `to` in the direction of traversal. This makes it slightly
easier to write generic/composable code. For example when using visitors
where one visitor reverses direction, and another only cares about
accepting particular edges or not depending on whether the target node
is seen before, it would be good if the second visitor didn't have to
know whether the order was changed or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR affects Spack core functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants