From fd5d44f6ca02373fdadce44ae55855d34cd9c78c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 9 Dec 2017 19:42:22 +0100 Subject: [PATCH] TreeExplorer: draft next case -- auto-expand children this leads to either unfolding the full tree depth-first, or, when expanding eagerly, to delve into each sub-branch down to the leaf nodes Both patterns should be simple to implement on top of what we've built already... --- src/lib/iter-tree-explorer.hpp | 20 +++++++ tests/library/iter-tree-explorer-test.cpp | 30 ++++++++++- wiki/thinkPad.ichthyo.mm | 63 +++++++++++++++++++++-- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index ea5aa4334..20e036cc1 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -963,6 +963,26 @@ namespace lib { } + /** @todo WIP 12/17 auto expand all + */ + auto + expandAll() + { + UNIMPLEMENTED ("automatically expand all elements"); + return *this; + } + + + /** @todo WIP 12/17 auto expand down to the leafs + */ + auto + expandLeaf() + { + UNIMPLEMENTED ("depth-first expand immediately, until reaching the leaf elements"); + return *this; + } + + /** adapt this TreeExplorer to pipe each result value through a transformation function. * Several "layers" of mapping can be piled on top of each other, possibly mixed with the * other types of adaptation, like the child-expanding operation, or a filter. Obviously, diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index b1158da43..1ab5ef475 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -59,6 +59,7 @@ #include "lib/format-string.hpp" #include "lib/format-cout.hpp" #include "lib/format-util.hpp" +#include "lib/itertools.hpp" #include "lib/util.hpp" #include "lib/iter-tree-explorer.hpp" @@ -67,6 +68,7 @@ #include #include #include +#include namespace lib { @@ -805,7 +807,33 @@ namespace test{ void verify_depthFirstExploration() { - UNIMPLEMENTED("preconfigured repeated depth-first expansion"); + cout << materialise( + treeExplore(CountDown{4}) + .expand([](uint j){ return CountDown{j-1}; }) + .expandAll() + .transform([](int i){ return i*10; }) + ) <; + auto summingExpander = [](Tu2 const& tup) + { + uint val = get<0>(tup); + uint sum = get<1>(tup); + return singleValIterator (Tu2{val-1, sum+val}); + }; + +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #888 + cout << materialise( + treeExplore(CountDown{4}) + .transform([](uint i){ return Tu2{i,0}; }) +// .expand(summingExpander) //////////////////TODO why isn't that result iterator (singleValIterator) accepted? It should be + .expandLeaf() + .transform([](Tu2 res){ return get<1>(res); }) + ) < - - + + + + + + + + +

+ ...nur was billig ist, +

+

+ denn im Moment brauchen wir das überhaupt nicht +

+ + +
+ +
+ + + + + + +

+ ...setzt eigentliche Expand-Operation darunter voraus +

+ + +
+ +
+ + + + + + + + + + + + + + + + + @@ -6718,9 +6766,18 @@ - + + + + + + + + + +