Skip to content

Commit 82a1605

Browse files
author
Alessandro
committed
added node_count. version bump
1 parent 54a3aab commit 82a1605

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TermInterface"
22
uuid = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
33
authors = ["Shashi Gowda <gowda@mit.edu>", "Alessandro Cheli <sudo-woodo3@protonmail.com>"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[compat]
77
julia = "1"

src/utils.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ Returns a single argument anonymous function predicate, that returns `true` if a
55
the argument to the predicate satisfies `isterm` and `gethead(x) == f`
66
"""
77
is_operation(f) = @nospecialize(x) -> isterm(x) && (gethead(x) == f)
8-
export is_operation
8+
export is_operation
9+
10+
11+
"""
12+
node_count(t)
13+
Count the nodes in a symbolic expression tree satisfying `isterm` and `getargs`.
14+
"""
15+
node_count(t) = isterm(t) ? reduce(+, node_count(x) for x in getargs(t), init=0) + 1 : 1

0 commit comments

Comments
 (0)