Browse Source

Planned changed over weights updating

master
Archivist 5 years ago
parent
commit
6d6088c0bf
3 changed files with 37 additions and 27 deletions
  1. +3
    -3
      Makefile
  2. +27
    -24
      include/scatter/scatter.h
  3. +7
    -0
      src/tests.cpp

+ 3
- 3
Makefile View File

@ -19,8 +19,8 @@
#
CXX := -g++-7
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -O0 -std=c++14 -fPIC -DUSE_CATCH
CXX := -g++-8
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -O0 -std=c++2a -fPIC -DUSE_CATCH
# -DCOMPAT_TLS
# ^ Enable this flag if your compiler ABI have issues with thread local storage
LDFLAGS := -L/usr/lib -lstdc++ -lm -lpthread
@ -28,7 +28,7 @@ BUILD := build
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/apps
TARGET := tests.cpp
INCLUDE := -Iinclude/
INCLUDE := -Iinclude/ -I9float/include
SRC := \
OBJECTS := $(SRC:%.cpp=$(OBJ_DIR)/%.o)

+ 27
- 24
include/scatter/scatter.h View File

@ -1,14 +1,10 @@
#pragma once
#include <stdint.h>
#ifdef COMPILE_TIME
#include "9float.hpp"
using scatter_key_t = ninefloat::Q<uint64_t,64>;
static const scatter_key_t scatter_key_increment = ninefloat::Q<uint64_t,64>::min_increment();
#else
using scatter_key_t = uint64_t;
static const scatter_key_t scatter_key_increment = 1;
#endif
#include "9float.hpp"
using scatter_key_t = ninefloat::Q<uint64_t,64>;
static const scatter_key_t scatter_key_increment = ninefloat::Q<uint64_t,64>::min_increment();
#include <vector>
#include <numeric>
namespace StorageTree{
@ -35,7 +31,7 @@ namespace StorageTree{
constexpr T max(T any = 0)
{
if(any>any+scatter_key_increment)
return any
return any;
return max(any+scatter_key_increment);
}
}
@ -50,26 +46,33 @@ namespace StorageTree{
using root = _impl::subdivision<datacenter>;
template<class T, std::enable_if_t<T::divisible>>
kt">void update_weights(T& root, uint64_t sub_ratio=1, scatter_key_t begin=0, scatter_key_t end=_impl::max<scatter_key_t>())
n">uint64_t total_weight(T& root)
{
scatter_key_t address_space = end-begin;
scatter_key_t base = begin
for(int idx=0:idx<root.content.size();idx++)
{
auto& elem = root.content[idx];
if(idx!=root.content.size()-1)
return std::reduce(
root.content.begin(),
root.content.end(),
0UL,
[](auto val, uint64_t acc)
{
update_weights(elem, root.content.size()*sub_ratio, base, base+address_space/root.content.size());
base = base+address_space/root.content.size()+scatter_key_increment;
return acc+total_weight(val);
}
else
update_weights(elem, root.content.size()*sub_ratio, base, end);
}
);
}
template<class T, std::enable_if_t<!T::divisible>>
uint64_t total_weight(T& root)
{
return root.weight;
}
template<class T, std::enable_if_t<T::divisible>>
scatter_key_t update_weights(T& root, uint64_t sub_ratio=1, uint64_t total, scatter_key_t begin=0, scatter_key_t ratio=0.5)
{
}
template<class T, std::enable_if_t<!T::divisible>>
void update_weights(T& root, scatter_key_t begin, scatter_key_t end)
n">scatter_key_t update_weights(T& root, uint64_t sub_ratio=1, uint64_t total, scatter_key_t begin, scatter_key_t end)
{
this->begin = begin;
this->end = end;

+ 7
- 0
src/tests.cpp View File

@ -0,0 +1,7 @@
#include "scatter/scatter.h"
int main()
{
StorageTree::root n;
StorageTree::update_weights(n,1,StorageTree::total_weight(T& root));
}

Loading…
Cancel
Save