From 7bc2c80d3adbe33c27a9dfdacb3b4c608943866b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 11 Nov 2023 23:55:11 +0100 Subject: [PATCH] Chain-Load: calculation node - basic properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A »Node« represents one junction point in the dependency graph, knows his predecessors and successors and carries out one step of the chained hash calculation. --- tests/vault/gear/test-chain-load-test.cpp | 60 +++++++++++++++++++++-- tests/vault/gear/test-chain-load.hpp | 55 ++++++++++++++++++++- wiki/thinkPad.ichthyo.mm | 45 ++++++++++++++--- 3 files changed, 149 insertions(+), 11 deletions(-) diff --git a/tests/vault/gear/test-chain-load-test.cpp b/tests/vault/gear/test-chain-load-test.cpp index 13df1286c..086a1244d 100644 --- a/tests/vault/gear/test-chain-load-test.cpp +++ b/tests/vault/gear/test-chain-load-test.cpp @@ -32,13 +32,13 @@ //#include "lib/time/timevalue.hpp" //#include "lib/format-cout.hpp" #include "lib/test/diagnostic-output.hpp"//////////////////////////TODO TOD-oh -//#include "lib/util.hpp" +#include "lib/util.hpp" //using lib::time::Time; //using lib::time::FSecs; -//using util::isSameObject; +using util::isSameObject; //using lib::test::randStr; //using lib::test::randTime; @@ -85,12 +85,64 @@ namespace test { { using Node = TestChainLoad<>::Node; - Node n0; + Node n0; // Default-created empty Node CHECK (n0.hash == 0); + CHECK (n0.pred.size() == DEFAULT_FAN); + CHECK (n0.succ.size() == DEFAULT_FAN); + CHECK (n0.pred == Node::Tab{0}); + CHECK (n0.succ == Node::Tab{0}); - Node n1{23}, n2{55}; + Node n1{23}, n2{55}; // further Nodes with initial seed hash CHECK (n1.hash == 23); CHECK (n2.hash == 55); + + CHECK (0 == n0.calculate()); // hash calculation is NOP on unconnected Nodes + CHECK (0 == n0.hash); + CHECK (23 == n1.calculate()); + CHECK (23 == n1.hash); + CHECK (55 == n2.calculate()); + CHECK (55 == n2.hash); + + n0.addPred(n1); // establish bidirectional link between Nodes + CHECK (isSameObject(*n0.pred[0], n1)); + CHECK (isSameObject(*n1.succ[0], n0)); + CHECK (not n0.pred[1]); + CHECK (not n1.succ[1]); + CHECK (n2.pred == Node::Tab{0}); + CHECK (n2.succ == Node::Tab{0}); + + n2.addSucc(n0); // works likewise in the other direction + CHECK (isSameObject(*n0.pred[0], n1)); + CHECK (isSameObject(*n0.pred[1], n2)); // next link added into next free slot + CHECK (isSameObject(*n2.succ[0], n0)); + CHECK (not n0.pred[2]); + CHECK (not n2.succ[1]); + + CHECK (n0.hash == 0); + n0.calculate(); // but now hash calculation combines predecessors + CHECK (n0.hash == 6050854883719206282u); + + Node n00; // another Node... + n00.addPred(n2) // just adding the predecessors in reversed order + .addPred(n1); + + CHECK (n00.hash == 0); + n00.calculate(); // ==> hash is different, since it depends on order + CHECK (n00.hash == 17052526497278249714u); + CHECK (n0.hash == 6050854883719206282u); + + CHECK (isSameObject(*n1.succ[0], n0)); + CHECK (isSameObject(*n1.succ[1], n00)); + CHECK (isSameObject(*n2.succ[0], n0)); + CHECK (isSameObject(*n2.succ[1], n00)); + CHECK (isSameObject(*n00.pred[0], n2)); + CHECK (isSameObject(*n00.pred[1], n1)); + CHECK (isSameObject(*n0.pred[0], n1)); + CHECK (isSameObject(*n0.pred[1], n2)); + + CHECK (n00.hash == 17052526497278249714u); + n00.calculate(); // calculation is NOT idempotent (inherently statefull) + CHECK (n00.hash == 13151338213516862912u); } diff --git a/tests/vault/gear/test-chain-load.hpp b/tests/vault/gear/test-chain-load.hpp index 533c9348a..b9dd9c770 100644 --- a/tests/vault/gear/test-chain-load.hpp +++ b/tests/vault/gear/test-chain-load.hpp @@ -58,6 +58,7 @@ //#include "lib/format-util.hpp" //#include "lib/util.hpp" +#include //#include //#include //#include @@ -81,11 +82,14 @@ namespace test { // using util::isnil; // using std::forward; // using std::move; + using boost::hash_combine; namespace {// Diagnostic markers // const string MARK_INC{"IncSeq"}; // const string MARK_SEQ{"Seq"}; + const size_t DEFAULT_FAN = 16; + const size_t DEFAULT_SIZ = 256; // using SIG_JobDiagnostic = void(Time, int32_t); } @@ -97,7 +101,7 @@ namespace test { * @tparam maxFan maximal fan-in/out from a node, also limits maximal parallel strands. * @see TestChainLoad_test */ - template + template class TestChainLoad : util::NonCopyable { @@ -106,11 +110,60 @@ namespace test { struct Node : util::MoveOnly { + using Tab = std::array; + size_t hash; + Tab pred; + Tab succ; Node(size_t seed =0) : hash{seed} + , pred{0} + , succ{0} { } + + Node& + addPred (Node& other) + { + for (Node*& entry : pred) + if (not entry) + { + entry = &other; + for (Node*& backlink : other.succ) + if (not backlink) + { + backlink = this; + return *this; + } + } + NOTREACHED ("excess node linkage"); + } + + Node& + addSucc (Node& other) + { + for (Node*& entry : succ) + if (not entry) + { + entry = &other; + for (Node*& backlink : other.pred) + if (not backlink) + { + backlink = this; + return *this; + } + } + NOTREACHED ("excess node linkage"); + } + + size_t + calculate() + { + for (Node*& entry: pred) + if (entry) + hash_combine (hash, entry->hash); + return hash; + } }; private: diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 41e3b7826..53be081a8 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -95855,11 +95855,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + - - + + @@ -95883,12 +95883,45 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + + + + + +

+ Konsequenz ⟹ nicht idempotent +

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