mirror of https://github.com/deavmi/niknaks
parent
04edc241ad
commit
ce78102af9
|
@ -666,27 +666,47 @@ public class Tree(T)
|
||||||
TouchStratergy!(T) touch = toDelegate(&Nothing!(T))
|
TouchStratergy!(T) touch = toDelegate(&Nothing!(T))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
writeln("dfs entry: ", this);
|
||||||
|
}
|
||||||
|
|
||||||
T[] collected;
|
T[] collected;
|
||||||
foreach(Tree!(T) child; this.children)
|
scope(exit)
|
||||||
|
{
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
writeln("leaving node ", this, " with collected ", collected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Touch
|
||||||
|
touch(this); // root[x]
|
||||||
|
|
||||||
|
foreach(Tree!(T) child; this.children) // subtree[x],
|
||||||
{
|
{
|
||||||
if(strat(child))
|
if(strat(child))
|
||||||
{
|
{
|
||||||
// Touch
|
version(unittest)
|
||||||
touch(child);
|
{
|
||||||
|
writeln("dfs, strat good for child: ", child);
|
||||||
|
}
|
||||||
|
|
||||||
// Visit
|
// Visit
|
||||||
collected ~= child.dfs(strat, touch);
|
collected ~= child.dfs(strat, touch);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
writeln("dfs, strat ignored for child: ", child);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strat(this))
|
// "Visit"
|
||||||
{
|
collected ~= this.value;
|
||||||
// Touch
|
|
||||||
touch(this);
|
|
||||||
|
|
||||||
// "Visit"
|
|
||||||
collected ~= this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return collected;
|
return collected;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue