Single Table query part 1
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include <utility>
|
||||
#include <limits>
|
||||
#include <deque>
|
||||
template <class T, template<typename ...> class VT>
|
||||
size_t count(const VT<T>& v) {
|
||||
return v.size;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
constexpr static inline size_t count(const T&) { return 1; }
|
||||
|
||||
// TODO: Specializations for dt/str/none
|
||||
template<class T, template<typename ...> class VT>
|
||||
types::GetLongType<T> sum(const VT<T>& v) {
|
||||
types::GetLongType<T> ret = 0;
|
||||
for (const auto& _v : v)
|
||||
ret += _v;
|
||||
return ret;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
types::GetFPType<T> avg(const VT<T>& v) {
|
||||
return static_cast<types::GetFPType<T>>(
|
||||
sum<T>(v) / static_cast<long double>(v.size));
|
||||
}
|
||||
template <class T, template<typename ...> class VT>
|
||||
T max(const VT<T>& v) {
|
||||
T max_v = std::numeric_limits<T>::min();
|
||||
for (const auto& _v : v)
|
||||
max_v = max_v > _v ? max_v : _v;
|
||||
return max_v;
|
||||
}
|
||||
template <class T, template<typename ...> class VT>
|
||||
T min(const VT<T>& v) {
|
||||
T min_v = std::numeric_limits<T>::max();
|
||||
for (const auto& _v : v)
|
||||
min_v = min_v < _v ? min_v : _v;
|
||||
return min_v;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
VT<T> mins(const VT<T>& arr) {
|
||||
const int& len = arr.size;
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
VT<T> ret(len);
|
||||
T min = std::numeric_limits<T>::max();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (arr[i] < min)
|
||||
min = arr[i];
|
||||
ret[i] = min;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
VT<T> maxs(const VT<T>& arr) {
|
||||
const int& len = arr.size;
|
||||
VT<T> ret(len);
|
||||
T max = std::numeric_limits<T>::min();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (arr[i] > max)
|
||||
max = arr[i];
|
||||
ret[i] = max;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
VT<T> minw(const VT<T>& arr, uint32_t w) {
|
||||
const int& len = arr.size;
|
||||
VT<T> ret(len);
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
|
||||
while (!cache.empty() && cache.back().first > arr[i]) cache.pop_back();
|
||||
cache.push_back({ arr[i], i });
|
||||
ret[i] = cache.front().first;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
VT<T> maxw(const VT<T>& arr, uint32_t w) {
|
||||
const int& len = arr.size;
|
||||
VT<T> ret(len);
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
|
||||
while (!cache.empty() && cache.back().first > arr[i]) cache.pop_back();
|
||||
cache.push_back({ arr[i], i });
|
||||
arr[i] = cache.front().first;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T> constexpr inline T max(const T& v) { return v; }
|
||||
template <class T> constexpr inline T min(const T& v) { return v; }
|
||||
template <class T> constexpr inline T avg(const T& v) { return v; }
|
||||
template <class T> constexpr inline T sum(const T& v) { return v; }
|
||||
template <class T> constexpr inline T maxw(const T& v, uint32_t) { return v; }
|
||||
template <class T> constexpr inline T minw(const T& v, uint32_t) { return v; }
|
||||
template <class T> constexpr inline T avgw(const T& v, uint32_t) { return v; }
|
||||
template <class T> constexpr inline T sumw(const T& v, uint32_t) { return v; }
|
||||
template <class T> constexpr inline T maxs(const T& v) { return v; }
|
||||
template <class T> constexpr inline T mins(const T& v) { return v; }
|
||||
template <class T> constexpr inline T avgs(const T& v) { return v; }
|
||||
template <class T> constexpr inline T sums(const T& v) { return v; }
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
template <class ...Types>
|
||||
struct hasher {
|
||||
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
|
||||
size_t>::type hashi(const std::tuple<Types...>& record) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <size_t i = 0> typename std::enable_if< i < sizeof ...(Types),
|
||||
size_t>::type hashi(const std::tuple<Types...>& record) const {
|
||||
using current_type = typename std::decay<typename std::tuple_element<i, std::tuple<Types...>>::type>::type;
|
||||
return std::hash<current_type>()(std::get<i>(record)) ^ hashi<i+1>(record);
|
||||
}
|
||||
size_t operator()(const std::tuple<Types...>& record) const {
|
||||
return hashi(record);
|
||||
}
|
||||
};
|
||||
@@ -3,8 +3,16 @@
|
||||
|
||||
#include "table.h"
|
||||
#include <unordered_map>
|
||||
|
||||
struct Context{
|
||||
std::unordered_map<const char*, void*> tables;
|
||||
std::unordered_map<const char*, uColRef *> cols;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __DLLEXPORT__ __declspec(dllexport) __stdcall
|
||||
#else
|
||||
#define __DLLEXPORT__
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.210806.1" targetFramework="native" />
|
||||
</packages>
|
||||
+20
-64
@@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
//#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "libaquery.h"
|
||||
#ifdef _WIN32
|
||||
#include "winhelper.h"
|
||||
@@ -32,6 +33,7 @@ struct thread_context{
|
||||
void daemon(thread_context* c) {
|
||||
|
||||
}
|
||||
#include "aggregations.h"
|
||||
typedef int (*code_snippet)(void*);
|
||||
int _main();
|
||||
int main(int argc, char** argv) {
|
||||
@@ -51,7 +53,7 @@ int main(int argc, char** argv) {
|
||||
printf("running: %s\n", running? "true":"false");
|
||||
printf("ready: %s\n", ready? "true":"false");
|
||||
while (running) {
|
||||
std::this_thread::sleep_for(1us);
|
||||
std::this_thread::sleep_for(100us);
|
||||
if(ready){
|
||||
printf("running: %s\n", running? "true":"false");
|
||||
printf("ready: %s\n", ready? "true":"false");
|
||||
@@ -75,72 +77,26 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
int _main()
|
||||
{
|
||||
using string = std::string;
|
||||
using std::cout;
|
||||
using std::thread;
|
||||
|
||||
//vector_type<int> t;
|
||||
//t = 1;
|
||||
//t.emplace_back(2);
|
||||
//print(t);
|
||||
//return 0;
|
||||
void* handle = dlopen("dll.so", RTLD_LAZY);
|
||||
io::CSVReader<4> in("../test.csv");
|
||||
in.read_header(io::ignore_extra_column, "a", "b", "c", "d");
|
||||
int a, b, cc, d;
|
||||
string tp, tpdf, st;
|
||||
while (in.read_row(a, b, cc, d))
|
||||
cout << a<< ' ' << b <<' ' << cc <<' ' << d << '\n';
|
||||
|
||||
//code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dlmain"));
|
||||
//printf("%d", c(0));
|
||||
//dlclose(handle);
|
||||
vector_type<double> t1{ 1.2, 3.4, .2, 1e-5, 1, 3, 5, 4, 5};
|
||||
vector_type<int> t2{ 2, 4, 3, 5, 0, 2, 6, 1, 2};
|
||||
printf("x: ");
|
||||
const auto& ret = t1 - t2;
|
||||
for (const auto& x : ret) {
|
||||
printf("%lf ", x);
|
||||
}
|
||||
puts("");
|
||||
|
||||
printf("handle: %x\n", handle);
|
||||
Context* cxt = new Context();
|
||||
auto stocks = TableInfo<int, int>("stocks", 2);
|
||||
cxt->tables.insert(std::make_pair("stocks", &stocks));
|
||||
if (handle) {
|
||||
printf("inner\n");
|
||||
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain"));
|
||||
printf("routine: %x\n", c);
|
||||
if (c) {
|
||||
printf("inner\n");
|
||||
printf("return: %d\n", c(cxt));
|
||||
}
|
||||
dlclose(handle);
|
||||
}
|
||||
|
||||
auto& stocks_0 = get<0>(stocks);
|
||||
auto& stocks_1 = get<1>(stocks);
|
||||
|
||||
stocks_0.init();
|
||||
stocks_1.init();
|
||||
|
||||
stocks_0.emplace_back(1);
|
||||
stocks_1.emplace_back(15);
|
||||
stocks_0.emplace_back(2);
|
||||
stocks_1.emplace_back(19);
|
||||
stocks_0.emplace_back(3);
|
||||
stocks_1.emplace_back(16);
|
||||
stocks_0.emplace_back(4);
|
||||
stocks_1.emplace_back(17);
|
||||
stocks_0.emplace_back(5);
|
||||
stocks_1.emplace_back(15);
|
||||
stocks_0.emplace_back(6);
|
||||
stocks_1.emplace_back(13);
|
||||
stocks_0.emplace_back(7);
|
||||
stocks_1.emplace_back(5);
|
||||
stocks_0.emplace_back(8);
|
||||
stocks_1.emplace_back(8);
|
||||
stocks_0.emplace_back(9);
|
||||
stocks_1.emplace_back(7);
|
||||
stocks_0.emplace_back(10);
|
||||
stocks_1.emplace_back(13);
|
||||
stocks_0.emplace_back(11);
|
||||
stocks_1.emplace_back(11);
|
||||
stocks_0.emplace_back(12);
|
||||
stocks_1.emplace_back(14);
|
||||
stocks_0.emplace_back(13);
|
||||
stocks_1.emplace_back(10);
|
||||
stocks_0.emplace_back(14);
|
||||
stocks_1.emplace_back(5);
|
||||
stocks_0.emplace_back(15);
|
||||
stocks_1.emplace_back(2);
|
||||
stocks_0.emplace_back(16);
|
||||
stocks_1.emplace_back(5);
|
||||
printf("%d\n", max(stocks_0 - mins(stocks_1)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
VisualStudioVersion = 17.2.32210.308
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server.vcxproj", "{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81} = {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "..\Project1\Project1.vcxproj", "{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -21,6 +26,14 @@ Global
|
||||
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.Build.0 = Release|x64
|
||||
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x86.Build.0 = Release|Win32
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x64.Build.0 = Debug|x64
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|x86.Build.0 = Debug|Win32
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.ActiveCfg = Release|x64
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x64.Build.0 = Release|x64
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.ActiveCfg = Release|Win32
|
||||
{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
+18
-12
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -90,6 +89,8 @@
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -105,6 +106,8 @@
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -120,6 +123,8 @@
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -135,6 +140,8 @@
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -144,35 +151,34 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Media Include="..\out.cpp" />
|
||||
<ClCompile Include="table.cpp" />
|
||||
<ClCompile Include="server.cpp" />
|
||||
<ClCompile Include="types.cpp" />
|
||||
<ClCompile Include="utils.cpp" />
|
||||
<ClCompile Include="vector_type.cpp" />
|
||||
<ClCompile Include="winhelper.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="csv.h" />
|
||||
<None Include="cpp.hint" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\csv.h" />
|
||||
<ClInclude Include="aggregations.h" />
|
||||
<ClInclude Include="gc.hpp" />
|
||||
<ClInclude Include="table.h" />
|
||||
<ClInclude Include="hasher.h" />
|
||||
<ClInclude Include="libaquery.h" />
|
||||
<ClInclude Include="table.h" />
|
||||
<ClInclude Include="types.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
<ClInclude Include="vector_type.hpp" />
|
||||
<ClInclude Include="winhelper.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.210806.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
+149
-80
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "vector_type.hpp"
|
||||
|
||||
#include <iostream>
|
||||
template <typename T>
|
||||
class vector_type;
|
||||
template <>
|
||||
@@ -18,22 +18,64 @@ namespace types {
|
||||
struct Coercion;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename _Ty>
|
||||
class ColView;
|
||||
template<typename _Ty>
|
||||
class ColRef : public vector_type<_Ty>
|
||||
{
|
||||
public:
|
||||
const char* name;
|
||||
types::Type_t ty = types::ERROR;
|
||||
ColRef(uint32_t size, const char* name = "") : vector_type<_Ty>(size), name(name) {}
|
||||
ColRef(const uint32_t& size, const char* name = "") : vector_type<_Ty>(size), name(name) {}
|
||||
ColRef(const char* name) : name(name) {}
|
||||
void init() { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; }
|
||||
ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {}
|
||||
|
||||
using vector_type<_Ty>::operator[];
|
||||
using vector_type<_Ty>::operator=;
|
||||
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
|
||||
return ColView<_Ty>(*this, idxs);
|
||||
}
|
||||
template<typename T>
|
||||
ColRef<T> scast();
|
||||
};
|
||||
|
||||
template<typename _Ty>
|
||||
class ColView {
|
||||
public:
|
||||
const vector_type<uint32_t>& idxs;
|
||||
const ColRef<_Ty>& orig;
|
||||
const uint32_t& size;
|
||||
ColView(const ColRef<_Ty>& orig, const vector_type<uint32_t>& idxs) : orig(orig), idxs(idxs), size(idxs.size) {}
|
||||
ColView(const ColView<_Ty>& orig, const vector_type<uint32_t>& idxs) : orig(orig.orig), idxs(idxs), size(idxs.size) {
|
||||
for (uint32_t i = 0; i < size; ++i)
|
||||
idxs[i] = orig.idxs[idxs[i]];
|
||||
}
|
||||
_Ty& operator [](const uint32_t& i) const {
|
||||
return orig[idxs[i]];
|
||||
}
|
||||
struct Iterator_t {
|
||||
const uint32_t* val;
|
||||
const ColRef<_Ty>& orig;
|
||||
constexpr Iterator_t(const uint32_t* val, const ColRef<_Ty>& orig) noexcept : val(val), orig(orig) {}
|
||||
_Ty& operator*() { return orig[*val]; }
|
||||
bool operator != (const Iterator_t& rhs) { return rhs.val != val; }
|
||||
Iterator_t& operator++ () {
|
||||
++val;
|
||||
return *this;
|
||||
}
|
||||
Iterator_t operator++ (int) {
|
||||
Iterator_t tmp = *this;
|
||||
++val;
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
Iterator_t begin() const {
|
||||
return Iterator_t(idxs.begin(), orig);
|
||||
}
|
||||
Iterator_t end() const {
|
||||
return Iterator_t(idxs.end(), orig);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename _Ty>
|
||||
template<typename T>
|
||||
@@ -47,10 +89,27 @@ template<class ...Types>
|
||||
struct TableInfo {
|
||||
const char* name;
|
||||
ColRef<void>* colrefs;
|
||||
uint32_t n_cols, n_rows;
|
||||
//void print();
|
||||
uint32_t n_cols;
|
||||
void print(const char* __restrict sep, const char* __restrict end) const;
|
||||
typedef std::tuple<Types...> tuple_type;
|
||||
template <size_t j = 0>
|
||||
typename std::enable_if<j == sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
|
||||
template <size_t j = 0>
|
||||
typename std::enable_if<j < sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
|
||||
template <size_t ...Idxs>
|
||||
struct GetTypes {
|
||||
typedef typename std::tuple<typename std::tuple_element<Idxs, tuple_type>::type ...> type;
|
||||
};
|
||||
template <size_t ...Idxs>
|
||||
using getRecordType = typename GetTypes<Idxs...>::type;
|
||||
TableInfo(const char* name, uint32_t n_cols);
|
||||
};
|
||||
|
||||
template <size_t _Index, class... _Types>
|
||||
constexpr inline ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableInfo<_Types...>& table) noexcept {
|
||||
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.colrefs[_Index]);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
constexpr static inline bool is_vector(const ColRef<T>&) {
|
||||
return true;
|
||||
@@ -68,100 +127,110 @@ TableInfo<Types...>::TableInfo(const char* name, uint32_t n_cols) : name(name),
|
||||
this->colrefs = (ColRef<void>*)malloc(sizeof(ColRef<void>) * n_cols);
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
ColRef<typename types::Coercion<T1, T2>::type> operator -(const ColRef<T1>& lhs, const ColRef<T2>& rhs) {
|
||||
auto ret = ColRef<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
template <class ...Types>
|
||||
template <size_t j>
|
||||
inline typename std::enable_if<j == sizeof...(Types) - 1, void>::type
|
||||
TableInfo<Types ...>::print_impl(const uint32_t& i, const char* __restrict sep) const {
|
||||
std::cout << (get<j>(*this))[i];
|
||||
}
|
||||
|
||||
template<class ...Types>
|
||||
template<size_t j>
|
||||
inline typename std::enable_if<j < sizeof...(Types) - 1, void>::type
|
||||
TableInfo<Types...>::print_impl(const uint32_t& i, const char* __restrict sep) const
|
||||
{
|
||||
std::cout << (get<j>(*this))[i] << sep;
|
||||
print_impl<j+1>(i, sep);
|
||||
}
|
||||
|
||||
template<class ...Types>
|
||||
inline void TableInfo<Types...>::print(const char* __restrict sep, const char* __restrict end) const {
|
||||
int n_rows = 0;
|
||||
if (n_cols > 0 && colrefs[0].size > 0)
|
||||
n_rows = colrefs[0].size;
|
||||
for (int i = 0; i < n_rows; ++i) {
|
||||
print_impl(i);
|
||||
std::cout << end;
|
||||
}
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const VT<T2>& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] - rhs.container[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2>
|
||||
ColRef<typename types::Coercion<T1, T2>::type> operator -(const ColRef<T1>& lhs, const T2& rhs) {
|
||||
auto ret = ColRef<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] - rhs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <size_t _Index, class... _Types>
|
||||
constexpr ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(TableInfo<_Types...>& table) noexcept {
|
||||
return *(ColRef< std::tuple_element_t<_Index, std::tuple<_Types...>>> *) &(table.colrefs[_Index]);
|
||||
}
|
||||
|
||||
|
||||
//void TableInfo::print()
|
||||
//{
|
||||
// for (int i = 0; i < n_rows; ++i) {
|
||||
// for (int j = 0; j < n_cols; ++j) // TODO: Deal with date/time
|
||||
// printf(types::printf_str[colrefs[j].ty], colrefs[j].get(i, colrefs[j].ty));
|
||||
// puts("");
|
||||
// }
|
||||
//}
|
||||
template<class T>
|
||||
ColRef<T> mins(const ColRef<T>& arr) {
|
||||
const int& len = arr.size;
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
ColRef<T> ret(len);
|
||||
T min = std::numeric_limits<T>::max();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (arr[i] < min)
|
||||
min = arr[i];
|
||||
ret[i] = min;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const VT<T2>& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] + rhs.container[i];
|
||||
return ret;
|
||||
}
|
||||
template<class T>
|
||||
ColRef<T> maxs(const ColRef<T>& arr) {
|
||||
const int& len = arr.size;
|
||||
ColRef<T> ret(len);
|
||||
T max = std::numeric_limits<T>::min();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (arr[i] > max)
|
||||
max = arr[i];
|
||||
ret[i] = max;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] + rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const VT<T2>& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] * rhs.container[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] * rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator /(const VT<T1>& lhs, const VT<T2>& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] / rhs.container[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
VT<typename types::Coercion<T1, T2>::type> operator /(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = VT<typename types::Coercion<T1, T2>::type>(lhs.size, "");
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
ret.container[i] = lhs.container[i] / rhs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ColRef<T> minw(const ColRef<T>& arr, uint32_t w) {
|
||||
const int& len = arr.size;
|
||||
ColRef<T> ret(len);
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
|
||||
while (!cache.empty() && cache.back().first > arr[i]) cache.pop_back();
|
||||
cache.push_back({ arr[i], i });
|
||||
ret[i] = cache.front().first;
|
||||
}
|
||||
return ret;
|
||||
template <class ...Types>
|
||||
void print(const TableInfo<Types...>& v, const char* delimiter = " ", const char* endline = "\n") {
|
||||
v.print(delimiter, endline);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ColRef<T> maxw(const ColRef<T>& arr, uint32_t w) {
|
||||
const int& len = arr.size;
|
||||
ColRef<T> ret(len);
|
||||
std::deque<std::pair<T, uint32_t>> cache;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (!cache.empty() && cache.front().second == i - w) cache.pop_front();
|
||||
while (!cache.empty() && cache.back().first > arr[i]) cache.pop_back();
|
||||
cache.push_back({ arr[i], i });
|
||||
arr[i] = cache.front().first;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void print(const T& v) {
|
||||
void print(const T& v, const char* delimiter = " ") {
|
||||
printf(types::printf_str[types::Types<T>::getType()], v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void print(const ColRef<T>& v, const char* delimiter) {
|
||||
|
||||
void inline print_impl(const T& v, const char* delimiter, const char* endline) {
|
||||
for (const auto& vi : v) {
|
||||
print(vi);
|
||||
puts(delimiter);
|
||||
printf("%s", delimiter);
|
||||
}
|
||||
printf("%s", endline);
|
||||
}
|
||||
|
||||
template <class T, template<typename> class VT>
|
||||
typename std::enable_if<!std::is_same<VT<T>, TableInfo<T>>::value>::type
|
||||
print(const VT<T>& v, const char* delimiter = " ", const char* endline = "\n") {
|
||||
print_impl(v, delimiter, endline);
|
||||
}
|
||||
|
||||
#endif
|
||||
+43
-4
@@ -4,7 +4,8 @@
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
#include <string>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __restrict__ __restrict
|
||||
#endif
|
||||
@@ -72,13 +73,51 @@ namespace types {
|
||||
};
|
||||
#define __Eq(x) (sizeof(T) == sizeof(x))
|
||||
template<class T>
|
||||
struct GetFPType {
|
||||
struct GetFPTypeImpl {
|
||||
using type = Cond(__Eq(float), float, Cond(__Eq(double), double, long double));
|
||||
};
|
||||
template<class T>
|
||||
struct GetLongType
|
||||
{
|
||||
using GetFPType = typename GetFPTypeImpl<T>::type;
|
||||
template<class T>
|
||||
struct GetLongTypeImpl {
|
||||
using type = Cond(_U(T), unsigned long long, Cond(Fp(T), long double, long long));
|
||||
};
|
||||
template<class T>
|
||||
using GetLongType = typename GetLongTypeImpl<T>::type;
|
||||
}
|
||||
|
||||
#define getT(i, t) std::tuple_element_t<i, std::tuple<t...>>
|
||||
template <template<typename ...> class T, typename ...Types>
|
||||
struct applyTemplates {
|
||||
using type = T<Types...>;
|
||||
};
|
||||
|
||||
template <class lT, template <typename ...> class rT>
|
||||
struct transTypes_s;
|
||||
template <template<typename ...> class lT, typename ...T, template<typename ...> class rT>
|
||||
struct transTypes_s<lT<T...>, rT> {
|
||||
using type = rT<T...>;
|
||||
};
|
||||
|
||||
// static_assert(std::is_same<transTypes<std::tuple<int, float>, std::unordered_map>, std::unordered_map<int, float>>::value);
|
||||
template <class lT, template <typename ...> class rT>
|
||||
using transTypes = typename transTypes_s<lT, rT>::type;
|
||||
|
||||
template <class ...Types>
|
||||
struct record_types {};
|
||||
|
||||
template <class ...Types>
|
||||
using record = std::tuple<Types...>;
|
||||
|
||||
template <class T>
|
||||
struct decayS {
|
||||
using type = typename std::decay<T>::type;
|
||||
};
|
||||
template<template<typename ...> class T, typename ...Types>
|
||||
struct decayS <T<Types...>>{
|
||||
using type = T<typename std::decay<Types>::type ...>;
|
||||
};
|
||||
template <class T>
|
||||
using decays = typename decayS<T>::type;
|
||||
|
||||
#endif // !_TYPES_H
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "utils.h"
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
using std::string;
|
||||
string base62uuid(int l = 8) {
|
||||
using namespace std;
|
||||
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
|
||||
static uniform_int_distribution<uint64_t> u(0x10000, 0xfffff);
|
||||
uint64_t uuid = (u(engine) << 32ull) + (chrono::system_clock::now().time_since_epoch().count() & 0xffffffff);
|
||||
printf("%llx\n", uuid);
|
||||
string ret;
|
||||
while (uuid && l-- >= 0) {
|
||||
ret = string("") + base62alp[uuid % 62] + ret;
|
||||
uuid /= 62;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
+15
-15
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
using std::string;
|
||||
string base62uuid(int l = 8) {
|
||||
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
|
||||
static uniform_int_distribution<uint64_t> u(0x100000000, 0xfffffffff);
|
||||
uint64_t uuid = (u(engine)<<16ull) + (time(0)&0xffff);
|
||||
printf("%lx\n", uuid);
|
||||
string ret;
|
||||
while (uuid && l-- >= 0){
|
||||
ret = string("") + base62alp[uuid % 62] + ret;
|
||||
uuid /= 62;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int cnt, int begin = 0, int interval = 1>
|
||||
struct const_range {
|
||||
int arr[cnt];
|
||||
constexpr const_range() {
|
||||
for (int i = begin, n = 0; n < cnt; ++n, i += interval)
|
||||
arr[n] = i;
|
||||
}
|
||||
const int* begin() const {
|
||||
return arr;
|
||||
}
|
||||
const int* end() const {
|
||||
return arr + cnt;
|
||||
}
|
||||
};
|
||||
+15
-37
@@ -41,7 +41,7 @@ public:
|
||||
_Ty* container;
|
||||
uint32_t size, capacity;
|
||||
typedef _Ty* iterator_t;
|
||||
vector_type(uint32_t size) : size(size), capacity(size) {
|
||||
vector_type(const uint32_t& size) : size(size), capacity(size) {
|
||||
container = (_Ty*)malloc(size * sizeof(_Ty));
|
||||
}
|
||||
constexpr vector_type(std::initializer_list<_Ty> _l) {
|
||||
@@ -51,13 +51,22 @@ public:
|
||||
*(_container++) = l;
|
||||
}
|
||||
}
|
||||
constexpr vector_type() noexcept {};
|
||||
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
|
||||
constexpr vector_type(vector_type<_Ty>& vt) noexcept {
|
||||
_copy(vt);
|
||||
}
|
||||
constexpr vector_type(vector_type<_Ty>&& vt) noexcept {
|
||||
_move(std::move(vt));
|
||||
}
|
||||
vector_type<_Ty> operator =(const _Ty& vt) {
|
||||
if (!container) {
|
||||
container = (_Ty*)malloc(sizeof(_Ty));
|
||||
capacity = 1;
|
||||
}
|
||||
size = 1;
|
||||
container[0] = vt;
|
||||
return *this;
|
||||
}
|
||||
vector_type<_Ty> operator =(vector_type<_Ty>& vt) {
|
||||
_copy(vt);
|
||||
return *this;
|
||||
@@ -102,7 +111,7 @@ public:
|
||||
return curr;
|
||||
}
|
||||
|
||||
_Ty& operator[](const std::size_t _i) const {
|
||||
_Ty& operator[](const uint32_t _i) const {
|
||||
return container[_i];
|
||||
}
|
||||
|
||||
@@ -240,42 +249,11 @@ public:
|
||||
}
|
||||
constexpr vector_type() : size(0), capacity(0), container(0) {};
|
||||
void *get(uint32_t i, types::Type_t atype){
|
||||
|
||||
return static_cast<void*>(static_cast<char*>(container) + (i * types::AType_sizes[atype]));
|
||||
}
|
||||
void operator[](const uint32_t& i) {
|
||||
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Specializations for dt/str/none
|
||||
template<class T>
|
||||
types::GetLongType<T> sum(const vector_type<T> &v) {
|
||||
types::GetLongType<T> ret = 0;
|
||||
for (const auto& _v : v)
|
||||
ret += _v;
|
||||
return ret;
|
||||
}
|
||||
template<class T>
|
||||
types::GetFPType<T> avg(const vector_type<T> &v) {
|
||||
return static_cast<types::GetFPType<T>>(
|
||||
sum<T>(v)/static_cast<long double>(v.size));
|
||||
}
|
||||
template <class T>
|
||||
T max(const vector_type<T>& v) {
|
||||
T max_v = std::numeric_limits<T>::min();
|
||||
for (const auto& _v : v)
|
||||
max_v = max_v > _v ? max_v : _v;
|
||||
return max_v;
|
||||
}
|
||||
template <class T>
|
||||
T min(const vector_type<T>& v) {
|
||||
T min_v = std::numeric_limits<T>::max();
|
||||
for (const auto& _v : v)
|
||||
min_v = min_v < _v ? min_v : _v;
|
||||
return min_v;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@ void* dlopen(const char* lib, int)
|
||||
|
||||
void* dlsym(void* handle, const char* proc)
|
||||
{
|
||||
return GetProcAddress(static_cast<HMODULE>(handle), proc);
|
||||
return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), proc));
|
||||
}
|
||||
|
||||
int dlclose(void* handle)
|
||||
|
||||
Reference in New Issue
Block a user