Bill Sun 3 years ago
parent d1a6b1d83f
commit 2462bc6711

@ -15,6 +15,9 @@ class ColRef:
self.order_pending = None # order_pending self.order_pending = None # order_pending
self.compound = compound # compound field (list as a field) self.compound = compound # compound field (list as a field)
self.views = [] self.views = []
self.aux_columns = [] # columns for temperary calculations
# e.g. order by, group by, filter by expressions
self.__arr__ = (cname, _ty, cobj, cnt, table, name, id) self.__arr__ = (cname, _ty, cobj, cnt, table, name, id)
def reference(self): def reference(self):
@ -90,6 +93,7 @@ class TableInfo:
type_tags += '>' type_tags += '>'
self.cxt.emit(f'auto& {base_name} = *(TableInfo{type_tags} *)(cxt->tables[{self.table_name}]);') self.cxt.emit(f'auto& {base_name} = *(TableInfo{type_tags} *)(cxt->tables[{self.table_name}]);')
return self.cxt_name
def refer_all(self): def refer_all(self):
self.reference() self.reference()
for c in self.columns: for c in self.columns:

@ -88,6 +88,15 @@ class outfile(ast_node):
def produce(self, node): def produce(self, node):
out_table:TableInfo = self.parent.out_table out_table:TableInfo = self.parent.out_table
filename = node['loc']['literal'] if 'loc' in node else node['literal'] filename = node['loc']['literal'] if 'loc' in node else node['literal']
sep = ',' if 'term' not in node else node['term']['literal']
self.context.headers.add('fstream')
cout_backup_buffer = 'stdout_' + base62uuid(4)
ofstream = 'ofstream_' + base62uuid(6)
self.emit(f'auto {cout_backup_buffer} = cout.rdbuf();')
self.emit(f'auto {ofstream} = ofstream("{filename}");')
self.emit(f'cout.rdbuf({ofstream}.rdbuf());')
self.emit_no_ln(f"\"{filename}\"1:`csv@(+(") self.emit_no_ln(f"\"{filename}\"1:`csv@(+(")
l_compound = False l_compound = False
l_cols = '' l_cols = ''
@ -115,5 +124,9 @@ class outfile(ast_node):
self.emit_no_ln(f'{l_keys}!+,/({ending(l_cols)})') self.emit_no_ln(f'{l_keys}!+,/({ending(l_cols)})')
self.emit('))') self.emit('))')
self.emit(f'cout.rdbuf({cout_backup_buffer});')
self.emit(f'{ofstream}.close();')
import sys import sys
include(sys.modules[__name__]) include(sys.modules[__name__])

@ -40,7 +40,7 @@ class expr(ast_node):
'not' : '!' 'not' : '!'
} }
coumpound_generating_ops = ['mod', 'mins', 'maxs', 'sums'] + \ coumpound_generating_ops = ['avgs', 'mins', 'maxs', 'sums'] + \
list( binary_ops.keys()) + list(compound_ops.keys()) + list(unary_ops.keys() ) list( binary_ops.keys()) + list(compound_ops.keys()) + list(unary_ops.keys() )
def __init__(self, parent, node, materialize_cols = True, abs_col = False): def __init__(self, parent, node, materialize_cols = True, abs_col = False):

