ChainSearch: configure the core of the chained search mechanism

...based on a monadic tree expansion: we define a single step,
which takes the current filter configuration and builds the next
filter configuration, based on a stored chain of configuration functions

The actual exhausting depth-first results just by the greedy application pattern,
and uses the stack embedded in the "Explorer" layer of TreeExplorer
This commit is contained in:
Fischlurch 2018-09-07 16:17:35 +02:00
parent 2b72175e04
commit d923138d1c
3 changed files with 68 additions and 29 deletions

View file

@ -42,6 +42,7 @@
#include "lib/error.hpp"
#include "lib/iter-tree-explorer.hpp"
#include "lib/meta/util.hpp"
//#include <type_traits>
//#include <utility>
@ -57,6 +58,8 @@ namespace iter {
using std::forward;
using std::string;
using lib::meta::disable_if;
namespace { // type construction helpers...
@ -91,7 +94,7 @@ namespace iter {
{
using Filter = decltype( buildSearchFilter (std::declval<SRC>()) );
using StepFunctor = typename iter_explorer::_BoundFunctor<Filter(Filter const&), Filter>::Functor;
using StepFunctor = typename iter_explorer::_BoundFunctor<Filter(Filter const&), Filter const&>::Functor;
using Pipeline = decltype( buildExplorer (std::declval<SRC>(), std::declval<StepFunctor>()) );
};
@ -117,6 +120,7 @@ namespace iter {
using _Trait = _IterChainSetup<SRC>;
using _Base = typename _Trait::Pipeline;
using Value = typename _Base::value_type;
using Filter = typename _Trait::Filter;
using Step = typename _Trait::StepFunctor;
@ -141,18 +145,53 @@ namespace iter {
/** */
IterChainSearch&&
search (string target)
/** configure additional chained search condition.
* @param a functor `Filter const& -> filter`, which takes a current filter configuration,
* returning a copy from this configuration, possibly configured differently.
* @note the given functor, lambda or function reference will be wrapped and adapted
* to conform to the required function signature. When using a generic lambda,
* the argument type `Filter const&` is assumed
* @remarks the additional chained search condition given here will be applied _after_
* matching all other conditions already in the filter chain. Each such condition
* is used to _filter_ the underlying source iterator, i.e. pull it until finding
* and element to match the condition. Basically these conditions are _not_ used in
* conjunction, but rather one after another. But since each such step in the chain
* is defined by a functor, which gets the previous filter configuration as argument,
* it is _possible_ to build a step which _extends_ or sharpens the preceding condition.
*/
template<typename FUN>
disable_if<is_convertible<FUN, Value>,
IterChainSearch&& >
search (FUN&& configureSearchStep)
{
TODO ("configure additional chained search condition");
stepChain_.emplace_back (Step{forward<FUN> (configureSearchStep)});
return move(*this);
}
/** attach additional direct search for a given value.
* After successfully searching for all the conditions currently in the filter chain,
* the underlying iterator will finally be pulled until matching the given target value.
*/
IterChainSearch&&
search (Value target)
{
search ([=](Filter filter) // note: filter taken by value
{
filter.setNewFilter ([target](Value const& currVal) { return currVal == target; });
return filter; // return copy of the original state with changed filter
});
return move(*this);
}
/** drop all search condition frames.
* @remark the filter chain becomes empty,
* passing through the unaltered
* source sequence
*/
IterChainSearch&&
clearFilter()
{
UNIMPLEMENTED ("drop all search condition frames");
stepChain_.clear();
return move(*this);
}
@ -160,8 +199,11 @@ namespace iter {
Filter
configureFilterChain (Filter const& currentFilterState)
{
uint depth = this->depth();
return Filter{}; /////TODO empty filter means recursion end
uint depth = currentFilterState.depth();
if (depth < stepChain_.size())
return stepChain_[depth](currentFilterState); // augmented copy
else
return Filter{}; // empty filter indicates recursion end
}
};

View file

@ -111,14 +111,11 @@ namespace test{
///////////////////////////////////////////////////TODO WIP
using Searcher = decltype(search);
SHOW_TYPE (Searcher);
SHOW_TYPE (Searcher::DebugPipeline);
SHOW_TYPE (Searcher::value_type);
SHOW_TYPE (Searcher::pointer);
// TypeDebugger<Searcher::reference> guggi; // --> std::__cxx11::basic_string<char> const&
cout << "search[0]=" <<*search<<endl;
++search;
cout << "search[1]=" <<*search<<endl;
///////////////////////////////////////////////////TODO WIP
CHECK (search);
CHECK (not isnil(search));

View file

@ -31196,15 +31196,15 @@
<node CREATED="1536018293535" ID="ID_361886715" MODIFIED="1536018315757" TEXT="Abk&#xfc;rzung f&#xfc;r direkten Wert-equality-Match"/>
<node CREATED="1536018276593" ID="ID_1222260775" MODIFIED="1536018287299" TEXT="prekonfigurierte Builder-Funktionen f&#xfc;r Standardf&#xe4;lle"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018364845" ID="ID_1351452920" MODIFIED="1536018457506" TEXT="Implementierung">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018375244" ID="ID_1906913554" MODIFIED="1536018458786" TEXT="Kern: Explore-Mechanismus">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018644456" ID="ID_477475522" MODIFIED="1536018654007" TEXT="Signatur der Explore-Funktion festlegen">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018364845" ID="ID_1351452920" MODIFIED="1536329770737" TEXT="Implementierung">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018375244" ID="ID_1906913554" MODIFIED="1536329750864" TEXT="Kern: Explore-Mechanismus">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1536018644456" ID="ID_477475522" MODIFIED="1536329729458" TEXT="Signatur der Explore-Funktion festlegen">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018705511" ID="ID_1131109871" MODIFIED="1536018800891" TEXT="greedy Tiefensuche">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1536018705511" ID="ID_1131109871" MODIFIED="1536329731179" TEXT="greedy Tiefensuche">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018802738" ID="ID_1560348563" MODIFIED="1536018807506" TEXT="Abbruchbedingung">
<icon BUILTIN="flag-yellow"/>
@ -31215,9 +31215,9 @@
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018862802" ID="ID_1044555993" MODIFIED="1536326576841" TEXT="abgeleiteten Frame konstruieren">
<node COLOR="#338800" CREATED="1536018862802" ID="ID_1044555993" MODIFIED="1536329736419" TEXT="abgeleiteten Frame konstruieren">
<linktarget COLOR="#65a7b1" DESTINATION="ID_1044555993" ENDARROW="Default" ENDINCLINATION="70;92;" ID="Arrow_ID_575633930" SOURCE="ID_1532889609" STARTARROW="None" STARTINCLINATION="149;-3;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node COLOR="#338800" CREATED="1536018406232" ID="ID_1330264339" MODIFIED="1536326484790" TEXT="Schritte als Funktoren">
@ -31456,14 +31456,14 @@
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018442123" ID="ID_829730232" MODIFIED="1536018463121" TEXT="Abk&#xfc;rzung f&#xfc;r direkten Match">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018985450" ID="ID_1700266521" MODIFIED="1536019004173" TEXT="Wert-Typ deduzieren">
<node COLOR="#338800" CREATED="1536018442123" ID="ID_829730232" MODIFIED="1536329759111" TEXT="Abk&#xfc;rzung f&#xfc;r direkten Match">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1536018985450" ID="ID_1700266521" MODIFIED="1536329755895" TEXT="Wert-Typ deduzieren">
<arrowlink DESTINATION="ID_1619721301" ENDARROW="Default" ENDINCLINATION="129;0;" ID="Arrow_ID_1721152439" STARTARROW="None" STARTINCLINATION="76;-5;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536019008151" ID="ID_29813547" MODIFIED="1536019026064" TEXT="equality comparision in Lambda">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1536019008151" ID="ID_29813547" MODIFIED="1536329757422" TEXT="equality comparision in Lambda">
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018471975" ID="ID_1115030606" MODIFIED="1536018481902" TEXT="Variante f&#xfc;r bidirektionale Suche">
@ -31484,8 +31484,8 @@
<icon BUILTIN="idea"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018539621" ID="ID_1857591081" MODIFIED="1536018556917" TEXT="simpleSearch()">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018539621" ID="ID_1857591081" MODIFIED="1536329779734" TEXT="simpleSearch()">
<icon BUILTIN="pencil"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536018544936" ID="ID_1750921303" MODIFIED="1536018557580" TEXT="chainedIteration()">
<icon BUILTIN="flag-yellow"/>