|
@ -6,6 +6,7 @@ static const scatter_key_t scatter_key_increment = ninefloat::Q<__int128,64>::mi |
|
|
#include <vector> |
|
|
#include <vector> |
|
|
#include <numeric> |
|
|
#include <numeric> |
|
|
#include <type_traits> |
|
|
#include <type_traits> |
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
namespace StorageTree { |
|
|
namespace StorageTree { |
|
|
|
|
|
|
|
@ -47,13 +48,7 @@ namespace StorageTree { |
|
|
using datacenter = _impl::subdivision<room>; |
|
|
using datacenter = _impl::subdivision<room>; |
|
|
using root = _impl::subdivision<datacenter>; |
|
|
using root = _impl::subdivision<datacenter>; |
|
|
|
|
|
|
|
|
template<class T,class = void> |
|
|
|
|
|
uint64_t total_weight(T& root) |
|
|
|
|
|
{ |
|
|
|
|
|
return root.weight; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<class T,std::enable_if_t<T::divisible>> |
|
|
|
|
|
|
|
|
template<class T> |
|
|
uint64_t total_weight(T& root) |
|
|
uint64_t total_weight(T& root) |
|
|
{ |
|
|
{ |
|
|
uint64_t ret=0; |
|
|
uint64_t ret=0; |
|
@ -65,27 +60,56 @@ namespace StorageTree { |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template<n">class T, class = void> |
|
|
|
|
|
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>(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<class Tp">,std::enable_if_t<T::divisible>> |
|
|
|
|
|
scatter_key_t update_weights(T& root, uint64_t total, double sub_ratio=1, scatter_key_t begin=0, n">scatter_key_t ratio=0.5) |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
scatter_key_t update_weights(T& root, uint64_t total, double sub_ratio=1, scatter_key_t begin=0, kt">double ratio=0.5) |
|
|
{ |
|
|
{ |
|
|
|
|
|
auto b = begin; |
|
|
for(auto& elem : root.content) { |
|
|
for(auto& elem : root.content) { |
|
|
begin = update_weights( |
|
|
|
|
|
|
|
|
std::cout<<"UP"<<std::endl; |
|
|
|
|
|
b = update_weights( |
|
|
elem, |
|
|
elem, |
|
|
total, |
|
|
total, |
|
|
sub_ratio*root.content.size(), |
|
|
sub_ratio*root.content.size(), |
|
|
begin, |
|
|
|
|
|
|
|
|
b, |
|
|
ratio |
|
|
ratio |
|
|
)+scatter_key_increment; |
|
|
)+scatter_key_increment; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return begin; |
|
|
return begin; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
scatter_key_t update_weights<daemon>(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()<<std::endl; |
|
|
|
|
|
return root.end; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<class T, typename... Args> |
|
|
|
|
|
void add_rule(T& root, uint64_t weight, size_t idx, std::tuple<Args...> Var) |
|
|
|
|
|
{ |
|
|
|
|
|
if(idx<root.content.size()) |
|
|
|
|
|
add_rule(root.content.at(idx),weight,Var...); |
|
|
|
|
|
else if(idx==root.content.size()) |
|
|
|
|
|
{ |
|
|
|
|
|
root.content.emplace_back(); |
|
|
|
|
|
add_rule(root.content.at(idx),weight,Var...); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
throw std::runtime_error("libscatter: Bad rule, are you sure the order is right?"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
void add_rule<daemon,size_t>(daemon& root, uint64_t weight,std::tuple<>) |
|
|
|
|
|
{ |
|
|
|
|
|
root.weight=weight; |
|
|
|
|
|
} |
|
|
} |
|
|
} |