소스 검색

(Must fix)

master
Archivist 6 년 전
부모
커밋
4796f69a78
2개의 변경된 파일46개의 추가작업 그리고 16개의 파일을 삭제
  1. +40
    -16
      include/scatter/scatter.h
  2. +6
    -0
      src/tests/StorageTree.tests.cpp

+ 40
- 16
include/scatter/scatter.h 파일 보기

@ -6,6 +6,7 @@ static const scatter_key_t scatter_key_increment = ninefloat::Q<__int128,64>::mi
#include <vector>
#include <numeric>
#include <type_traits>
#include <iostream>
namespace StorageTree {
@ -47,13 +48,7 @@ namespace StorageTree {
using datacenter = _impl::subdivision<room>;
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 ret=0;
@ -65,27 +60,56 @@ namespace StorageTree {
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) {
begin = update_weights(
std::cout<<"UP"<<std::endl;
b = update_weights(
elem,
total,
sub_ratio*root.content.size(),
begin,
b,
ratio
)+scatter_key_increment;
}
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;
}
}

+ 6
- 0
src/tests/StorageTree.tests.cpp 파일 보기

@ -1,8 +1,14 @@
#include "catch.hpp"
#include "scatter/scatter.h"
#include <iostream>
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="<<StorageTree::total_weight<StorageTree::root>(n)<<std::endl;
StorageTree::update_weights(n,StorageTree::total_weight<StorageTree::root>(n));
}

불러오는 중...
취소
저장