Merge branch 'master' of https://github.com/sunyinqi0508/AQuery2
This commit is contained in:
+19
-7
@@ -107,18 +107,26 @@ decayed_t<VT, T> maxw(uint32_t w, const VT<T>& arr) {
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<T>> ratios(const VT<T>& arr) {
|
||||
uint32_t len = arr.size - 1;
|
||||
if (!arr.size)
|
||||
decayed_t<VT, types::GetFPType<T>> ratiow(uint32_t w, const VT<T>& arr) {
|
||||
typedef std::decay_t<types::GetFPType<T>> FPType;
|
||||
uint32_t len = arr.size;
|
||||
if (arr.size <= w)
|
||||
len = 1;
|
||||
decayed_t<VT, types::GetFPType<T>> ret(len);
|
||||
w = w > len ? len : w;
|
||||
decayed_t<VT, FPType> ret(arr.size);
|
||||
ret[0] = 0;
|
||||
|
||||
for (uint32_t i = 1; i < arr.size; ++i)
|
||||
ret[i - 1] = arr[i] / arr[i - 1];
|
||||
for (uint32_t i = 0; i < w; ++i)
|
||||
ret[i] = arr[i] / (FPType)arr[0];
|
||||
for (uint32_t i = w; i < arr.size; ++i)
|
||||
ret[i] = arr[i] / (FPType) arr[i - w];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<T>> ratios(const VT<T>& arr) {
|
||||
return ratiow(1, arr);
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetLongType<T>> sums(const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
@@ -129,6 +137,7 @@ decayed_t<VT, types::GetLongType<T>> sums(const VT<T>& arr) {
|
||||
ret[i] = ret[i - 1] + arr[i];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<types::GetLongType<T>>> avgs(const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
@@ -141,6 +150,7 @@ decayed_t<VT, types::GetFPType<types::GetLongType<T>>> avgs(const VT<T>& arr) {
|
||||
ret[i] = (s += arr[i]) / (FPType)(i + 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetLongType<T>> sumw(uint32_t w, const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
@@ -154,6 +164,7 @@ decayed_t<VT, types::GetLongType<T>> sumw(uint32_t w, const VT<T>& arr) {
|
||||
ret[i] = ret[i - 1] + arr[i] - arr[i - w];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<types::GetLongType<T>>> avgw(uint32_t w, const VT<T>& arr) {
|
||||
typedef types::GetFPType<types::GetLongType<T>> FPType;
|
||||
@@ -209,6 +220,7 @@ template <class T> constexpr inline T maxw(uint32_t, const T& v) { return v; }
|
||||
template <class T> constexpr inline T minw(uint32_t, const T& v) { return v; }
|
||||
template <class T> constexpr inline T avgw(uint32_t, const T& v) { return v; }
|
||||
template <class T> constexpr inline T sumw(uint32_t, const T& v) { return v; }
|
||||
template <class T> constexpr inline T ratiow(uint32_t, const T& v) { return 1; }
|
||||
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; }
|
||||
|
||||
+43
-3
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <functional>
|
||||
#include "types.h"
|
||||
// only works for 64 bit systems
|
||||
constexpr size_t _FNV_offset_basis = 14695981039346656037ULL;
|
||||
@@ -21,7 +22,31 @@ inline size_t append_bytes(const astring_view& view) noexcept {
|
||||
return append_bytes(view.str);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
union int128_struct
|
||||
{
|
||||
struct {
|
||||
uint64_t low, high;
|
||||
}__struct;
|
||||
__int128_t value = 0;
|
||||
__uint128_t uvalue;
|
||||
constexpr int128_struct() : value(0) {}
|
||||
constexpr int128_struct(const __int128_t &value) noexcept : value(value) {}
|
||||
constexpr int128_struct(const __uint128_t &value) noexcept : uvalue(value) {}
|
||||
operator __int128_t () const {
|
||||
return value;
|
||||
}
|
||||
operator __uint128_t () const {
|
||||
return uvalue;
|
||||
}
|
||||
operator __int128_t& () {
|
||||
return value;
|
||||
}
|
||||
operator __uint128_t& () {
|
||||
return uvalue;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
template <class ...Types>
|
||||
struct hasher {
|
||||
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
|
||||
@@ -32,8 +57,15 @@ struct hasher {
|
||||
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);
|
||||
#ifdef __SIZEOF_INT128__
|
||||
using _current_type = typename std::conditional_t<
|
||||
std::is_same_v<current_type, __uint128_t> ||
|
||||
std::is_same_v<current_type, __int128_t>,
|
||||
int128_struct, current_type>;
|
||||
#else
|
||||
#define _current_type current_type
|
||||
#endif
|
||||
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);
|
||||
@@ -75,7 +107,15 @@ namespace std{
|
||||
std::hash<types::time_t>()(_Keyval.time);
|
||||
}
|
||||
};
|
||||
#ifdef __SIZEOF_INT128__
|
||||
|
||||
template<>
|
||||
struct hash<int128_struct>{
|
||||
size_t operator() (const int128_struct& _Keyval) const noexcept {
|
||||
return std::hash<uint64_t>()(_Keyval.__struct.low) ^ std::hash<uint64_t>()(_Keyval.__struct.high);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
template <class ...Types>
|
||||
struct hash<std::tuple<Types...>> : public hasher<Types...>{ };
|
||||
|
||||
|
||||
+13
-13
@@ -265,16 +265,16 @@ string base62uuid(int l) {
|
||||
}
|
||||
|
||||
|
||||
template<typename _Ty>
|
||||
inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
|
||||
{
|
||||
n = n > size ? size : n;
|
||||
std::cout << '(';
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (; i < n - 1; ++i)
|
||||
std::cout << this->operator[](i) << sep;
|
||||
std::cout << this->operator[](i);
|
||||
}
|
||||
std::cout << ')';
|
||||
}
|
||||
// template<typename _Ty>
|
||||
// inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
|
||||
// {
|
||||
// n = n > size ? size : n;
|
||||
// std::cout << '(';
|
||||
// {
|
||||
// uint32_t i = 0;
|
||||
// for (; i < n - 1; ++i)
|
||||
// std::cout << this->operator[](i) << sep;
|
||||
// std::cout << this->operator[](i);
|
||||
// }
|
||||
// std::cout << ')';
|
||||
// }
|
||||
|
||||
+2
-2
@@ -176,10 +176,10 @@ int dll_main(int argc, char** argv, Context* cxt){
|
||||
//getlasterror
|
||||
|
||||
if (!user_module_handle)
|
||||
#ifndef _MSC_VER
|
||||
#ifndef _WIN32
|
||||
puts(dlerror());
|
||||
#else
|
||||
printf("Fatal Error: Module %s failed to load with error code %d.\n", mname, GetLastError());
|
||||
printf("Fatal Error: Module %s failed to load with error code %d.\n", mname, dlerror());
|
||||
#endif
|
||||
user_module_map[mname] = user_module_handle;
|
||||
initialize_module(mname, user_module_handle, cxt);
|
||||
|
||||
+104
-46
@@ -129,8 +129,8 @@ public:
|
||||
}
|
||||
|
||||
// defined in table_ext_monetdb.hpp
|
||||
void* monetdb_get_col();
|
||||
|
||||
void* monetdb_get_col(void** gc_vecs, uint32_t& cnt);
|
||||
|
||||
};
|
||||
template<>
|
||||
class ColRef<void> : public ColRef<int> {};
|
||||
@@ -391,11 +391,11 @@ struct TableInfo {
|
||||
constexpr auto num_date = count_type<types::date_t>((tuple_type*)(0));
|
||||
constexpr auto num_time = count_type<types::time_t>((tuple_type*)(0));
|
||||
constexpr auto num_timestamp = count_type<types::timestamp_t>((tuple_type*)(0));
|
||||
char cbuf[num_hge * 41
|
||||
+ num_time * types::time_t::string_length()
|
||||
+ num_date * types::date_t::string_length()
|
||||
+ num_timestamp * types::timestamp_t::string_length()
|
||||
+ 1
|
||||
char cbuf[ num_hge * 41
|
||||
+ num_time * types::time_t::string_length()
|
||||
+ num_date * types::date_t::string_length()
|
||||
+ num_timestamp * types::timestamp_t::string_length()
|
||||
+ 1 // padding for msvc not allowing empty arrays
|
||||
];
|
||||
setgbuf(cbuf);
|
||||
if (view)
|
||||
@@ -625,106 +625,164 @@ inline void TableInfo<Types...>::print(const char* __restrict sep, const char* _
|
||||
std::cout << end;
|
||||
}
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1,
|
||||
template<typename> class VT,
|
||||
class TRet>
|
||||
using test_vt_support = typename std::enable_if_t<std::is_same_v<VT<T1>, ColRef<T1>> ||
|
||||
std::is_same_v<VT<T1>, ColView<T1>> ||
|
||||
std::is_same_v<VT<T1>, vector_type<T1>>, TRet>;
|
||||
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT>
|
||||
using get_autoext_type = test_vt_support<T1, VT,
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type>>;
|
||||
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT>
|
||||
using get_long_type = test_vt_support<T1, VT,
|
||||
decayed_t<VT, types::GetLongType<typename types::Coercion<T1, T2>::type>>>;
|
||||
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT>
|
||||
using get_fp_type = test_vt_support<T1, VT,
|
||||
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>>;
|
||||
|
||||
template <class T1,
|
||||
template<typename> class VT, template<typename> class VT2,
|
||||
class TRet>
|
||||
using test_vt_support2 = typename std::enable_if_t<(std::is_same_v<VT<T1>, ColRef<T1>> ||
|
||||
std::is_same_v<VT<T1>, ColView<T1>> ||
|
||||
std::is_same_v<VT<T1>, vector_type<T1>>) &&
|
||||
(std::is_same_v<VT2<T1>, ColRef<T1>> ||
|
||||
std::is_same_v<VT2<T1>, ColView<T1>> ||
|
||||
std::is_same_v<VT2<T1>, vector_type<T1>>), TRet >;
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT, template<typename> class VT2>
|
||||
using get_autoext_type2 = test_vt_support2<T1, VT, VT2,
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type>>;
|
||||
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT, template<typename> class VT2>
|
||||
using get_long_type2 = test_vt_support2<T1, VT, VT2,
|
||||
decayed_t<VT, types::GetLongType<typename types::Coercion<T1, T2>::type>>>;
|
||||
|
||||
template <class T1, class T2,
|
||||
template<typename> class VT, template<typename> class VT2>
|
||||
using get_fp_type2 = test_vt_support2<T1, VT, VT2,
|
||||
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>>;
|
||||
|
||||
template <class T1, class T2, template<typename> class VT, template<typename> class VT2>
|
||||
get_autoext_type2<T1, T2, VT, VT2>
|
||||
operator -(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = get_autoext_type2<T1, T2, VT, VT2>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] - rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_autoext_type<T1, T2, VT>
|
||||
operator -(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = get_autoext_type<T1, T2, VT>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] - rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_autoext_type<T1, T2, VT>
|
||||
operator -(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = get_autoext_type<T1, T2, VT>(rhs.size);
|
||||
for (uint32_t i = 0; i < rhs.size; ++i)
|
||||
ret[i] = lhs - rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT, template<typename> class VT2>
|
||||
get_autoext_type2<T1, T2, VT, VT2>
|
||||
operator +(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = get_autoext_type2<T1, T2, VT, VT2>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] + rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_autoext_type<T1, T2, VT>
|
||||
operator +(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = get_autoext_type<T1, T2, VT>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] + rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_autoext_type<T1, T2, VT>
|
||||
operator +(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = get_autoext_type<T1, T2, VT> (rhs.size);
|
||||
for (uint32_t i = 0; i < rhs.size; ++i)
|
||||
ret[i] = lhs + rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT, template<typename> class VT2>
|
||||
get_long_type2<T1, T2, VT, VT2>
|
||||
operator *(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = get_long_type2<T1, T2, VT, VT2>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] * rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_long_type<T1, T2, VT>
|
||||
operator *(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = get_long_type<T1, T2, VT>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] * rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_long_type<T1, T2, VT>
|
||||
operator *(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = get_long_type<T1, T2, VT>(rhs.size);
|
||||
for (uint32_t i = 0; i < rhs.size; ++i)
|
||||
ret[i] = lhs * rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
|
||||
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT, template<typename> class VT2>
|
||||
get_fp_type2<T1, T2, VT, VT2>
|
||||
operator /(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = get_fp_type2<T1, T2, VT, VT2>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] / rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_fp_type<T1, T2, VT>
|
||||
operator /(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = get_fp_type<T1, T2, VT>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] / rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(rhs.size);
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
get_fp_type<T1, T2, VT>
|
||||
operator /(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = get_fp_type<T1, T2, VT>(rhs.size);
|
||||
for (uint32_t i = 0; i < rhs.size; ++i)
|
||||
ret[i] = lhs / rhs[i];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
|
||||
template <class T1, class T2, template<typename> class VT, template<typename> class VT2>
|
||||
VT<bool> operator >(const VT<T1>& lhs, const VT2<T2>& rhs) {
|
||||
auto ret = VT<bool>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] > rhs[i];
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
VT<bool> operator >(const VT<T1>& lhs, const T2& rhs) {
|
||||
auto ret = VT<bool>(lhs.size);
|
||||
for (uint32_t i = 0; i < lhs.size; ++i)
|
||||
ret[i] = lhs[i] > rhs;
|
||||
return ret;
|
||||
}
|
||||
template <class T1, class T2, template<typename ...> class VT>
|
||||
template <class T1, class T2, template<typename> class VT>
|
||||
VT<bool> operator >(const T2& lhs, const VT<T1>& rhs) {
|
||||
auto ret = VT<bool>(rhs.size);
|
||||
for (uint32_t i = 0; i < rhs.size; ++i)
|
||||
|
||||
@@ -22,7 +22,12 @@ inline constexpr monetdbe_types AQType_2_monetdbe[] = {
|
||||
#else
|
||||
monetdbe_int64_t,
|
||||
#endif
|
||||
monetdbe_int16_t, monetdbe_int8_t, monetdbe_bool, monetdbe_int64_t,
|
||||
monetdbe_int16_t, monetdbe_int8_t, monetdbe_bool,
|
||||
#ifdef HAVE_HGE
|
||||
monetdbe_int128_t,
|
||||
#else
|
||||
monetdbe_int64_t,
|
||||
#endif
|
||||
monetdbe_timestamp, monetdbe_int64_t, monetdbe_int64_t
|
||||
};
|
||||
|
||||
@@ -35,19 +40,22 @@ void TableInfo<Ts ...>::monetdb_append_table(void* srv, const char* alt_name) {
|
||||
monetdbe_column** monetdbe_cols = new monetdbe_column * [sizeof...(Ts)];
|
||||
|
||||
uint32_t i = 0;
|
||||
constexpr auto n_vecs = count_vector_type((tuple_type*)(0));
|
||||
void* gc_vecs[1 + n_vecs];
|
||||
puts("getcols...");
|
||||
const auto get_col = [&monetdbe_cols, &i, *this](auto v) {
|
||||
uint32_t cnt = 0;
|
||||
const auto get_col = [&monetdbe_cols, &i, *this, &gc_vecs, &cnt](auto v) {
|
||||
printf("%d %d\n", i, (ColRef<void>*)v - colrefs);
|
||||
monetdbe_cols[i++] = (monetdbe_column*)v->monetdb_get_col();
|
||||
monetdbe_cols[i++] = (monetdbe_column*)v->monetdb_get_col(gc_vecs, cnt);
|
||||
};
|
||||
(get_col((ColRef<Ts>*)(colrefs + i)), ...);
|
||||
puts("getcols done");
|
||||
for(int i = 0; i < sizeof...(Ts); ++i)
|
||||
{
|
||||
printf("no:%d name: %s count:%d data: %p \n",
|
||||
i, monetdbe_cols[i]->name, monetdbe_cols[i]->count, monetdbe_cols[i]->data);
|
||||
printf("no:%d name: %s count:%d data: %p type:%d \n",
|
||||
i, monetdbe_cols[i]->name, monetdbe_cols[i]->count, monetdbe_cols[i]->data, monetdbe_cols[i]->type);
|
||||
}
|
||||
std::string create_table_str = "CREATE TABLE ";
|
||||
std::string create_table_str = "CREATE TABLE IF NOT EXISTS ";
|
||||
create_table_str += alt_name;
|
||||
create_table_str += " (";
|
||||
i = 0;
|
||||
@@ -70,12 +78,14 @@ void TableInfo<Ts ...>::monetdb_append_table(void* srv, const char* alt_name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// for(uint32_t i = 0; i < n_vecs; ++i)
|
||||
// free(gc_vecs[i]);
|
||||
puts("Error! Empty table.");
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void* ColRef<Type>::monetdb_get_col() {
|
||||
void* ColRef<Type>::monetdb_get_col(void** gc_vecs, uint32_t& cnt) {
|
||||
auto aq_type = AQType_2_monetdbe[types::Types<Type>::getType()];
|
||||
monetdbe_column* col = (monetdbe_column*)malloc(sizeof(monetdbe_column));
|
||||
|
||||
@@ -83,7 +93,13 @@ void* ColRef<Type>::monetdb_get_col() {
|
||||
col->count = this->size;
|
||||
col->data = this->container;
|
||||
col->name = const_cast<char*>(this->name);
|
||||
|
||||
// auto arr = (types::timestamp_t*) malloc (sizeof(types::timestamp_t)* this->size);
|
||||
// if constexpr (is_vector_type<Type>){
|
||||
// for(uint32_t i = 0; i < this->size; ++i){
|
||||
// memcpy(arr + i, this->container + i, sizeof(types::timestamp_t));
|
||||
// }
|
||||
// gc_vecs[cnt++] = arr;
|
||||
// }
|
||||
return col;
|
||||
}
|
||||
|
||||
|
||||
+46
-29
@@ -3,6 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
using std::size_t;
|
||||
|
||||
#if defined(__SIZEOF_INT128__) and not defined(_WIN32)
|
||||
#define __AQ__HAS__INT128__
|
||||
@@ -29,9 +30,9 @@ namespace types {
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%d", "%hi", "%s", "%s", "%c",
|
||||
"%u", "%lu", "%s", "%hu", "%hhu", "%s", "%s", "Vector<%s>", "%s", "NULL", "ERROR" };
|
||||
static constexpr const char* SQL_Type[] = { "INT", "REAL", "TEXT", "DOUBLE", "DOUBLE", "BIGINT", "HUGEINT", "SMALLINT", "DATE", "TIME", "TINYINT",
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BOOL", "BLOB", "TIMESTAMP", "NULL", "ERROR" };
|
||||
|
||||
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BOOL", "HUGEINT", "TIMESTAMP", "NULL", "ERROR"};
|
||||
|
||||
|
||||
// TODO: deal with data/time <=> str/uint conversion
|
||||
struct date_t {
|
||||
unsigned char day = 0;
|
||||
@@ -168,23 +169,22 @@ namespace types {
|
||||
template<class T>
|
||||
using GetLongType = typename GetLongTypeImpl<typename std::decay<T>::type>::type;
|
||||
|
||||
|
||||
template<class T>
|
||||
struct GetLongerTypeImpl {
|
||||
using type = Cond(
|
||||
|
||||
__U(T), Cond(__Eq(char), unsigned short,
|
||||
Cond(__Eq(short), unsigned int,
|
||||
Cond(__Eq(int), unsigned long long,
|
||||
Cond(__Eq(short), unsigned int,
|
||||
Cond(__Eq(int), unsigned long long,
|
||||
ULL_Type
|
||||
))),
|
||||
))),
|
||||
|
||||
Cond(Fp(T), double,
|
||||
Cond(Fp(T), double,
|
||||
|
||||
Cond(__Eq(char), short,
|
||||
Cond(__Eq(short), int,
|
||||
Cond(__Eq(int), long,
|
||||
LL_Type
|
||||
Cond(__Eq(char), short,
|
||||
Cond(__Eq(short), int,
|
||||
Cond(__Eq(int), long,
|
||||
LL_Type
|
||||
))))
|
||||
|
||||
);
|
||||
@@ -194,22 +194,22 @@ namespace types {
|
||||
}
|
||||
|
||||
|
||||
struct astring_view {
|
||||
union astring_view {
|
||||
const unsigned char* str = 0;
|
||||
|
||||
#if defined(__clang__) || !defined(__GNUC__)
|
||||
const signed char* sstr;
|
||||
const char* rstr;
|
||||
size_t ptr;
|
||||
|
||||
|
||||
constexpr
|
||||
astring_view(const char* str) noexcept :
|
||||
rstr(str) {}
|
||||
constexpr
|
||||
#endif
|
||||
astring_view(const char* str) noexcept :
|
||||
str((const unsigned char*)(str)) {}
|
||||
#if defined(__clang__) || !defined(__GNUC__)
|
||||
constexpr
|
||||
#endif
|
||||
astring_view(const signed char* str) noexcept :
|
||||
str((const unsigned char*)(str)) {}
|
||||
astring_view(const signed char* str) noexcept :
|
||||
sstr(str) {}
|
||||
|
||||
constexpr
|
||||
astring_view(const unsigned char* str) noexcept :
|
||||
astring_view(const unsigned char* str) noexcept :
|
||||
str(str) {}
|
||||
constexpr astring_view() noexcept = default;
|
||||
|
||||
@@ -224,17 +224,28 @@ struct astring_view {
|
||||
}
|
||||
return !(*this_str || *other_str);
|
||||
}
|
||||
bool operator >(const astring_view& r) const {
|
||||
|
||||
bool operator >(const astring_view&r) const{
|
||||
auto this_str = str;
|
||||
auto other_str = r.str;
|
||||
bool ret = true;
|
||||
while (*this_str && *other_str) {
|
||||
if (*this_str <= *other_str)
|
||||
ret = false;
|
||||
this_str++;
|
||||
other_str++;
|
||||
}
|
||||
|
||||
return (*this_str && !*other_str) ||
|
||||
(ret && !*this_str && *other_str);
|
||||
}
|
||||
operator const char* () const {
|
||||
return reinterpret_cast<const char*>(str);
|
||||
return rstr;
|
||||
}
|
||||
operator const unsigned char* () const {
|
||||
return reinterpret_cast<const unsigned char*>(str);
|
||||
return str;
|
||||
}
|
||||
operator const signed char* () const {
|
||||
return reinterpret_cast<const signed char*>(str);
|
||||
return sstr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -373,4 +384,10 @@ constexpr size_t count_type(std::tuple<Types...>* ts) {
|
||||
size_t t[] = { sum_type<Types, T1...>() ... };
|
||||
return sum_type(t, sizeof...(Types));
|
||||
}
|
||||
template<class ...Types>
|
||||
constexpr size_t count_vector_type(std::tuple<Types...>* ts) {
|
||||
size_t t[] = {is_vector_type<Types> ...};
|
||||
return sum_type(t, sizeof...(Types));
|
||||
}
|
||||
|
||||
#endif // !_TYPES_H
|
||||
|
||||
+24
-1
@@ -12,11 +12,16 @@
|
||||
#include <iterator>
|
||||
#include <initializer_list>
|
||||
#include <unordered_set>
|
||||
#include <iostream>
|
||||
#include "hasher.h"
|
||||
#include "types.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
template <typename _Ty>
|
||||
class slim_vector {
|
||||
|
||||
};
|
||||
template <typename _Ty>
|
||||
class vector_type {
|
||||
public:
|
||||
typedef vector_type<_Ty> Decayed_t;
|
||||
@@ -249,7 +254,25 @@ public:
|
||||
}
|
||||
size = this->size + dist;
|
||||
}
|
||||
void out(uint32_t n = 4, const char* sep = " ") const;
|
||||
inline void out(uint32_t n = 4, const char* sep = " ") const
|
||||
{
|
||||
const char* more = "";
|
||||
if (n < this->size)
|
||||
more = " ... ";
|
||||
else
|
||||
n = this->size;
|
||||
|
||||
std::cout << '(';
|
||||
if (n > 0)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (; i < n - 1; ++i)
|
||||
std::cout << this->operator[](i) << sep;
|
||||
std::cout << this->operator[](i);
|
||||
}
|
||||
std::cout<< more;
|
||||
std::cout << ')';
|
||||
}
|
||||
vector_type<_Ty> subvec_memcpy(uint32_t start, uint32_t end) const {
|
||||
vector_type<_Ty> subvec(end - start);
|
||||
memcpy(subvec.container, container + start, sizeof(_Ty) * (end - start));
|
||||
|
||||
@@ -20,6 +20,10 @@ int dlclose(void* handle)
|
||||
return FreeLibrary(static_cast<HMODULE>(handle));
|
||||
}
|
||||
|
||||
int dlerror() {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
SharedMemory::SharedMemory(const char* fname)
|
||||
{
|
||||
this->hFileMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 2, fname);
|
||||
|
||||
@@ -5,6 +5,8 @@ static constexpr int RTLD_LAZY = 1;
|
||||
void* dlopen(const char*, int);
|
||||
void* dlsym(void*, const char*);
|
||||
int dlclose(void*);
|
||||
int dlerror();
|
||||
|
||||
struct SharedMemory
|
||||
{
|
||||
void* hFileMap;
|
||||
|
||||
Reference in New Issue
Block a user