update
This commit is contained in:
+15
@@ -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;
|
||||
}
|
||||
};
|
||||
+4
-1
@@ -75,6 +75,7 @@ int main(int argc, char** argv) {
|
||||
shm.FreeMemoryMap();
|
||||
return 0;
|
||||
}
|
||||
#include "utils.h"
|
||||
int _main()
|
||||
{
|
||||
|
||||
@@ -83,6 +84,7 @@ int _main()
|
||||
//t.emplace_back(2);
|
||||
//print(t);
|
||||
//return 0;
|
||||
puts(cpp_17 ?"true":"false");
|
||||
void* handle = dlopen("dll.so", RTLD_LAZY);
|
||||
printf("handle: %x\n", handle);
|
||||
Context* cxt = new Context();
|
||||
@@ -96,7 +98,8 @@ int _main()
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@
|
||||
<ClInclude Include="gc.hpp" />
|
||||
<ClInclude Include="hasher.h" />
|
||||
<ClInclude Include="libaquery.h" />
|
||||
<ClInclude Include="priority_vector.hpp" />
|
||||
<ClInclude Include="table.h" />
|
||||
<ClInclude Include="types.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
@@ -175,10 +176,4 @@
|
||||
<ClInclude Include="winhelper.h" />
|
||||
</ItemGroup>
|
||||
<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>
|
||||
+107
-41
@@ -1,3 +1,5 @@
|
||||
// TODO: Replace `cout, printf` with sprintf&fputs and custom buffers
|
||||
|
||||
#ifndef _TABLE_H
|
||||
#define _TABLE_H
|
||||
|
||||
@@ -85,13 +87,31 @@ inline ColRef<T> ColRef<_Ty>::scast()
|
||||
return *(ColRef<T> *)this;
|
||||
}
|
||||
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>
|
||||
struct TableInfo {
|
||||
const char* name;
|
||||
ColRef<void>* colrefs;
|
||||
uint32_t n_cols;
|
||||
void print(const char* __restrict sep, const char* __restrict end) const;
|
||||
typedef std::tuple<Types...> tuple_type;
|
||||
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>
|
||||
@@ -103,46 +123,60 @@ struct TableInfo {
|
||||
template <size_t ...Idxs>
|
||||
using getRecordType = typename GetTypes<Idxs...>::type;
|
||||
TableInfo(const char* name, uint32_t n_cols);
|
||||
//template<size_t ...Idxs = Types...>
|
||||
//struct Iterator_t {
|
||||
// uint32_t val;
|
||||
// const TableInfo* info;
|
||||
// constexpr Iterator_t(const uint32_t* val, const TableInfo* info) noexcept : val(val), info(info) {}
|
||||
// getRecordType<Idxs...> operator*() {
|
||||
// return getRecordType<Idxs...>(info->colrefs[Idxs].operator[](*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;
|
||||
// }
|
||||
//};
|
||||
//template<size_t ...Idxs = Types...>
|
||||
//Iterator_t<Idxs...> begin() const {
|
||||
//
|
||||
//}
|
||||
//template<size_t ...Idxs = Types...>
|
||||
//Iterator_t<Idxs...> end() const {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//template<int ...Cols, bool ...ord>
|
||||
//order_by() {
|
||||
// vector_type<uint32_t> order(colrefs[0].size);
|
||||
// std::sort(this->begin<Cols>)
|
||||
//}
|
||||
template <int prog = 0>
|
||||
inline void materialize(const vector_type<uint32_t>& idxs, TableInfo<Types...>* tbl = nullptr) { // inplace materialize
|
||||
if constexpr(prog == 0) tbl = 0 ? this : tbl;
|
||||
if constexpr (prog == sizeof...(Types)) return;
|
||||
else {
|
||||
auto& col = get<prog>(*this);
|
||||
auto new_col = decays<decltype(col)>{idxs.size};
|
||||
for(uint32_t i = 0; i < idxs.size; ++i)
|
||||
new_col[i] = col[idxs[i]];
|
||||
get<prog>(*tbl) = new_col;
|
||||
materialize<prog + 1>();
|
||||
}
|
||||
}
|
||||
inline TableInfo<Types...>* materialize_copy(const vector_type<uint32_t>& idxs) {
|
||||
auto tbl = new TableInfo<Types...>(this->name, sizeof...(Types));
|
||||
materialize<0>(idxs, tbl);
|
||||
return tbl;
|
||||
}
|
||||
template<int ...cols>
|
||||
inline vector_type<uint32_t>* order_by() {
|
||||
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;
|
||||
std::sort(ord->begin(), ord->end(), [this](const uint32_t& lhs, const uint32_t& rhs) {
|
||||
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]) ...);
|
||||
});
|
||||
return ord;
|
||||
}
|
||||
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>
|
||||
constexpr static inline bool is_vector(const ColRef<T>&) {
|
||||
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) {
|
||||
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 <size_t j>
|
||||
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") {
|
||||
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>
|
||||
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>
|
||||
void inline print_impl(const T& v, const char* delimiter, const char* endline) {
|
||||
for (const auto& vi : v) {
|
||||
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>
|
||||
|
||||
+11
-1
@@ -118,6 +118,16 @@ struct decayS <T<Types...>>{
|
||||
using type = T<typename std::decay<Types>::type ...>;
|
||||
};
|
||||
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
|
||||
|
||||
+13
-15
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
|
||||
constexpr static bool cpp_17 = true;
|
||||
#else
|
||||
constexpr static bool cpp_17 = false;
|
||||
#endif
|
||||
template <class T>
|
||||
inline const char* str(const T& v) {
|
||||
return "";
|
||||
}
|
||||
template <>
|
||||
inline const char* str(const bool& v) {
|
||||
return v ? "true" : "false";
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
template <typename _Ty>
|
||||
class vector_type {
|
||||
public:
|
||||
void inline _copy(vector_type<_Ty>& vt) {
|
||||
void inline _copy(const vector_type<_Ty>& vt) {
|
||||
this->size = vt.size;
|
||||
this->capacity = vt.capacity;
|
||||
this->container = (_Ty*)malloc(size * sizeof(_Ty));
|
||||
@@ -30,6 +30,8 @@ public:
|
||||
memcpy(container, vt.container, sizeof(_Ty) * size);
|
||||
}
|
||||
void inline _move(vector_type<_Ty>&& vt) {
|
||||
if (capacity > 0) free(container);
|
||||
|
||||
this->size = vt.size;
|
||||
this->capacity = vt.capacity;
|
||||
this->container = vt.container;
|
||||
@@ -52,7 +54,7 @@ public:
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
constexpr vector_type(vector_type<_Ty>&& vt) noexcept {
|
||||
@@ -67,7 +69,7 @@ public:
|
||||
container[0] = vt;
|
||||
return *this;
|
||||
}
|
||||
vector_type<_Ty> operator =(vector_type<_Ty>& vt) {
|
||||
vector_type<_Ty> operator =(const vector_type<_Ty>& vt) {
|
||||
_copy(vt);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user