diff --git a/README.md b/README.md index b12e302..7328873 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Frontend built on top of [mo-sql-parsing](https://github.com/klahnakoski/mo-sql- - [ ] Subqueries - [ ] -> Optimizing Compiler +## TODO: +- [ ] C++ Meta-Programming: Elimilate template recursions as much as possible. +- [ ] IPC: Better ways to communicate between Interpreter (Python) and Executer (C++). + - [ ] Sockets? stdin/stdout capture? ## Introduction ## Requirements diff --git a/engine/ast.py b/engine/ast.py index a4aaf70..02d3464 100644 --- a/engine/ast.py +++ b/engine/ast.py @@ -143,8 +143,8 @@ class TableInfo: def get_col_d(self, col_name): col = self.columns_byname[col_name] - if type(self.rec) is list: - self.rec.append(col) + if type(self.rec) is set: + self.rec.add(col) return col def get_ccolname_d(self, col_name): @@ -167,12 +167,12 @@ class TableInfo: self.alias.add(alias) def parse_tablenames(self, colExpr, materialize = True, raw = False): - self.get_col = self.get_col if materialize else self.get_col_d + # get_col = self.get_col if materialize else self.get_col_d parsedColExpr = colExpr.split('.') ret = None if len(parsedColExpr) <= 1: - ret = self.get_col(colExpr) + ret = self.get_col_d(colExpr) else: datasource = self.cxt.tables_byname[parsedColExpr[0]] if datasource is None: @@ -184,6 +184,7 @@ class TableInfo: if self.groupinfo is not None and ret and ret in self.groupinfo.raw_groups: string = f'get<{self.groupinfo.raw_groups.index(ret)}>({{y}})' return string, ret if raw else string + class View: def __init__(self, context, table = None, tmp = True): self.table: TableInfo = table @@ -200,6 +201,7 @@ class Context: extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { using namespace std; using namespace types; + ''' def __init__(self): self.tables:List[TableInfo] = [] diff --git a/engine/ddl.py b/engine/ddl.py index a13ba2c..0c946b6 100644 --- a/engine/ddl.py +++ b/engine/ddl.py @@ -89,43 +89,19 @@ class outfile(ast_node): out_table:TableInfo = self.parent.out_table 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@(+(") - l_compound = False - l_cols = '' - l_keys = '' - ending = lambda x: x[:-1] if len(x) > 0 and x[-1]==';' else x - for i, c in enumerate(out_table.columns): - c:ColRef - l_keys += '`' + c.name - if c.compound: - if l_compound: - l_cols=f'flatBOTH\'+(({ending(l_cols)});{c.cname})' - else: - l_compound = True - if i >= 1: - l_cols = f'flatRO\'+(({ending(l_cols)});{c.cname})' - else: - l_cols = c.cname + ';' - elif l_compound: - l_cols = f'flatLO\'+(({ending(l_cols)});{c.cname})' - else: - l_cols += f"{c.cname};" - if not l_compound: - self.emit_no_ln(l_keys + '!(' + ending(l_cols) + ')') - else: - self.emit_no_ln(f'{l_keys}!+,/({ending(l_cols)})') - self.emit('))') - - self.emit(f'cout.rdbuf({cout_backup_buffer});') - self.emit(f'{ofstream}.close();') + file_pointer = 'fp_' + base62uuid(6) + self.emit(f'FILE* {file_pointer} = fopen("{filename}", "w");') + self.emit(f'{out_table.cxt_name}->printall("{sep}", "\\n", nullptr, {file_pointer});') + self.emit(f'fclose({file_pointer});') + # 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());') + # TODO: ADD STMTS. + # self.emit(f'cout.rdbuf({cout_backup_buffer});') + # self.emit(f'{ofstream}.close();') import sys diff --git a/engine/expr.py b/engine/expr.py index 91440e9..b387d79 100644 --- a/engine/expr.py +++ b/engine/expr.py @@ -11,10 +11,10 @@ class expr(ast_node): 'avg': 'avg', 'sum': 'sum', 'count' : 'count', - 'mins': ['mins', 'minsw'], - 'maxs': ['maxs', 'maxsw'], - 'avgs': ['avgs', 'avgsw'], - 'sums': ['sums', 'sumsw'], + 'mins': ['mins', 'minw'], + 'maxs': ['maxs', 'maxw'], + 'avgs': ['avgs', 'avgw'], + 'sums': ['sums', 'sumw'], } binary_ops = { @@ -47,6 +47,9 @@ class expr(ast_node): self.materialize_cols = materialize_cols self.raw_col = None self.__abs = abs_col + self.inside_agg = False + if(type(parent) is expr): + self.inside_agg = parent.inside_agg ast_node.__init__(self, parent, node, None) def init(self, _): @@ -67,7 +70,8 @@ class expr(ast_node): if type(node) is dict: for key, val in node.items(): if key in self.func_maps: - # if type(val) in [dict, str]: + # TODO: distinguish between UDF agg functions and other UDF functions. + self.inside_agg = True self.context.headers.add('"./server/aggregations.h"') if type(val) is list and len(val) > 1: cfunc = self.func_maps[key] @@ -81,6 +85,7 @@ class expr(ast_node): self._expr += f"{funcname}(" self._expr += expr(self, val)._expr self._expr += ')' + self.inside_agg = False elif key in self.binary_ops: l = expr(self, val[0])._expr r = expr(self, val[1])._expr @@ -112,7 +117,7 @@ class expr(ast_node): self._expr, self.raw_col = self.datasource.parse_tablenames(node, self.materialize_cols, True) self.raw_col = self.raw_col if type(self.raw_col) is ColRef else None if self.__abs and self.raw_col: - self._expr = self.raw_col.reference() + index_expr + self._expr = self.raw_col.reference() + ("" if self.inside_agg else index_expr) elif type(node) is bool: self._expr = '1' if node else '0' else: diff --git a/engine/groupby.py b/engine/groupby.py index d03aef5..8d2999a 100644 --- a/engine/groupby.py +++ b/engine/groupby.py @@ -12,7 +12,7 @@ class groupby(ast_node): self.group_type = 'record_type' + base62uuid(7) self.datasource = self.parent.datasource self.scanner = None - self.datasource.rec = [] + self.datasource.rec = set() self.raw_groups = [] def produce(self, node): diff --git a/engine/projection.py b/engine/projection.py index 204632e..22cd5c6 100644 --- a/engine/projection.py +++ b/engine/projection.py @@ -4,7 +4,7 @@ from engine.join import join from engine.expr import expr from engine.orderby import orderby from engine.scan import filter -from engine.utils import base62uuid, enlist, base62alp +from engine.utils import base62uuid, enlist, base62alp, has_other from engine.ddl import create_table, outfile import copy @@ -88,26 +88,39 @@ class projection(ast_node): for i, proj in enumerate(self.projections): cname = '' compound = False - self.datasource.rec = [] + self.datasource.rec = set() if type(proj) is dict: if 'value' in proj: e = proj['value'] sname = expr(self, e)._expr fname = expr.toCExpr(sname) # fastest access method at innermost context absname = expr(self, e, abs_col=True)._expr # absolute name at function scope - compound = True + compound = True # compound column cexprs.append(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 + elif type(proj) is str: + col = self.datasource.get_col_d(proj) + if type(col) is ColRef: + col.reference() + + compound = compound and has_groupby and has_other(self.datasource.rec, self.group_node.referenced) + self.datasource.rec = None + + typename = '' + if not compound: + typename = f'value_type>' + else : + typename = f'decays' + + cols.append(ColRef(cname, expr.toCExpr(typename)(), self.out_table, 0, None, cname, i, compound=compound)) - cols.append(ColRef(cname, expr.toCExpr(f'decays')(0), self.out_table, 0, None, cname, i, compound=compound)) self.out_table.add_cols(cols, False) if has_groupby: - create_table(self, self.out_table) + create_table(self, self.out_table) # only initializes out_table. self.group_node.finalize(cexprs, self.out_table) else: create_table(self, self.out_table, cexpr = cexprs) @@ -129,8 +142,6 @@ class projection(ast_node): if flatten: - if len(self.projections) > 1 and not self.inv: - self.emit(f"{disp_varname}:+{disp_varname}") outfile(self, node['outfile']) if self.datasource_changed: diff --git a/engine/utils.py b/engine/utils.py index 283a80f..5a7c427 100644 --- a/engine/utils.py +++ b/engine/utils.py @@ -16,4 +16,10 @@ def enlist(l): return l if type(l) is list else [l] def seps(s, i, l): - return s if i < len(l) - 1 else '' \ No newline at end of file + return s if i < len(l) - 1 else '' + +def has_other(a, b): + for ai in a: + if ai not in b: + return True + return False \ No newline at end of file diff --git a/moving_avg.a b/moving_avg.a index 2d4d5fa..391f71c 100644 --- a/moving_avg.a +++ b/moving_avg.a @@ -6,7 +6,7 @@ FIELDS TERMINATED BY "\t" SELECT Month,avgs(3,sales) FROM sale - ASSUMING ASC Month +-- ASSUMING ASC Month INTO OUTFILE "moving_avg_output.csv" FIELDS TERMINATED BY "," diff --git a/msc-plugin/msc-plugin.vcxproj b/msc-plugin/msc-plugin.vcxproj index 78d05a4..8e000f0 100644 --- a/msc-plugin/msc-plugin.vcxproj +++ b/msc-plugin/msc-plugin.vcxproj @@ -93,6 +93,7 @@ true _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console @@ -108,6 +109,7 @@ true _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console @@ -123,6 +125,7 @@ true _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console @@ -138,6 +141,7 @@ true _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console diff --git a/msvs-py/engine/projection.py b/msvs-py/engine/projection.py new file mode 100644 index 0000000..0eafd1f --- /dev/null +++ b/msvs-py/engine/projection.py @@ -0,0 +1,145 @@ +from engine.ast import ColRef, TableInfo, ast_node, Context, include +from engine.groupby import groupby +from engine.join import join +from engine.expr import expr +from engine.orderby import orderby +from engine.scan import filter +from engine.utils import base62uuid, enlist, base62alp +from engine.ddl import create_table, outfile +import copy + +class projection(ast_node): + name='select' + def __init__(self, parent:ast_node, node, context:Context = None, outname = None, disp = True): + self.disp = disp + self.outname = outname + self.group_node = None + self.assumption = None + self.where = None + ast_node.__init__(self, parent, node, context) + def init(self, _): + if self.outname is None: + self.outname = self.context.gen_tmptable() + + def produce(self, node): + p = node['select'] + self.projections = p if type(p) is list else [p] + print(node) + + def spawn(self, node): + self.datasource = None + if 'from' in node: + from_clause = node['from'] + if type(from_clause) is list: + # from joins + join(self, from_clause) + elif type(from_clause) is dict: + if 'value' in from_clause: + value = from_clause['value'] + if type(value) is dict: + if 'select' in value: + # from subquery + projection(self, from_clause, disp = False) + else: + # TODO: from func over table + print(f'from func over table{node}') + elif type(value) is str: + self.datasource = self.context.tables_byname[value] + if 'assumptions' in from_clause: + self.assumption = orderby(self, enlist(from_clause['assumptions'])) + + elif type(from_clause) is str: + self.datasource = self.context.tables_byname[from_clause] + + if self.datasource is None: + raise ValueError('spawn error: from clause') + + if self.datasource is not None: + self.datasource_changed = True + self.prev_datasource = self.context.datasource + self.context.datasource = self.datasource + if 'where' in node: + self.where = filter(self, node['where'], True) + # self.datasource = filter(self, node['where'], True).output + #self.context.datasource = self.datasource + + if 'groupby' in node: + self.group_node = groupby(self, node['groupby']) + self.datasource = copy.copy(self.datasource) # shallow copy + self.datasource.groupinfo = self.group_node + else: + self.group_node = None + + def consume(self, node): + self.inv = True + disp_varname = 'd'+base62uuid(7) + has_groupby = False + if self.group_node is not None: + # There is group by; + has_groupby = True + cexprs = [] + flatten = False + cols = [] + self.out_table = TableInfo('out_'+base62uuid(4), [], self.context) + if 'outfile' in node: + flatten = True + + new_names = [] + for i, proj in enumerate(self.projections): + cname = '' + compound = False + self.datasource.rec = set() + if type(proj) is dict: + if 'value' in proj: + e = proj['value'] + sname = expr(self, e)._expr + fname = expr.toCExpr(sname) # fastest access method at innermost context + absname = expr(self, e, abs_col=True)._expr # absolute name at function scope + compound = True + cexprs.append(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) + elif type(proj) is str: + col = self.datasource.get_col_d(proj) + if type(col) is ColRef: + col.reference() + compound = compound and has_groupby and self.datasource.rec not in self.group_node.referenced + self.datasource.rec = None + cols.append(ColRef(cname, expr.toCExpr(f'decays')(0), self.out_table, 0, None, cname, i, compound=compound)) + self.out_table.add_cols(cols, False) + + if has_groupby: + create_table(self, self.out_table) + self.group_node.finalize(cexprs, self.out_table) + else: + create_table(self, self.out_table, cexpr = cexprs) + self.datasource.group_node = None + + if self.where is not None: + self.where.finalize() + + has_orderby = 'orderby' in node + if has_orderby: + self.datasource = self.out_table + self.context.datasource = self.out_table # discard current ds + orderby_node = orderby(self, node['orderby']) + self.emit(f'auto {disp_varname} ={self.out_table.reference()}->order_by_view<{",".join([f"{c}" for c in orderby_node.col_list])}>();') + else: + disp_varname = f'*{self.out_table.cxt_name}' + if self.disp: + self.emit(f'print({disp_varname});') + + + if flatten: + if len(self.projections) > 1 and not self.inv: + self.emit(f"{disp_varname}:+{disp_varname}") + outfile(self, node['outfile']) + + if self.datasource_changed: + self.context.datasource = self.prev_datasource + + +import sys +include(sys.modules[__name__]) \ No newline at end of file diff --git a/msvs-py/msvs-py.pyproj b/msvs-py/msvs-py.pyproj new file mode 100644 index 0000000..67fab2a --- /dev/null +++ b/msvs-py/msvs-py.pyproj @@ -0,0 +1,90 @@ + + + Debug + 2.0 + ccc243f5-663e-45b7-a6de-b2468c58b3a7 + . + + + ..\msvs-py + . + . + msvs-py + msvs-py + + + true + false + + + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out.cpp b/out.cpp index d91c898..6d056ce 100644 --- a/out.cpp +++ b/out.cpp @@ -1,12 +1,13 @@ -#include "csv.h" -#include "./server/hasher.h" #include -#include "./server/aggregations.h" #include "./server/libaquery.h" +#include "./server/hasher.h" +#include "./server/aggregations.h" +#include "csv.h" extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { using namespace std; using namespace types; + auto test = new TableInfo("test", 4); cxt->tables.insert({"test", test}); auto& test_a = *(ColRef *)(&test->colrefs[0]); @@ -17,45 +18,40 @@ test_a.init(); test_b.init(); test_c.init(); test_d.init(); -io::CSVReader<4> csv_reader_53LkPG("test.csv"); -csv_reader_53LkPG.read_header(io::ignore_extra_column, "a","b","c","d"); -int tmp_43xeYChp; -int tmp_3Vnt4fLK; -int tmp_1HKZwQBO; -int tmp_6IwJuIpg; -while(csv_reader_53LkPG.read_row(tmp_43xeYChp,tmp_3Vnt4fLK,tmp_1HKZwQBO,tmp_6IwJuIpg)) { +io::CSVReader<4> csv_reader_4bTMJ9("test.csv"); +csv_reader_4bTMJ9.read_header(io::ignore_extra_column, "a","b","c","d"); +int tmp_78E1nhZJ; +int tmp_4wnHGd9t; +int tmp_5OL9GlRp; +int tmp_155GVQC6; +while(csv_reader_4bTMJ9.read_row(tmp_78E1nhZJ,tmp_4wnHGd9t,tmp_5OL9GlRp,tmp_155GVQC6)) { -test_a.emplace_back(tmp_43xeYChp); -test_b.emplace_back(tmp_3Vnt4fLK); -test_c.emplace_back(tmp_1HKZwQBO); -test_d.emplace_back(tmp_6IwJuIpg); +test_a.emplace_back(tmp_78E1nhZJ); +test_b.emplace_back(tmp_4wnHGd9t); +test_c.emplace_back(tmp_5OL9GlRp); +test_d.emplace_back(tmp_155GVQC6); } -typedef record record_type1CmZCvh; -unordered_map, transTypes> g6nov6MR; -for (uint32_t i4I = 0; i4I < test_a.size; ++i4I){ -g6nov6MR[forward_as_tuple(test_a[i4I],test_b[i4I],test_d[i4I])].emplace_back(i4I); +typedef record record_type6jn8Y49; +unordered_map, transTypes> g5gn6KEb; +for (uint32_t i3V = 0; i3V < test_a.size; ++i3V){ +g5gn6KEb[forward_as_tuple(test_a[i3V],test_b[i3V],test_d[i3V])].emplace_back(i3V); } -auto out_684r = new TableInfo,decays,decays>("out_684r", 3); -cxt->tables.insert({"out_684r", out_684r}); -auto& out_684r_sumtestc = *(ColRef> *)(&out_684r->colrefs[0]); -auto& out_684r_b = *(ColRef> *)(&out_684r->colrefs[1]); -auto& out_684r_d = *(ColRef> *)(&out_684r->colrefs[2]); -out_684r_sumtestc.init(); -out_684r_b.init(); -out_684r_d.init(); -for(auto& i3d : g6nov6MR) { -auto &key_1TaM8D7 = i3d.first; -auto &val_129np3x = i3d.second; -out_684r_sumtestc.emplace_back(sum(test_c[val_129np3x])); -out_684r_b.emplace_back(get<1>(key_1TaM8D7)); -out_684r_d.emplace_back(get<2>(key_1TaM8D7)); +auto out_4DCN = new TableInfo,value_type>,value_type>>("out_4DCN", 3); +cxt->tables.insert({"out_4DCN", out_4DCN}); +auto& out_4DCN_sumtestc = *(ColRef> *)(&out_4DCN->colrefs[0]); +auto& out_4DCN_b = *(ColRef>> *)(&out_4DCN->colrefs[1]); +auto& out_4DCN_d = *(ColRef>> *)(&out_4DCN->colrefs[2]); +out_4DCN_sumtestc.init(); +out_4DCN_b.init(); +out_4DCN_d.init(); +for(auto& i1s : g5gn6KEb) { +auto &key_4Q0aEyH = i1s.first; +auto &val_7BUMR6d = i1s.second; +out_4DCN_sumtestc.emplace_back(sum(test_c[val_7BUMR6d])); +out_4DCN_b.emplace_back(get<1>(key_4Q0aEyH)); +out_4DCN_d.emplace_back(get<2>(key_4Q0aEyH)); } -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); +auto d6X0PMzl =out_4DCN->order_by_view<-3,1>(); +print(d6X0PMzl); return 0; } \ No newline at end of file diff --git a/out_attempt1.cpp b/out_attempt1.cpp new file mode 100644 index 0000000..de6ffb3 --- /dev/null +++ b/out_attempt1.cpp @@ -0,0 +1,60 @@ +#include "./server/libaquery.h" +#include +#include "./server/hasher.h" +#include "csv.h" +#include "./server/aggregations.h" + + extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { + using namespace std; + using namespace types; + + auto sale = new TableInfo("sale", 2); +cxt->tables.insert({"sale", sale}); +auto& sale_Month = *(ColRef *)(&sale->colrefs[0]); +auto& sale_sales = *(ColRef *)(&sale->colrefs[1]); +sale_Month.init(); +sale_sales.init(); +io::CSVReader<2> csv_reader_53ychC("moving_avg.csv"); +csv_reader_53ychC.read_header(io::ignore_extra_column, "Month","sales"); +int tmp_7ttMnHd3; +int tmp_5nHjeAtP; +while(csv_reader_53ychC.read_row(tmp_7ttMnHd3,tmp_5nHjeAtP)) { + +sale_Month.emplace_back(tmp_7ttMnHd3); +sale_sales.emplace_back(tmp_5nHjeAtP); +} +auto out_3Xio = new TableInfo,decays>("out_3Xio", 2); +cxt->tables.insert({"out_3Xio", out_3Xio}); +auto& out_3Xio_Month = *(ColRef> *)(&out_3Xio->colrefs[0]); +auto& out_3Xio_avgsw3salesales = *(ColRef> *)(&out_3Xio->colrefs[1]); +out_3Xio_Month.init(); +out_3Xio_Month = sale_Month; +out_3Xio_avgsw3salesales.init(); +out_3Xio_avgsw3salesales = avgw(3,sale_sales); +// print(*out_3Xio); +FILE* fp_4nKGhD = fopen("moving_avg_output.csv", "w"); +out_3Xio->printall(",", "\n", nullptr, fp_4nKGhD); +fclose(fp_4nKGhD); +typedef record record_type1H2vDGL; +unordered_map, transTypes> g6Mjxfk5; +for (uint32_t i7u = 0; i7u < sale_sales.size; ++i7u){ +g6Mjxfk5[forward_as_tuple(sale_sales[i7u])].emplace_back(i7u); +} +auto out_2IU2 = new TableInfo,decays>("out_2IU2", 2); +cxt->tables.insert({"out_2IU2", out_2IU2}); +auto& out_2IU2_sales = *(ColRef> *)(&out_2IU2->colrefs[0]); +auto& out_2IU2_minsw2saleMonth = *(ColRef> *)(&out_2IU2->colrefs[1]); +out_2IU2_sales.init(); +out_2IU2_minsw2saleMonth.init(); +for(auto& i5J : g6Mjxfk5) { +auto &key_4jl5toH = i5J.first; +auto &val_VJGwVwH = i5J.second; +out_2IU2_sales.emplace_back(get<0>(key_4jl5toH)); +out_2IU2_minsw2saleMonth.emplace_back(minw(2,sale_Month[val_VJGwVwH])); +} +// print(*out_2IU2); +FILE* fp_18R4fY = fopen("flatten.csv", "w"); +out_2IU2->printall(",","\n", nullptr, fp_18R4fY); +fclose(fp_18R4fY); +return 0; +} \ No newline at end of file diff --git a/server/aggregations.h b/server/aggregations.h index 71de8aa..8bd79b5 100644 --- a/server/aggregations.h +++ b/server/aggregations.h @@ -39,10 +39,10 @@ T min(const VT& v) { return min_v; } template class VT> -VT mins(const VT& arr) { - const int& len = arr.size; +decayed_t mins(const VT& arr) { + const uint32_t& len = arr.size; std::deque> cache; - VT ret(len); + decayed_t ret(len); T min = std::numeric_limits::max(); for (int i = 0; i < len; ++i) { if (arr[i] < min) @@ -52,9 +52,9 @@ VT mins(const VT& arr) { return ret; } template class VT> -VT maxs(const VT& arr) { - const int& len = arr.size; - VT ret(len); +decayed_t maxs(const VT& arr) { + const uint32_t& len = arr.size; + decayed_t ret(len); T max = std::numeric_limits::min(); for (int i = 0; i < len; ++i) { if (arr[i] > max) @@ -65,9 +65,9 @@ VT maxs(const VT& arr) { } template class VT> -VT minw(const VT& arr, uint32_t w) { - const int& len = arr.size; - VT ret(len); +decayed_t minw(uint32_t w, const VT& arr) { + const uint32_t& len = arr.size; + decayed_t ret{len}; std::deque> cache; for (int i = 0; i < len; ++i) { if (!cache.empty() && cache.front().second == i - w) cache.pop_front(); @@ -79,9 +79,9 @@ VT minw(const VT& arr, uint32_t w) { } template class VT> -VT maxw(const VT& arr, uint32_t w) { - const int& len = arr.size; - VT ret(len); +decayed_t maxw(uint32_t w, const VT& arr) { + const uint32_t& len = arr.size; + decayed_t ret(len); std::deque> cache; for (int i = 0; i < len; ++i) { if (!cache.empty() && cache.front().second == i - w) cache.pop_front(); @@ -91,15 +91,44 @@ VT maxw(const VT& arr, uint32_t w) { } return ret; } - +template class VT> +decayed_t> sumw(uint32_t w, const VT& arr) { + const uint32_t& len = arr.size; + decayed_t> ret(len); + uint32_t i = 0; + w = w > len ? len : w; + if(arr.size) + ret[i++] = arr[0]; + for (; i < w; ++i) + ret[i] = ret[i-1] + arr[i]; + for (; i < len; ++i) + ret[i] = ret[i-1] + arr[i] - arr[i-w]; + return ret; +} +template class VT> +decayed_t> avgw(uint32_t w, const VT& arr) { + typedef types::GetFPType FPType; + const uint32_t& len = arr.size; + decayed_t ret(len); + uint32_t i = 0; + types::GetLongType s; + w = w > len ? len : w; + if(arr.size) + s = ret[i++] = arr[0]; + for (; i < w; ++i) + ret[i] = (s += arr[i])/(FPType)(i+1); + for (; i < len; ++i) + ret[i] = ret[i-1] + (arr[i] - arr[i-w])/(FPType)w; + return ret; +} template constexpr inline T max(const T& v) { return v; } template constexpr inline T min(const T& v) { return v; } template constexpr inline T avg(const T& v) { return v; } template constexpr inline T sum(const T& v) { return v; } -template constexpr inline T maxw(const T& v, uint32_t) { return v; } -template constexpr inline T minw(const T& v, uint32_t) { return v; } -template constexpr inline T avgw(const T& v, uint32_t) { return v; } -template constexpr inline T sumw(const T& v, uint32_t) { return v; } +template constexpr inline T maxw(uint32_t, const T& v) { return v; } +template constexpr inline T minw(uint32_t, const T& v) { return v; } +template constexpr inline T avgw(uint32_t, const T& v) { return v; } +template constexpr inline T sumw(uint32_t, const T& v) { return v; } template constexpr inline T maxs(const T& v) { return v; } template constexpr inline T mins(const T& v) { return v; } template constexpr inline T avgs(const T& v) { return v; } diff --git a/server/io.h b/server/io.h index ad7835b..43be108 100644 --- a/server/io.h +++ b/server/io.h @@ -2,14 +2,14 @@ #include "types.h" #include #include -#include -#include template std::string generate_printf_string(const char* sep = " ", const char* end = "\n") { std::string str; - (void)std::initializer_list{ - (str += types::printf_str[types::Types::getType()], str += sep, 0)... - }; + ((str += types::printf_str[types::Types>::getType()], str += sep), ...); + const auto trim = str.size() - strlen(sep); + if (trim > 0) + str.resize(trim); str += end; return str; } + diff --git a/server/server.cpp b/server/server.cpp index fe06af1..934cfe1 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -98,7 +98,7 @@ int _main() } dlclose(handle); } - static_assert(std::is_same_v()), std::integer_sequence>, ""); + //static_assert(std::is_same_v()), std::integer_sequence>, ""); return 0; } diff --git a/server/server.sln b/server/server.sln index 598688f..d22be11 100644 --- a/server/server.sln +++ b/server/server.sln @@ -10,30 +10,48 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server.vcxproj", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msc-plugin", "..\msc-plugin\msc-plugin.vcxproj", "{8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}" EndProject +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "msvs-py", "..\msvs-py\msvs-py.pyproj", "{CCC243F5-663E-45B7-A6DE-B2468C58B3A7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|Any CPU.ActiveCfg = Debug|x64 + {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|Any CPU.Build.0 = Debug|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.ActiveCfg = Debug|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x64.Build.0 = Debug|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.ActiveCfg = Debug|Win32 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Debug|x86.Build.0 = Debug|Win32 + {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|Any CPU.ActiveCfg = Release|x64 + {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|Any CPU.Build.0 = Release|x64 {031352C2-AFBB-45AA-9518-DBC1F9EF2AF3}.Release|x64.ActiveCfg = Release|x64 {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|Any CPU.ActiveCfg = Debug|x64 + {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Debug|Any CPU.Build.0 = Debug|x64 {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|Any CPU.ActiveCfg = Release|x64 + {8081FDAA-4D13-4B7A-ADB2-8224AF7F1C81}.Release|Any CPU.Build.0 = Release|x64 {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 + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|x64.ActiveCfg = Debug|Any CPU + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Debug|x86.ActiveCfg = Debug|Any CPU + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|x64.ActiveCfg = Release|Any CPU + {CCC243F5-663E-45B7-A6DE-B2468C58B3A7}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/server/server.vcxproj b/server/server.vcxproj index 03f1f79..92de8fb 100644 --- a/server/server.vcxproj +++ b/server/server.vcxproj @@ -167,6 +167,7 @@ + diff --git a/server/table.h b/server/table.h index ffbe96b..49ce40c 100644 --- a/server/table.h +++ b/server/table.h @@ -6,6 +6,8 @@ #include "types.h" #include "vector_type.hpp" #include +#include +#include "io.h" template class vector_type; template <> @@ -26,8 +28,10 @@ template class ColRef : public vector_type<_Ty> { public: + typedef ColRef<_Ty> Decayed_t; const char* name; types::Type_t ty = types::ERROR; + ColRef() : vector_type<_Ty>(0), 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; } @@ -37,6 +41,14 @@ public: ColView<_Ty> operator [](const vector_type&idxs) const { return ColView<_Ty>(*this, idxs); } + + void out(uint32_t n = 4, const char* sep = " ") const { + n = n > this->size ? this->size : n; + std::cout << '('; + for (uint32_t i = 0; i < n; ++i) + std::cout << this->operator[](i) << sep; + std::cout << ')'; + } template ColRef scast(); }; @@ -44,6 +56,7 @@ public: template class ColView { public: + typedef ColRef<_Ty> Decayed_t; const vector_type& idxs; const ColRef<_Ty>& orig; const uint32_t& size; @@ -77,8 +90,22 @@ public: Iterator_t end() const { return Iterator_t(idxs.end(), orig); } + void out(uint32_t n = 4, const char* sep = " ") const { + n = n > size ? size : n; + std::cout<<'('; + for (uint32_t i = 0; i < n; ++i) + std::cout << this->operator[](i)<< sep; + std::cout << ')'; + } }; - +template