TreeExplorer: draft the filter operation
should be low hanging fruit now....
This commit is contained in:
parent
085b304a38
commit
2eacde7f2c
3 changed files with 121 additions and 6 deletions
|
|
@ -644,6 +644,80 @@ namespace lib {
|
|||
return *treated_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @internal Decorator for TreeExplorer to filter elements based on a predicate.
|
||||
*
|
||||
* @todo WIP 12/17 implement filter
|
||||
*/
|
||||
template<class SRC, class FUN>
|
||||
class Filter
|
||||
: public SRC
|
||||
{
|
||||
static_assert(can_IterForEach<SRC>::value, "Lumiera Iterator required as source");
|
||||
using _Traits = _BoundFunctorTraits<FUN,SRC>;
|
||||
using Res = typename _Traits::Res;
|
||||
static_assert(std::is_constructible<bool, Res>::value, "Functor must be a predicate");
|
||||
|
||||
using FilterPredicate = typename _Traits::Functor;
|
||||
|
||||
FilterPredicate trafo_;
|
||||
|
||||
public:
|
||||
|
||||
Filter() =default;
|
||||
// inherited default copy operations
|
||||
|
||||
Filter (SRC&& dataSrc, FUN&& filterFun)
|
||||
: SRC{move (dataSrc)}
|
||||
, trafo_{forward<FUN> (filterFun)}
|
||||
{ }
|
||||
|
||||
|
||||
/** refresh state when other layers manipulate the source sequence */
|
||||
void
|
||||
expandChildren()
|
||||
{
|
||||
//////////////////////TODO trigger re-evaluation here...
|
||||
SRC::expandChildren();
|
||||
}
|
||||
|
||||
public: /* === Iteration control API for IterableDecorator === */
|
||||
|
||||
bool
|
||||
checkPoint() const
|
||||
{
|
||||
return false; //////////////TODO filter and pull here...
|
||||
}
|
||||
|
||||
typename SRC::reference
|
||||
yield() const
|
||||
{
|
||||
return *(*this);
|
||||
}
|
||||
|
||||
void
|
||||
iterNext()
|
||||
{
|
||||
++ srcIter();
|
||||
}
|
||||
|
||||
private:
|
||||
SRC&
|
||||
srcIter() const
|
||||
{
|
||||
return unConst(*this);
|
||||
}
|
||||
|
||||
bool
|
||||
pullFilter ()
|
||||
{
|
||||
////////////////////////TODO while-not-filter iter
|
||||
return false; //////////TODO return true if any result??
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -742,6 +816,20 @@ namespace lib {
|
|||
return TreeExplorer<ResIter> (ResCore {move(*this), forward<FUN>(transformFunctor)});
|
||||
}
|
||||
|
||||
|
||||
/** @todo implement filter
|
||||
*/
|
||||
template<class FUN>
|
||||
auto
|
||||
filter (FUN&& filterPredicate)
|
||||
{
|
||||
using ResCore = iter_explorer::Filter<SRC, FUN>;
|
||||
using ResIter = typename _DecoratorTraits<ResCore>::SrcIter;
|
||||
|
||||
return TreeExplorer<ResIter> (ResCore {move(*this), forward<FUN>(filterPredicate)});
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -625,7 +625,10 @@ namespace test{
|
|||
void
|
||||
verify_FilterIterator()
|
||||
{
|
||||
UNIMPLEMENTED("preconfigured repeated depth-first expansion");
|
||||
cout << materialise (
|
||||
treeExplore(CountDown{10})
|
||||
.filter([](uint j){ return j % 2; })
|
||||
) << endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -635,7 +638,7 @@ namespace test{
|
|||
void
|
||||
verify_asIterSource()
|
||||
{
|
||||
UNIMPLEMENTED("preconfigured repeated depth-first expansion");
|
||||
UNIMPLEMENTED("package as IterSource");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5691,8 +5691,8 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511837279715" ID="ID_1694539348" MODIFIED="1511837456610" TEXT="filter-Operation">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511837279715" ID="ID_1694539348" MODIFIED="1512523928755" TEXT="filter-Operation">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1511837285306" ID="ID_928417859" MODIFIED="1511837293629" TEXT="der Vollständigkeit halber">
|
||||
<node CREATED="1511837296921" ID="ID_151298846" MODIFIED="1511837304547" TEXT="ist zwar redundant zu den Itertools"/>
|
||||
<node CREATED="1511837305410" ID="ID_1979322634" MODIFIED="1511837324464" TEXT="treeExplorer könnte Itertools ablösen">
|
||||
|
|
@ -5700,10 +5700,19 @@
|
|||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1511837329140" ID="ID_1963360740" MODIFIED="1511837374658" TEXT="sollte billig zu implementieren sein">
|
||||
<node COLOR="#338800" CREATED="1511837329140" ID="ID_1963360740" MODIFIED="1512523888392" TEXT="billige Implementierung nach Schema-F">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1511837338643" ID="ID_1734683995" MODIFIED="1511837344590" TEXT="bestehende Dekorator-Technik"/>
|
||||
<node CREATED="1511837345226" ID="ID_991593174" MODIFIED="1511837351797" TEXT="bestehende Funktor-Argument-Traits"/>
|
||||
</node>
|
||||
<node CREATED="1512523892775" ID="ID_673112014" MODIFIED="1512523896362" TEXT="Knackpunkte">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523897422" ID="ID_1007287631" MODIFIED="1512523916092" TEXT="pullFilter">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node CREATED="1512523905005" ID="ID_1286045611" MODIFIED="1512523921543" TEXT="wie "ausgewertet" merken?">
|
||||
<icon BUILTIN="help"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512363846804" ID="ID_1346062807" MODIFIED="1512363878326" TEXT="auto-expand">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
|
|
@ -6276,9 +6285,24 @@
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511836579562" ID="ID_1718741335" MODIFIED="1511836583779" TEXT="verify_FilterIterator();">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511836579562" ID="ID_1718741335" MODIFIED="1512523829719" TEXT="verify_FilterIterator();">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523719350" ID="ID_351021178" MODIFIED="1512523742972" TEXT="einfaches Prädikat">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523726885" ID="ID_282579718" MODIFIED="1512523741403" TEXT="konsumieren bis leer">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523773559" ID="ID_917494688" MODIFIED="1512523798076" TEXT="Prädikat<Core>">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523783318" ID="ID_1808219280" MODIFIED="1512523797205" TEXT="Prädikat<Iter> (generisch)">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512523810946" ID="ID_461047497" MODIFIED="1512523821311" TEXT="ggfs mit expand()">
|
||||
<icon BUILTIN="help"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511836589393" ID="ID_54165230" MODIFIED="1511836592073" TEXT="verify_asIterSource();">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue