Skip to content

Commit 05a695c

Browse files
committed
Move count_nodes back to EquationUtils.jl
1 parent a2b4dcf commit 05a695c

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/EquationUtils.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ import ..EquationModule:
1818
1919
Count the number of nodes in the tree.
2020
"""
21-
count_nodes
21+
function count_nodes(tree::AbstractNode; break_sharing=Val(false))
22+
return tree_mapreduce(
23+
_ -> 1,
24+
+,
25+
tree,
26+
Int64;
27+
f_on_shared=(c, is_shared) -> is_shared ? 0 : c,
28+
break_sharing,
29+
)
30+
end
2231

2332
"""
2433
count_depth(tree::AbstractNode)::Int

src/base.jl

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ end
128128
function allocate_id_map(tree::AbstractNode, ::Type{RT}) where {RT}
129129
d = Dict{UInt,RT}()
130130
# Preallocate maximum storage (counting with duplicates is fast)
131-
N = count_nodes(tree; break_sharing=Val(true))
131+
N = length(tree; break_sharing=Val(true))
132132
sizehint!(d, N)
133133
return d
134134
end
@@ -318,17 +318,6 @@ function count(
318318
) + init
319319
end
320320

321-
function count_nodes(tree::AbstractNode; break_sharing=Val(false))
322-
return tree_mapreduce(
323-
_ -> 1,
324-
+,
325-
tree,
326-
Int64;
327-
f_on_shared=(c, is_shared) -> is_shared ? 0 : c,
328-
break_sharing,
329-
)
330-
end
331-
332321
function sum(
333322
f::F,
334323
tree::AbstractNode;

0 commit comments

Comments
 (0)