Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up label_nodes by sharing dictionary lookups #3

Merged
merged 1 commit into from
Nov 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/dags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,12 @@ Assign an integer label to each circuit node, bottom up, starting at `1`
function label_nodes(root::DAG)
labeling = Dict{DAG,Int}()
i = 0
foreach(root) do node
labeling[node] = (i+=1)
end
f_inner(n, call) = begin
foreach(call, children(n))
(i += 1)
end
f_leaf(n) = (i += 1)
foldup(root, f_leaf, f_inner, Int, labeling)
labeling
end

Expand Down