@ -16,43 +16,26 @@ class order_item:
return ('' if self.order else '-') + f'({self.name})' return ('' if self.order else '-') + f'({self.name})'
def __str__(self): def __str__(self):
return self.materialize() return self.name
def __repr__(self): def __repr__(self):
return self.__str__() return self.__str__()
class orders:
def __init__(self, node, datasource):
self.order_items = []
self.materialized = False
self.view = None
self.node = node
self.datasource = datasource
self.n_attrs = -1
def materialize(self):
if not self.materialized:
self.view = View(self.node.context, self.datasource, False)
keys = ';'.join([f'{o}' for o in self.order_items])
self.n_attrs = len(self.order_items)
self.node.emit(f"{self.view.name}: > +`j (({',' if self.n_attrs == 1 else ''}{keys}))")
self.materialized = True
def append(self, o):
self.order_items.append(o)
class orderby(ast_node): class orderby(ast_node):
name = '_orderby' name = '_orderby'
def __init__(self, parent: "ast_node", node, context: Context = None):
self.col_list = []
super().__init__(parent, node, context)
def init(self, _): def init(self, _):
self.datasource = self.parent.datasource self.datasource = self.parent.datasource
self.order = orders(self, self.datasource) self.order = []
self.view = '' self.view = ''
def produce(self, node): def produce(self, node):
if type(node) is not list: if type(node) is not list:
node = [node] node = [node]
for n in node: for n in node:
order = not ('sort' in n and n['sort'] == 'desc') order = not ('sort' in n and n['sort'] == 'desc')
col_id = self.datasource.columns_byname[n['value']].id
self.col_list.append(col_id if order else -col_id-1)
self.order.append(order_item(n['value'], self, order)) self.order.append(order_item(n['value'], self, order))
def finialize(self, references):
def consume(self, _): self.order = [ o for o in self.order if o.name in references ]
self.datasource.order.append(self.order)

@ -14,6 +14,7 @@ class projection(ast_node):
self.disp = disp self.disp = disp
self.outname = outname self.outname = outname
self.group_node = None self.group_node = None
self.assumption = None
self.where = None self.where = None
ast_node.__init__(self, parent, node, context) ast_node.__init__(self, parent, node, context)
def init(self, _): def init(self, _):
@ -45,8 +46,7 @@ class projection(ast_node):
elif type(value) is str: elif type(value) is str:
self.datasource = self.context.tables_byname[value] self.datasource = self.context.tables_byname[value]
if 'assumptions' in from_clause: if 'assumptions' in from_clause:
for assumption in enlist(from_clause['assumptions']): self.assumption = orderby(self, enlist(from_clause['assumptions']))
orderby(self, assumption)
elif type(from_clause) is str: elif type(from_clause) is str:
self.datasource = self.context.tables_byname[from_clause] self.datasource = self.context.tables_byname[from_clause]
@ -84,6 +84,7 @@ class projection(ast_node):
if 'outfile' in node: if 'outfile' in node:
flatten = True flatten = True
new_names = []
for i, proj in enumerate(self.projections): for i, proj in enumerate(self.projections):
cname = '' cname = ''
compound = False compound = False
@ -92,12 +93,14 @@ class projection(ast_node):
if 'value' in proj: if 'value' in proj:
e = proj['value'] e = proj['value']
sname = expr(self, e)._expr sname = expr(self, e)._expr
fname = expr.toCExpr(sname) fname = expr.toCExpr(sname) # fastest access method at innermost context
absname = expr(self, e, abs_col=True)._expr absname = expr(self, e, abs_col=True)._expr # absolute name at function scope
compound = True compound = True
cexprs.append(fname) cexprs.append(fname)
cname = ''.join([a if a in base62alp else '' for a in fname()]) cname = e if type(e) is str else ''.join([a if a in base62alp else '' for a in expr.toCExpr(absname)()])
if 'name' in proj: # renaming column by AS keyword
cname = proj['name']
new_names.append(cname)
compound = compound and has_groupby and self.datasource.rec not in self.group_node.referenced compound = compound and has_groupby and self.datasource.rec not in self.group_node.referenced
cols.append(ColRef(cname, expr.toCExpr(f'decays<decltype({absname})>')(0), self.out_table, 0, None, cname, i, compound=compound)) cols.append(ColRef(cname, expr.toCExpr(f'decays<decltype({absname})>')(0), self.out_table, 0, None, cname, i, compound=compound))
@ -114,21 +117,17 @@ class projection(ast_node):
self.where.finalize() self.where.finalize()
has_orderby = 'orderby' in node has_orderby = 'orderby' in node
if has_orderby: if has_orderby:
self.datasource = self.out_table self.datasource = self.out_table
self.context.datasource = self.out_table # discard current ds self.context.datasource = self.out_table # discard current ds
orderby_node = orderby(self, node['orderby']) orderby_node = orderby(self, node['orderby'])
self.context.datasource.materialize_orderbys() self.emit(f'auto {disp_varname} ={self.out_table.reference()}->order_by_view<{",".join([f"{c}" for c in orderby_node.col_list])}>();')
self.emit_no_ln(f"{f'{disp_varname}:+' if flatten else ''}(") else:
disp_varname = f'*{self.out_table.cxt_name}'
if self.disp:
self.emit(f'print({disp_varname});')
if self.disp or has_orderby:
self.emit(f'print(*{self.out_table.cxt_name});')
if has_orderby:
self.emit(f')[{orderby_node.view}]')
else:
self.context.emit_flush()
if flatten: if flatten:
if len(self.projections) > 1 and not self.inv: if len(self.projections) > 1 and not self.inv:
self.emit(f"{disp_varname}:+{disp_varname}") self.emit(f"{disp_varname}:+{disp_varname}")

