From ce78102af9943e823095f89fb717149eb1c6fea7 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 23 Apr 2024 16:02:40 +0200 Subject: [PATCH] Tree - Correct visitation stratergy --- source/niknaks/containers.d | 42 +++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/source/niknaks/containers.d b/source/niknaks/containers.d index 7d7eee8..20b128f 100644 --- a/source/niknaks/containers.d +++ b/source/niknaks/containers.d @@ -666,27 +666,47 @@ public class Tree(T) TouchStratergy!(T) touch = toDelegate(&Nothing!(T)) ) { + version(unittest) + { + writeln("dfs entry: ", this); + } + 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)) { - // Touch - touch(child); + version(unittest) + { + writeln("dfs, strat good for child: ", child); + } // Visit collected ~= child.dfs(strat, touch); } + else + { + version(unittest) + { + writeln("dfs, strat ignored for child: ", child); + } + } } - if(strat(this)) - { - // Touch - touch(this); - - // "Visit" - collected ~= this.value; - } + // "Visit" + collected ~= this.value; + return collected; }