소스 검색

Added ratio support

master
Archivist 6 년 전
부모
커밋
04e18f8768
7개의 변경된 파일11063개의 추가작업 그리고 9108개의 파일을 삭제
  1. +2
    -0
      .gitignore
  2. +1
    -1
      9float
  3. +10
    -4
      Makefile
  4. +10964
    -9031
      include/catch.hpp
  5. +76
    -65
      include/scatter/scatter.h
  6. +2
    -7
      src/tests.cpp
  7. +8
    -0
      src/tests/StorageTree.tests.cpp

+ 2
- 0
.gitignore 파일 보기

@ -0,0 +1,2 @@
build/*
*.orig

+ 1
- 1
9float

@ -1 +1 @@
Subproject commit a2b9ca0d78fa2e4d4297c9dc841390117e0c742f
Subproject commit 01b4f6f1cbff85289674ab8e5aa95ecf976bd593

+ 10
- 4
Makefile 파일 보기

@ -20,7 +20,7 @@
CXX := -g++-8
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -O0 -std=c++2a -fPIC -DUSE_CATCH
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -Wno-pedantic -O0 -std=gnu++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
@ -31,8 +31,11 @@ TARGET := tests.cpp
INCLUDE := -Iinclude/ -I9float/include
SRC := \
TEST_SRC := \
$(wildcard src/tests/*.tests.cpp) \
OBJECTS := $(SRC:%.cpp=$(OBJ_DIR)/%.o)
TEST_OBJECTS := $(SRC:%.cpp=$(OBJ_DIR)/%.test.o)
TEST_OBJECTS := $(TEST_SRC:%.cpp=$(OBJ_DIR)/%.o) $(OBJECTS)
TARGETNAME := $(TARGET:%.cpp=%)
all: build $(TARGET)
@ -64,8 +67,11 @@ install: lib
ASTYLE_FLAGS= --style=stroustrup --align-reference=type --align-pointer=type --break-blocks \
--indent-namespaces --indent=tab --add-brackets
format:
astyle $(ASTYLE_FLAGS) include/scatter/*
astyle $(ASTYLE_FLAGS) src/scatter/*
-astyle $(ASTYLE_FLAGS) include/scatter/*
-astyle $(ASTYLE_FLAGS) src/scatter/*
-astyle $(ASTYLE_FLAGS) src/tests/*
-astyle $(ASTYLE_FLAGS) include/*
-astyle $(ASTYLE_FLAGS) src/*
build:
@mkdir -p $(APP_DIR)

+ 10964
- 9031
include/catch.hpp
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 76
- 65
include/scatter/scatter.h 파일 보기

@ -1,80 +1,91 @@
#pragma once
#include <stdint.h>
#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();
using scatter_key_t = ninefloat::Q<__int128,64>;
static const scatter_key_t scatter_key_increment = ninefloat::Q<__int128,64>::min_increment();
#include <vector>
#include <numeric>
#include <type_traits>
namespace StorageTree{
namespace StorageTree {
namespace _impl{
namespace _impl {
template<class childs>
struct subdivision
{
uint64_t weight;
std::vector<childs> content;
scatter_key_t begin;
scatter_key_t end;
static const bool divisible = true;
};
template<class childs>
struct subdivision {
uint64_t weight;
std::vector<childs> content;
scatter_key_t begin;
scatter_key_t end;
static constexpr bool divisible = true;
};
struct daemon_impl{
uint64_t weight;
scatter_key_t begin;
scatter_key_t end;
static const bool divisible = false;
};
template<class T>
constexpr T max(T any = 0)
{
if(any>any+scatter_key_increment)
return any;
return max(any+scatter_key_increment);
}
}
struct daemon_impl {
uint64_t weight;
scatter_key_t begin;
scatter_key_t end;
static constexpr bool divisible = false;
};
template<class T>
constexpr T max(T any = 0)
{
if(any>any+scatter_key_increment) {
return any;
}
using daemon = _impl::daemon_impl;
using server = _impl::subdivision<daemon>;
using subrack = _impl::subdivision<server>;
using rack = _impl::subdivision<subrack>;
using room = _impl::subdivision<rack>;
using datacenter = _impl::subdivision<room>;
using root = _impl::subdivision<datacenter>;
return max(any+scatter_key_increment);
}
}
template<class T, std::enable_if_t<T::divisible>>
uint64_t total_weight(T& root)
{
return std::reduce(
root.content.begin(),
root.content.end(),
0UL,
[](auto val, uint64_t acc)
{
return acc+total_weight(val);
}
);
}
template<class T, std::enable_if_t<!T::divisible>>
uint64_t total_weight(T& root)
{
return root.weight;
}
using daemon = _impl::daemon_impl;
using server = _impl::subdivision<daemon>;
using subrack = _impl::subdivision<server>;
using rack = _impl::subdivision<subrack>;
using room = _impl::subdivision<rack>;
using datacenter = _impl::subdivision<room>;
using root = _impl::subdivision<datacenter>;
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>>
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;
}
template<class T,class = void>
uint64_t total_weight(T& root)
{
return root.weight;
}
template<class T,std::enable_if_t<T::divisible>>
uint64_t total_weight(T& root)
{
uint64_t ret=0;
for(auto& val : root.content) {
ret+=total_weight(val);
}
return ret;
}
template<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)
{
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;
}
template<class T,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, scatter_key_t ratio=0.5)
{
for(auto& elem : root.content) {
begin = update_weights(
elem,
total,
sub_ratio*root.content.size(),
begin,
ratio
)+scatter_key_increment;
}
return begin;
}
}

+ 2
- 7
src/tests.cpp 파일 보기

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

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

@ -0,0 +1,8 @@
#include "catch.hpp"
#include "scatter/scatter.h"
TEST_CASE("Storage tree")
{
StorageTree::root n;
StorageTree::update_weights(n,StorageTree::total_weight<StorageTree::root>(n));
}

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