@ -1,8 +1,8 @@
#include "csv.h" #include "csv.h"
#include <unordered_map>
#include "./server/libaquery.h"
#include "./server/hasher.h" #include "./server/hasher.h"
#include <unordered_map>
#include "./server/aggregations.h" #include "./server/aggregations.h"
#include "./server/libaquery.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std; using namespace std;
@ -17,40 +17,45 @@ test_a.init();
test_b.init(); test_b.init();
test_c.init(); test_c.init();
test_d.init(); test_d.init();
io::CSVReader<4> csv_reader_6qlGpe("test.csv"); io::CSVReader<4> csv_reader_53LkPG("test.csv");
csv_reader_6qlGpe.read_header(io::ignore_extra_column, "a","b","c","d"); csv_reader_53LkPG.read_header(io::ignore_extra_column, "a","b","c","d");
int tmp_39gHMkie; int tmp_43xeYChp;
int tmp_190h2sZs; int tmp_3Vnt4fLK;
int tmp_4a8dDzSN; int tmp_1HKZwQBO;
int tmp_3LAKxSmM; int tmp_6IwJuIpg;
while(csv_reader_6qlGpe.read_row(tmp_39gHMkie,tmp_190h2sZs,tmp_4a8dDzSN,tmp_3LAKxSmM)) { while(csv_reader_53LkPG.read_row(tmp_43xeYChp,tmp_3Vnt4fLK,tmp_1HKZwQBO,tmp_6IwJuIpg)) {
test_a.emplace_back(tmp_39gHMkie); test_a.emplace_back(tmp_43xeYChp);
test_b.emplace_back(tmp_190h2sZs); test_b.emplace_back(tmp_3Vnt4fLK);
test_c.emplace_back(tmp_4a8dDzSN); test_c.emplace_back(tmp_1HKZwQBO);
test_d.emplace_back(tmp_3LAKxSmM); test_d.emplace_back(tmp_6IwJuIpg);
} }
typedef record<decltype(test_a[0]),decltype(test_b[0]),decltype(test_d[0])> record_type2Te4GFo; typedef record<decltype(test_a[0]),decltype(test_b[0]),decltype(test_d[0])> record_type1CmZCvh;
unordered_map<record_type2Te4GFo, vector_type<uint32_t>, transTypes<record_type2Te4GFo, hasher>> g79JNXM8; unordered_map<record_type1CmZCvh, vector_type<uint32_t>, transTypes<record_type1CmZCvh, hasher>> g6nov6MR;
for (uint32_t i5x = 0; i5x < test_a.size; ++i5x){ for (uint32_t i4I = 0; i4I < test_a.size; ++i4I){
g79JNXM8[forward_as_tuple(test_a[i5x],test_b[i5x],test_d[i5x])].emplace_back(i5x); g6nov6MR[forward_as_tuple(test_a[i4I],test_b[i4I],test_d[i4I])].emplace_back(i4I);
} }
auto out_5NL7 = new TableInfo<decays<decltype(sum(test_c[0]))>,decays<decltype(test_b[0])>,decays<decltype(test_d[0])>>("out_5NL7", 3); auto out_684r = new TableInfo<decays<decltype(sum(test_c[0]))>,decays<decltype(test_b[0])>,decays<decltype(test_d[0])>>("out_684r", 3);
cxt->tables.insert({"out_5NL7", out_5NL7}); cxt->tables.insert({"out_684r", out_684r});
auto& out_5NL7_sumtestc = *(ColRef<decays<decltype(sum(test_c[0]))>> *)(&out_5NL7->colrefs[0]); auto& out_684r_sumtestc = *(ColRef<decays<decltype(sum(test_c[0]))>> *)(&out_684r->colrefs[0]);
auto& out_5NL7_get1None = *(ColRef<decays<decltype(test_b[0])>> *)(&out_5NL7->colrefs[1]); auto& out_684r_b = *(ColRef<decays<decltype(test_b[0])>> *)(&out_684r->colrefs[1]);
auto& out_5NL7_get2None = *(ColRef<decays<decltype(test_d[0])>> *)(&out_5NL7->colrefs[2]); auto& out_684r_d = *(ColRef<decays<decltype(test_d[0])>> *)(&out_684r->colrefs[2]);
out_5NL7_sumtestc.init(); out_684r_sumtestc.init();
out_5NL7_get1None.init(); out_684r_b.init();
out_5NL7_get2None.init(); out_684r_d.init();
for(auto& i4l : g79JNXM8) { for(auto& i3d : g6nov6MR) {
auto &key_ADPihOU = i4l.first; auto &key_1TaM8D7 = i3d.first;
auto &val_7LsrkDP = i4l.second; auto &val_129np3x = i3d.second;
out_5NL7_sumtestc.emplace_back(sum(test_c[val_7LsrkDP])); out_684r_sumtestc.emplace_back(sum(test_c[val_129np3x]));
out_5NL7_get1None.emplace_back(get<1>(key_ADPihOU)); out_684r_b.emplace_back(get<1>(key_1TaM8D7));
out_5NL7_get2None.emplace_back(get<2>(key_ADPihOU)); out_684r_d.emplace_back(get<2>(key_1TaM8D7));
} }
print(*out_5NL7); auto d2X3bP6l =out_684r->order_by_view<-3,1>();
puts("a");
print(*(out_684r->order_by<-3,1>()));
puts("b");
print(out_684r->order_by_view<-3,1>());
puts("e");
print(*out_684r);
return 0; return 0;
} }

