From 34f1b0da89d8739c59693df760dfc8ef598ff06a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 18 Nov 2023 19:28:16 +0100 Subject: [PATCH] Chain-Load: investigate ways for notation of topology rules While the Cap-Helper introduced yesterday was already a step in the right direction, I had considerable difficulties picking the correct parameters for the upper/lower bounds and the divisor for random generation so as to match an intended probability profile. Since this tool shall be used for load testing, an easier to handle notation will both help with focusing on the main tasks and later to document the test cases. Thus engaging (again) into the DSL building game... --- research/try.cpp | 153 +++++++++++++++++---------------------- wiki/thinkPad.ichthyo.mm | 33 +++++++++ 2 files changed, 101 insertions(+), 85 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index c4ca20f0f..85449245f 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -47,14 +47,16 @@ // 01/21 - look for ways to detect the presence of an (possibly inherited) getID() function // 08/22 - techniques to supply additional feature selectors to a constructor call // 10/23 - search for ways to detect signatures of member functions and functors uniformly +// 11/23 - prototype for a builder-DSL to configure a functor to draw and map random values /** @file try.cpp - * Investigate how to detect the signature of a _function-like member,_ irrespective - * if referring to a static function, a member function or a functor member. Turns out this - * can be achieved in a syntactically uniform way by passing either a pointer or member pointer. - * @see vault::gear::_verify_usable_as_ExecutionContext - * @see lib::meta::isFunMember + * Prototyping to find a suitable DSL to configure drawing of random numbers and mapping results. + * The underlying implementation shall be extracted from (and later used by) TestChainLoad; the + * random numbers will be derived from node hash values and must be mapped to yield parameters + * limited to a very small value range. While numerically simple, this turns out to be rather + * error-prone, hence the desire to put a DSL in front. The challenge however arises from + * the additional requirement to support various usage patters, all with minimal specs. */ typedef unsigned int uint; @@ -66,100 +68,81 @@ typedef unsigned int uint; #include "lib/util.hpp" #include "lib/meta/function.hpp" +#include -struct Stat +using std::function; + +template +struct Limited { - static long fun (double, char*) {return 42; } + static constexpr T min() { return T(0); } + static constexpr T max() { return max; } + + T val; + + template + Limited (X raw) + : val(util::limited (X(min()), raw, X(max()))) + { } }; -struct Funi +template +struct Spec { - std::function fun; - short gun; + using Lim = Limited; + static constexpr double CAP_EPSILON = 0.001; + + double lower{0}; + double upper{max}; + + Spec() = default; + + Lim + limited (double val) + { + if (val==lower) + return Lim{0}; + val -= lower; + val /= upper-lower; + val *= max; + val += CAP_EPSILON; + return Lim{val}; + } + }; -struct Dyna +template +struct Draw + : Spec + , function(size_t)> { - long fun (double, char*) const {return 42; } + using Spc = Spec; + using Lim = typename Spc::Lim; + using Fun = function; + + Draw() + : Spc{} + , Fun{[](size_t){ return Spc{}.limited(0); }} + { } + + template + Draw(FUN fun) + : Fun{fun} + { } }; - -using lib::meta::_Fun; - - - /** @deprecated this is effectively the same than using decltype */ - template - struct Probe - : _Fun

- { - Probe(P&&){} - }; - - template()> - struct has_SIGx - : std::is_same::Sig> - { -// has_SIGx() = default; -// has_SIGx(FUN, _Fun){ } - }; - - template - struct has_SIGx - : std::false_type - { -// has_SIGx() = default; -// has_SIGx(FUN, _Fun){ } - }; - - - - template - constexpr inline auto - isFunMember (FUN) - { - return has_SIGx{}; - } - -#define ARSERT_MEMBER_FUNCTOR(_EXPR_, _SIG_) \ - static_assert (isFunMember<_SIG_>(_EXPR_), \ - "Member " STRINGIFY(_EXPR_) " unsuitable, expect function signature: " STRINGIFY(_SIG_)); - int main (int, char**) { - using F1 = decltype(Stat::fun); - using F2 = decltype(Funi::fun); - using F3 = decltype(&Dyna::fun); + using D = Draw; + using L = typename D::Lim; + using S = typename D::Spc; + D draw; +SHOW_EXPR(draw) +SHOW_EXPR(draw(5).val) + draw = D{[](size_t i){ return S{}.limited(i); }}; - SHOW_TYPE(F1) - SHOW_TYPE(F2) - SHOW_TYPE(F3) - - using F1a = decltype(&Stat::fun); - using F2a = decltype(&Funi::fun); - using F2b = decltype(&Funi::gun); - SHOW_TYPE(F1a) - SHOW_TYPE(F2a) - SHOW_TYPE(F2b) - - SHOW_TYPE(_Fun::Sig) - SHOW_TYPE(_Fun::Sig) - SHOW_TYPE(_Fun::Sig) - - SHOW_TYPE(_Fun::Sig) - SHOW_TYPE(_Fun::Sig) - - SHOW_EXPR(_Fun::value) - SHOW_EXPR(_Fun::value) - cout << "\n--------\n"; - - SHOW_EXPR(bool(isFunMember(&Stat::fun))) - SHOW_EXPR(bool(isFunMember(&Funi::fun))) - SHOW_EXPR(bool(isFunMember(&Funi::gun))) - SHOW_EXPR(bool(isFunMember(&Dyna::fun))) - - ARSERT_MEMBER_FUNCTOR (&Stat::fun, long(double,char*)); - ARSERT_MEMBER_FUNCTOR (&Dyna::fun, long(double,char*)); +SHOW_EXPR(draw(5).val) cout << "\n.gulp.\n"; return 0; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 6d41cb14f..ba38e5350 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -96098,6 +96098,39 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + +

+ Cap ⟶ Ergebnis-Typ Draw +

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