From 4796f69a78a6d986644c1c25a9b5d649b387edd6 Mon Sep 17 00:00:00 2001 From: Archivist Date: Thu, 2 Aug 2018 18:15:20 +0200 Subject: [PATCH] (Must fix) --- include/scatter/scatter.h | 56 +++++++++++++++++++++++---------- src/tests/StorageTree.tests.cpp | 6 ++++ 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/include/scatter/scatter.h b/include/scatter/scatter.h index 3b3a8f1..148cf35 100644 --- a/include/scatter/scatter.h +++ b/include/scatter/scatter.h @@ -6,6 +6,7 @@ static const scatter_key_t scatter_key_increment = ninefloat::Q<__int128,64>::mi #include #include #include +#include namespace StorageTree { @@ -47,13 +48,7 @@ namespace StorageTree { using datacenter = _impl::subdivision; using root = _impl::subdivision; - template - uint64_t total_weight(T& root) - { - return root.weight; - } - - template> + template uint64_t total_weight(T& root) { uint64_t ret=0; @@ -65,27 +60,56 @@ namespace StorageTree { return ret; } - template - scatter_key_t update_weights(T& root, uint64_t total, double sub_ratio=1, scatter_key_t begin=0, double ratio=0.5) + template<> + uint64_t total_weight(daemon& root) { - root.begin = begin; - root.end = begin+scatter_key_t(0.5)*((scatter_key_t(1/sub_ratio)*scatter_key_t(ratio)+scatter_key_t((double)root.weight/(double)total)*scatter_key_t(1-ratio))); - return root.end; + return root.weight; } - template> - scatter_key_t update_weights(T& root, uint64_t total, double sub_ratio=1, scatter_key_t begin=0, scatter_key_t ratio=0.5) + template + scatter_key_t update_weights(T& root, uint64_t total, double sub_ratio=1, scatter_key_t begin=0, double ratio=0.5) { + auto b = begin; for(auto& elem : root.content) { - begin = update_weights( + std::cout<<"UP"< + scatter_key_t update_weights(daemon& root, uint64_t total, double sub_ratio, scatter_key_t begin, double ratio) + { + root.begin = begin; + root.end = begin+scatter_key_t(0.5)*((scatter_key_t(1/sub_ratio)*scatter_key_t(ratio)+scatter_key_t((double)root.weight/(double)total)*scatter_key_t(1-ratio))); + std::cout<<"Starts: "<<(uint64_t)root.begin.data()<<" Ends: "<<(uint64_t)root.end.data()< + void add_rule(T& root, uint64_t weight, size_t idx, std::tuple Var) + { + if(idx + void add_rule(daemon& root, uint64_t weight,std::tuple<>) + { + root.weight=weight; + } } \ No newline at end of file diff --git a/src/tests/StorageTree.tests.cpp b/src/tests/StorageTree.tests.cpp index d279400..ce26d7f 100644 --- a/src/tests/StorageTree.tests.cpp +++ b/src/tests/StorageTree.tests.cpp @@ -1,8 +1,14 @@ #include "catch.hpp" #include "scatter/scatter.h" +#include TEST_CASE("Storage tree") { StorageTree::root n; + StorageTree::add_rule(n,25,0,0,0,0,0,0); + StorageTree::add_rule(n,25,0,0,0,1,0,0); + StorageTree::add_rule(n,25,0,0,0,1,0,1); + StorageTree::add_rule(n,25,0,0,0,1,0,2); + std::cout<<"Total weight="<(n)<(n)); } \ No newline at end of file