@ -7,4 +7,4 @@ FIELDS TERMINATED BY ","
SELECT sum(c), b, d SELECT sum(c), b, d
FROM test FROM test
group by a,b,d group by a,b,d
-- order by d DESC, b ASC order by d DESC, b ASC

@ -0,0 +1,15 @@
#pragma once
#include "types.h"
#include <cstdio>
#include <string>
#include <cstdio>
#include <string>
template <class ...Types>
std::string generate_printf_string(const char* sep = " ", const char* end = "\n") {
std::string str;
(void)std::initializer_list<int>{
(str += types::printf_str[types::Types<Types>::getType()], str += sep, 0)...
};
str += end;
return str;
}

@ -0,0 +1,19 @@
#pragma once
#include "vector_type.hpp"
#include <algorithm>
#include <stdint.h>
template <class Comparator, typename T = uint32_t>
class priority_vector : public vector_type<T> {
const Comparator comp;
public:
priority_vector(Comparator comp = std::less<T>{}) :
comp(comp), vector_type<T>(0) {}
void emplace_back(T val) {
vector_type<T>::emplace_back(val);
std::push_heap(container, container + size, comp);
}
void pop_back() {
std::pop_heap(container, container + size, comp);
--size;
}
};

@ -75,6 +75,7 @@ int main(int argc, char** argv) {
shm.FreeMemoryMap(); shm.FreeMemoryMap();
return 0; return 0;
} }
#include "utils.h"
int _main() int _main()
{ {
@ -83,6 +84,7 @@ int _main()
//t.emplace_back(2); //t.emplace_back(2);
//print(t); //print(t);
//return 0; //return 0;
puts(cpp_17 ?"true":"false");
void* handle = dlopen("dll.so", RTLD_LAZY); void* handle = dlopen("dll.so", RTLD_LAZY);
printf("handle: %x\n", handle); printf("handle: %x\n", handle);
Context* cxt = new Context(); Context* cxt = new Context();
@ -96,7 +98,8 @@ int _main()
} }
dlclose(handle); dlclose(handle);
} }
static_assert(std::is_same_v<decltype(fill_integer_array<5, 1>()), std::integer_sequence<bool, 1,1,1,1,1>>, "");
return 0; return 0;
} }

