|
19 | 19 |
|
20 | 20 | The node's parent. If `t` is a root, then `parent(t)==t`. |
21 | 21 | """ |
22 | | -function parent(t::AbstractTree) |
| 22 | +function Base.parent(t::AbstractTree) |
23 | 23 | abstractmethod(t) |
24 | 24 | end |
25 | 25 |
|
@@ -58,29 +58,30 @@ function depth(tree::AbstractTree,acc=0) |
58 | 58 | end |
59 | 59 |
|
60 | 60 | """ |
61 | | - filter(filter,tree::AbstractTree,[isterminal=true]) |
| 61 | + filter_tree(f,tree,isterminal=true) |
62 | 62 |
|
63 | | -Return all the nodes of `tree` satisfying `filter(node)==true`. If |
64 | | -`isterminal`, do not recurse on children of nodes for which `filter(node)==true`. |
| 63 | +Return a vector containing all the nodes of `tree` such that |
| 64 | +`filter(node)==true`. The argument `isterminal` can be used to control whether |
| 65 | +to continue the search on `children` of nodes for which `f(node)==true`. |
65 | 66 | """ |
66 | | -function Base.filter(f,tree::AbstractTree,isterminal=true) |
| 67 | +function filter_tree(f,tree,isterminal=true) |
67 | 68 | nodes = Vector{typeof(tree)}() |
68 | | - filter!(f,nodes,tree,isterminal) |
| 69 | + filter_tree!(f,nodes,tree,isterminal) |
69 | 70 | end |
70 | 71 |
|
71 | 72 | """ |
72 | | - filter!(filter,nodes,tree,[isterminal=true]) |
| 73 | + filter_tree!(filter,nodes,tree,[isterminal=true]) |
73 | 74 |
|
74 | | -Like [`filter`](@ref), but appends results to `nodes`. |
| 75 | +Like [`filter_tree`](@ref), but appends results to `nodes`. |
75 | 76 | """ |
76 | | -function Base.filter!(f,nodes,tree::AbstractTree,isterminal=true) |
| 77 | +function filter_tree!(f,nodes,tree,isterminal=true) |
77 | 78 | if f(tree) |
78 | 79 | push!(nodes,tree) |
79 | 80 | # terminate the search along this path if terminal=true |
80 | | - isterminal || map(x->filter!(f,nodes,x,isterminal),getchildren(tree)) |
| 81 | + isterminal || map(x->filter_tree!(f,nodes,x,isterminal),children(tree)) |
81 | 82 | else |
82 | 83 | # continue on on children |
83 | | - map(x->filter!(f,nodes,x,isterminal),tree.children) |
| 84 | + map(x->filter_tree!(f,nodes,x,isterminal),children(tree)) |
84 | 85 | end |
85 | 86 | return nodes |
86 | 87 | end |
|
0 commit comments