Skip to content

Commit 3f8836b

Browse files
authored
Merge pull request #21 from cserteGT3/master
Add new function: allparents
2 parents c522748 + 91996e9 commit 3f8836b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/RegionTrees.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export Cell,
2222
initial_data,
2323
allcells,
2424
allleaves,
25+
allparents,
2526
adaptivesampling!
2627

2728
include("twosarray.jl")

src/cell.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ function allleaves(cell::Cell)
114114
end
115115
end
116116
end
117+
118+
function allparents(cell::Cell)
119+
Channel() do c
120+
queue = [cell]
121+
while !isempty(queue)
122+
current = pop!(queue)
123+
p = parent(current)
124+
if ! (p === nothing)
125+
put!(c, p)
126+
push!(queue, p)
127+
end
128+
end
129+
end
130+
end

test/cell.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@ end
3535
@test findleaf(cell, SVector(-0.01, -0.01, -0.01)) === cell[1,1,1]
3636
@test findleaf(cell, SVector(0.01, -0.01, -0.01)) === cell[2,1,1]
3737
end
38+
39+
@testset "find parents" begin
40+
cell2D = Cell(SVector(0., 0), SVector(1., 1))
41+
split!(cell2D)
42+
split!(cell2D[1,1])
43+
parents2D = [p for p in allparents(cell2D[1,1][1,2])]
44+
45+
@test parents2D[1] === cell2D[1,1]
46+
@test parents2D[2] === cell2D
47+
48+
cell3D = Cell(SVector(-1., -2, -3), SVector(2., 4, 6), 0)
49+
split!(cell3D)
50+
split!(cell3D[2,2,2])
51+
parents3D = [p for p in allparents(cell3D[2,2,2][1,1,1])]
52+
53+
@test parents3D[1] === cell3D[2,2,2]
54+
@test parents3D[2] === cell3D
55+
56+
noparents = [p for p in allparents(cell2D)]
57+
@test length(noparents) == 0
58+
end

0 commit comments

Comments
 (0)