Skip to content

Commit 5813d29

Browse files
committed
add filter_tree method + bug fixes
1 parent d0249f1 commit 5813d29

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/Geometry/Geometry.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using OrderedCollections
1414
using AbstractTrees
1515
using RecipesBase
1616
using Printf
17-
using Statistics: median
17+
using Statistics:median
1818

1919
using WavePropBase
2020
using WavePropBase.Utils
@@ -62,7 +62,6 @@ export
6262
new_tag,
6363
global_add_entity!,
6464
index_range,
65-
children,
6665
parent,
6766
container,
6867
loc2glob,

src/IO/plotsIO.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct PlotTree end
141141
grid --> false
142142
aspect_ratio --> :equal
143143
# plot nodes
144-
blocks = filter(predicate,tree)
144+
blocks = filter_tree(predicate,tree)
145145
for block in blocks
146146
@series begin
147147
block

src/Trees/Trees.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ export
3636
PrincipalComponentSplitter,
3737
DyadicSplitter,
3838
CardinalitySplitter,
39+
# re-exported from AbstractTrees
40+
Leaves,
41+
PreOrderDFS,
42+
PostOrderDFS,
43+
print_tree,
3944
# functions
4045
children,
4146
parent,
4247
isroot,
4348
isleaf,
49+
depth,
4450
container,
4551
loc2glob,
4652
root_elements,
47-
index_range
53+
index_range,
54+
filter_tree,
55+
filter_tree!
4856

4957
end # module

src/Trees/abstracttree.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
2020
The node's parent. If `t` is a root, then `parent(t)==t`.
2121
"""
22-
function parent(t::AbstractTree)
22+
function Base.parent(t::AbstractTree)
2323
abstractmethod(t)
2424
end
2525

@@ -58,29 +58,30 @@ function depth(tree::AbstractTree,acc=0)
5858
end
5959

6060
"""
61-
filter(filter,tree::AbstractTree,[isterminal=true])
61+
filter_tree(f,tree,isterminal=true)
6262
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`.
6566
"""
66-
function Base.filter(f,tree::AbstractTree,isterminal=true)
67+
function filter_tree(f,tree,isterminal=true)
6768
nodes = Vector{typeof(tree)}()
68-
filter!(f,nodes,tree,isterminal)
69+
filter_tree!(f,nodes,tree,isterminal)
6970
end
7071

7172
"""
72-
filter!(filter,nodes,tree,[isterminal=true])
73+
filter_tree!(filter,nodes,tree,[isterminal=true])
7374
74-
Like [`filter`](@ref), but appends results to `nodes`.
75+
Like [`filter_tree`](@ref), but appends results to `nodes`.
7576
"""
76-
function Base.filter!(f,nodes,tree::AbstractTree,isterminal=true)
77+
function filter_tree!(f,nodes,tree,isterminal=true)
7778
if f(tree)
7879
push!(nodes,tree)
7980
# 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))
8182
else
8283
# 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))
8485
end
8586
return nodes
8687
end

src/Trees/clustertree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ index_range(clt::ClusterTree) = clt.index_range
5151

5252
children(clt::ClusterTree) = clt.children
5353

54-
parent(clt::ClusterTree) = clt.parent
54+
Base.parent(clt::ClusterTree) = clt.parent
5555

5656
"""
5757
container(clt::ClusterTree)

0 commit comments

Comments
 (0)