@ -168,6 +168,7 @@
<ClInclude Include="gc.hpp" /> <ClInclude Include="gc.hpp" />
<ClInclude Include="hasher.h" /> <ClInclude Include="hasher.h" />
<ClInclude Include="libaquery.h" /> <ClInclude Include="libaquery.h" />
<ClInclude Include="priority_vector.hpp" />
<ClInclude Include="table.h" /> <ClInclude Include="table.h" />
<ClInclude Include="types.h" /> <ClInclude Include="types.h" />
<ClInclude Include="utils.h" /> <ClInclude Include="utils.h" />
@ -175,10 +176,4 @@
<ClInclude Include="winhelper.h" /> <ClInclude Include="winhelper.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<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>
</Target>
</Project> </Project>

@ -1,3 +1,5 @@
// TODO: Replace `cout, printf` with sprintf&fputs and custom buffers
#ifndef _TABLE_H #ifndef _TABLE_H
#define _TABLE_H #define _TABLE_H
@ -85,13 +87,31 @@ inline ColRef<T> ColRef<_Ty>::scast()
return *(ColRef<T> *)this; return *(ColRef<T> *)this;
} }
using uColRef = ColRef<void>; using uColRef = ColRef<void>;
template<class ...Types> struct TableInfo;
template<class ...Types> struct TableView;
template <long long _Index, bool order = true, class... _Types>
constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept {
if constexpr (order)
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.colrefs[_Index]);
else
return *(ColRef<std::tuple_element_t<-1-_Index, std::tuple<_Types...>>> *) & (table.colrefs[-1-_Index]);
}
template <long long _Index, class... _Types>
constexpr inline ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableView<_Types...>& table) noexcept {
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.info.colrefs[_Index]);
}
template<class ...Types>
struct TableView;
template<class ...Types> template<class ...Types>
struct TableInfo { struct TableInfo {
const char* name; const char* name;
ColRef<void>* colrefs; ColRef<void>* colrefs;
uint32_t n_cols; uint32_t n_cols;
void print(const char* __restrict sep, const char* __restrict end) const;
typedef std::tuple<Types...> tuple_type; typedef std::tuple<Types...> tuple_type;
void print(const char* __restrict sep, const char* __restrict end) const;
template <size_t j = 0> 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; 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> template <size_t j = 0>
@ -103,46 +123,60 @@ struct TableInfo {
template <size_t ...Idxs> template <size_t ...Idxs>
using getRecordType = typename GetTypes<Idxs...>::type; using getRecordType = typename GetTypes<Idxs...>::type;
TableInfo(const char* name, uint32_t n_cols); TableInfo(const char* name, uint32_t n_cols);
//template<size_t ...Idxs = Types...> template <int prog = 0>
//struct Iterator_t { inline void materialize(const vector_type<uint32_t>& idxs, TableInfo<Types...>* tbl = nullptr) { // inplace materialize
// uint32_t val; if constexpr(prog == 0) tbl = 0 ? this : tbl;
// const TableInfo* info; if constexpr (prog == sizeof...(Types)) return;
// constexpr Iterator_t(const uint32_t* val, const TableInfo* info) noexcept : val(val), info(info) {} else {
// getRecordType<Idxs...> operator*() { auto& col = get<prog>(*this);
// return getRecordType<Idxs...>(info->colrefs[Idxs].operator[](*val)...); auto new_col = decays<decltype(col)>{idxs.size};
// } for(uint32_t i = 0; i < idxs.size; ++i)
// bool operator != (const Iterator_t& rhs) { return rhs.val != val; } new_col[i] = col[idxs[i]];
// Iterator_t& operator++ () { get<prog>(*tbl) = new_col;
// ++val; materialize<prog + 1>();
// return *this; }
// } }
// Iterator_t operator++ (int) { inline TableInfo<Types...>* materialize_copy(const vector_type<uint32_t>& idxs) {
// Iterator_t tmp = *this; auto tbl = new TableInfo<Types...>(this->name, sizeof...(Types));
// ++val; materialize<0>(idxs, tbl);
// return tmp; return tbl;
// } }
//}; template<int ...cols>
//template<size_t ...Idxs = Types...> inline vector_type<uint32_t>* order_by() {
//Iterator_t<Idxs...> begin() const { vector_type<uint32_t>* ord = new vector_type<uint32_t>(colrefs[0].size);
// for (uint32_t i = 0; i < colrefs[0].size; ++i)
//} (*ord)[i] = i;
//template<size_t ...Idxs = Types...> std::sort(ord->begin(), ord->end(), [this](const uint32_t& lhs, const uint32_t& rhs) {
//Iterator_t<Idxs...> end() const { return
// std::forward_as_tuple((cols >= 0 ? get<cols, (cols >= 0)>(*this)[lhs] : -get<cols, (cols >= 0)>(*this)[lhs]) ...)
//} <
// std::forward_as_tuple((cols >= 0 ? get<cols, (cols >= 0)>(*this)[rhs] : -get<cols, (cols >= 0)>(*this)[rhs]) ...);
//template<int ...Cols, bool ...ord> });
//order_by() { return ord;
// vector_type<uint32_t> order(colrefs[0].size); }
// std::sort(this->begin<Cols>) template <int ...cols>
//} auto order_by_view () {
return TableView<Types...>(order_by<cols...>(), *this);
}
}; };
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 ...Types>
struct TableView {
const vector_type<uint32_t>* idxs;
const TableInfo<Types...>& info;
constexpr TableView(const vector_type<uint32_t>* idxs, const TableInfo<Types...>& info) noexcept : idxs(idxs), info(info) {}
void print(const char* __restrict sep, const char* __restrict end) 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 j = 0>
typename std::enable_if < j < sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
~TableView() {
delete idxs;
}
};
template <class T> template <class T>
constexpr static inline bool is_vector(const ColRef<T>&) { constexpr static inline bool is_vector(const ColRef<T>&) {
return true; return true;
@ -159,7 +193,32 @@ template<class ...Types>
TableInfo<Types...>::TableInfo(const char* name, uint32_t n_cols) : name(name), n_cols(n_cols) { TableInfo<Types...>::TableInfo(const char* name, uint32_t n_cols) : name(name), n_cols(n_cols) {
this->colrefs = (ColRef<void>*)malloc(sizeof(ColRef<void>) * n_cols); this->colrefs = (ColRef<void>*)malloc(sizeof(ColRef<void>) * n_cols);
} }
template <class ...Types>
template <size_t j>
inline typename std::enable_if<j == sizeof...(Types) - 1, void>::type
TableView<Types ...>::print_impl(const uint32_t& i, const char* __restrict sep) const {
std::cout << (get<j>(*this))[(*idxs)[i]];
}
template<class ...Types>
template<size_t j>
inline typename std::enable_if < j < sizeof...(Types) - 1, void>::type
TableView<Types...>::print_impl(const uint32_t& i, const char* __restrict sep) const
{
std::cout << (get<j>(*this))[(*idxs)[i]] << sep;
print_impl<j + 1>(i, sep);
}
template<class ...Types>
inline void TableView<Types...>::print(const char* __restrict sep, const char* __restrict end) const {
int n_rows = 0;
if (info.colrefs[0].size > 0)
n_rows = info.colrefs[0].size;
for (int i = 0; i < n_rows; ++i) {
print_impl(i);
std::cout << end;
}
}
template <class ...Types> template <class ...Types>
template <size_t j> template <size_t j>
inline typename std::enable_if<j == sizeof...(Types) - 1, void>::type inline typename std::enable_if<j == sizeof...(Types) - 1, void>::type
@ -247,17 +306,24 @@ template <class ...Types>
void print(const TableInfo<Types...>& v, const char* delimiter = " ", const char* endline = "\n") { void print(const TableInfo<Types...>& v, const char* delimiter = " ", const char* endline = "\n") {
v.print(delimiter, endline); v.print(delimiter, endline);
} }
template <class ...Types>
void print(const TableView<Types...>& v, const char* delimiter = " ", const char* endline = "\n") {
v.print(delimiter, endline);
}
template <class T> template <class T>
void print(const T& v, const char* delimiter = " ") { void print(const T& v, const char* delimiter = " ") {
printf(types::printf_str[types::Types<T>::getType()], v); std::cout<< v;
// printf(types::printf_str[types::Types<T>::getType()], v);
} }
template <class T> template <class T>
void inline print_impl(const T& v, const char* delimiter, const char* endline) { void inline print_impl(const T& v, const char* delimiter, const char* endline) {
for (const auto& vi : v) { for (const auto& vi : v) {
print(vi); print(vi);
printf("%s", delimiter); std::cout << delimiter;
// printf("%s", delimiter);
} }
printf("%s", endline); std::cout << endline;
//printf("%s", endline);
} }
template <class T, template<typename> class VT> template <class T, template<typename> class VT>

@ -118,6 +118,16 @@ struct decayS <T<Types...>>{
using type = T<typename std::decay<Types>::type ...>; using type = T<typename std::decay<Types>::type ...>;
}; };
template <class T> template <class T>
using decays = typename decayS<T>::type; using decays = typename decayS<typename std::decay<T>::type>::type;
template <class T>
using decay_inner = typename decayS<T>::type;
template <int n, bool v = 1, bool ...vals>
auto fill_integer_array() {
if constexpr (n == 0)
return std::integer_sequence<bool, vals...>{};
else
return fill_integer_array<n - 1, v, v, vals...>();
};
#endif // !_TYPES_H #endif // !_TYPES_H

@ -1,18 +1,16 @@
#pragma once #pragma once
#include <string> #include <string>
#include <ctime> #include <ctime>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
template<int cnt, int begin = 0, int interval = 1> constexpr static bool cpp_17 = true;
struct const_range { #else
int arr[cnt]; constexpr static bool cpp_17 = false;
constexpr const_range() { #endif
for (int i = begin, n = 0; n < cnt; ++n, i += interval) template <class T>
arr[n] = i; inline const char* str(const T& v) {
} return "";
const int* begin() const { }
return arr; template <>
} inline const char* str(const bool& v) {
const int* end() const { return v ? "true" : "false";
return arr + cnt; }
}
};

@ -22,7 +22,7 @@
template <typename _Ty> template <typename _Ty>
class vector_type { class vector_type {
public: public:
void inline _copy(vector_type<_Ty>& vt) { void inline _copy(const vector_type<_Ty>& vt) {
this->size = vt.size; this->size = vt.size;
this->capacity = vt.capacity; this->capacity = vt.capacity;
this->container = (_Ty*)malloc(size * sizeof(_Ty)); this->container = (_Ty*)malloc(size * sizeof(_Ty));
@ -30,6 +30,8 @@ public:
memcpy(container, vt.container, sizeof(_Ty) * size); memcpy(container, vt.container, sizeof(_Ty) * size);
} }
void inline _move(vector_type<_Ty>&& vt) { void inline _move(vector_type<_Ty>&& vt) {
if (capacity > 0) free(container);
this->size = vt.size; this->size = vt.size;
this->capacity = vt.capacity; this->capacity = vt.capacity;
this->container = vt.container; this->container = vt.container;
@ -52,7 +54,7 @@ public:
} }
} }
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {}; constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
constexpr vector_type(vector_type<_Ty>& vt) noexcept { constexpr vector_type(const vector_type<_Ty>& vt) noexcept {
_copy(vt); _copy(vt);
} }
constexpr vector_type(vector_type<_Ty>&& vt) noexcept { constexpr vector_type(vector_type<_Ty>&& vt) noexcept {
@ -67,7 +69,7 @@ public:
container[0] = vt; container[0] = vt;
return *this; return *this;
} }
vector_type<_Ty> operator =(vector_type<_Ty>& vt) { vector_type<_Ty> operator =(const vector_type<_Ty>& vt) {
_copy(vt); _copy(vt);
return *this; return *this;
} }

Loading…
Cancel
Save