- Correct visitation stratergy
This commit is contained in:
Tristan B. Velloza Kildaire 2024-04-23 16:02:40 +02:00
parent 04edc241ad
commit ce78102af9
1 changed files with 31 additions and 11 deletions

View File

@ -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;
} }