More Date/Time, Complex expr on groupby, bug fixes
This commit is contained in:
+31
-2
@@ -16,14 +16,16 @@ constexpr static inline size_t count(const T&) { return 1; }
|
||||
|
||||
// TODO: Specializations for dt/str/none
|
||||
template<class T, template<typename ...> class VT>
|
||||
types::GetLongType<T> sum(const VT<T>& v) {
|
||||
// types::GetLongType<T>
|
||||
LL_Type sum(const VT<T>& v) {
|
||||
types::GetLongType<T> ret = 0;
|
||||
for (const auto& _v : v)
|
||||
ret += _v;
|
||||
return ret;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
types::GetFPType<T> avg(const VT<T>& v) {
|
||||
//types::GetFPType<T>
|
||||
double avg(const VT<T>& v) {
|
||||
return static_cast<types::GetFPType<T>>(
|
||||
sum<T>(v) / static_cast<long double>(v.size));
|
||||
}
|
||||
@@ -156,6 +158,31 @@ decayed_t<VT, types::GetFPType<types::GetLongType<T>>> avgw(uint32_t w, const VT
|
||||
return ret;
|
||||
}
|
||||
|
||||
// use getSignedType
|
||||
template<class T, template<typename ...> class VT>
|
||||
decayed_t<VT, T> deltas(const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
decayed_t<VT, T> ret(len);
|
||||
uint32_t i = 0;
|
||||
if(len) ret[i++] = 0;
|
||||
for (; i < len; ++i)
|
||||
ret[i] = arr[i] - arr[i-1];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T, template<typename ...> class VT>
|
||||
T last(const VT<T>& arr) {
|
||||
const uint32_t& len = arr.size;
|
||||
decayed_t<VT, T> ret(len);
|
||||
uint32_t i = 0;
|
||||
if (len)
|
||||
ret[i++] = arr[0];
|
||||
for (; i < len; ++i)
|
||||
ret[i] = arr[i-1];
|
||||
return ret;
|
||||
}
|
||||
|
||||
// wrong behavior with count(0)
|
||||
template <class T> constexpr inline T count(const T& v) { return 1; }
|
||||
template <class T> constexpr inline T max(const T& v) { return v; }
|
||||
template <class T> constexpr inline T min(const T& v) { return v; }
|
||||
@@ -169,3 +196,5 @@ template <class T> constexpr inline T maxs(const T& v) { return v; }
|
||||
template <class T> constexpr inline T mins(const T& v) { return v; }
|
||||
template <class T> constexpr inline T avgs(const T& v) { return v; }
|
||||
template <class T> constexpr inline T sums(const T& v) { return v; }
|
||||
template <class T> constexpr inline T last(const T& v) { return v; }
|
||||
template <class T> constexpr inline T daltas(const T& v) { return 0; }
|
||||
|
||||
+192
-15
@@ -1,13 +1,15 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "io.h"
|
||||
|
||||
|
||||
|
||||
#include "table.h"
|
||||
#include <limits>
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
|
||||
#include "utils.h"
|
||||
#include <random>
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
char* gbuf = nullptr;
|
||||
|
||||
void setgbuf(char* buf) {
|
||||
@@ -18,6 +20,8 @@ void setgbuf(char* buf) {
|
||||
gbuf = buf;
|
||||
}
|
||||
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter){
|
||||
char s[41];
|
||||
@@ -40,6 +44,7 @@ std::ostream& operator<<(std::ostream& os, __uint128_t & v)
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <>
|
||||
@@ -47,25 +52,197 @@ void print<bool>(const bool&v, const char* delimiter){
|
||||
std::cout<< (v?"true":"false") << delimiter;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T getInt(const char*& buf){
|
||||
T ret = 0;
|
||||
while(*buf >= '0' and *buf <= '9'){
|
||||
ret = ret*10 + *buf - '0';
|
||||
buf++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class T>
|
||||
char* intToString(T val, char* buf){
|
||||
|
||||
while (val > 0){
|
||||
*--buf = val%10 + '0';
|
||||
val /= 10;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
void skip(const char*& buf){
|
||||
while(*buf && (*buf >'9' || *buf < '0')) buf++;
|
||||
}
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
namespace types {
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
string date_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
|
||||
date_t::date_t(const char* str) { fromString(str); }
|
||||
date_t& date_t::fromString(const char* str) {
|
||||
if(str) {
|
||||
skip(str);
|
||||
year = getInt<short>(str);
|
||||
skip(str);
|
||||
month = getInt<unsigned char>(str);
|
||||
skip(str);
|
||||
day = getInt<unsigned char>(str);
|
||||
}
|
||||
else{
|
||||
day = month = year = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
string time_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
bool date_t::validate() const{
|
||||
return year <= 9999 && month <= 12 && day <= 31;
|
||||
}
|
||||
|
||||
char* date_t::toString(char* buf) const {
|
||||
// if (!validate()) return "(invalid date)";
|
||||
*--buf = 0;
|
||||
buf = intToString(day, buf);
|
||||
*--buf = '-';
|
||||
buf = intToString(month, buf);
|
||||
*--buf = '-';
|
||||
buf = intToString(year, buf);
|
||||
return buf;
|
||||
}
|
||||
bool date_t::operator > (const date_t& other) const {
|
||||
return year > other.year || (year == other.year && (month > other.month || (month == other.month && day > other.day)));
|
||||
}
|
||||
|
||||
bool date_t::operator < (const date_t& other) const {
|
||||
return year < other.year || (year == other.year && (month < other.month || (month == other.month && day < other.day)));
|
||||
}
|
||||
|
||||
bool date_t::operator >= (const date_t& other) const {
|
||||
return year >= other.year || (year == other.year && (month >= other.month || (month == other.month && day >= other.day)));
|
||||
}
|
||||
|
||||
bool date_t::operator <= (const date_t& other) const {
|
||||
return year <= other.year || (year == other.year && (month <= other.month || (month == other.month && day <= other.day)));
|
||||
}
|
||||
|
||||
bool date_t::operator == (const date_t& other) const {
|
||||
return year == other.year && month == other.month && day == other.day;
|
||||
}
|
||||
|
||||
bool date_t::operator != (const date_t& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
time_t::time_t(const char* str) { fromString(str); }
|
||||
time_t& time_t::fromString(const char* str) {
|
||||
if(str) {
|
||||
skip(str);
|
||||
hours = getInt<unsigned char>(str);
|
||||
skip(str);
|
||||
minutes = getInt<unsigned char>(str);
|
||||
skip(str);
|
||||
seconds = getInt<unsigned char>(str);
|
||||
skip(str);
|
||||
ms = getInt<unsigned int> (str);
|
||||
}
|
||||
else {
|
||||
hours = minutes = seconds = ms = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
char* time_t::toString(char* buf) const {
|
||||
// if (!validate()) return "(invalid date)";
|
||||
*--buf = 0;
|
||||
buf = intToString(ms, buf);
|
||||
*--buf = ':';
|
||||
buf = intToString(seconds, buf);
|
||||
*--buf = ':';
|
||||
buf = intToString(minutes, buf);
|
||||
*--buf = ':';
|
||||
buf = intToString(hours, buf);
|
||||
return buf;
|
||||
}
|
||||
bool time_t::operator > (const time_t& other) const {
|
||||
return hours > other.hours || (hours == other.hours && (minutes > other.minutes || (minutes == other.minutes && (seconds > other.seconds || (seconds == other.seconds && ms > other.ms)))));
|
||||
}
|
||||
bool time_t::operator< (const time_t& other) const {
|
||||
return hours < other.hours || (hours == other.hours && (minutes < other.minutes || (minutes == other.minutes && (seconds < other.seconds || (seconds == other.seconds && ms < other.ms)))));
|
||||
}
|
||||
bool time_t::operator>= (const time_t& other) const {
|
||||
return hours >= other.hours || (hours == other.hours && (minutes >= other.minutes || (minutes == other.minutes && (seconds >= other.seconds || (seconds == other.seconds && ms >= other.ms)))));
|
||||
}
|
||||
bool time_t::operator<= (const time_t& other) const{
|
||||
return hours <= other.hours || (hours == other.hours && (minutes <= other.minutes || (minutes == other.minutes && (seconds <= other.seconds || (seconds == other.seconds && ms <= other.ms)))));
|
||||
}
|
||||
bool time_t::operator==(const time_t& other) const {
|
||||
return hours == other.hours && minutes == other.minutes && seconds == other.seconds && ms == other.ms;
|
||||
}
|
||||
bool time_t::operator!= (const time_t& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
bool time_t::validate() const{
|
||||
return hours < 24 && minutes < 60 && seconds < 60 && ms < 1000;
|
||||
}
|
||||
|
||||
timestamp_t::timestamp_t(const char* str) { fromString(str); }
|
||||
timestamp_t& timestamp_t::fromString(const char* str) {
|
||||
date.fromString(str);
|
||||
time.fromString(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
bool timestamp_t::validate() const {
|
||||
return date.validate() && time.validate();
|
||||
}
|
||||
|
||||
char* timestamp_t::toString(char* buf) const {
|
||||
buf = time.toString(buf);
|
||||
auto ret = date.toString(buf);
|
||||
*(buf-1) = ' ';
|
||||
return ret;
|
||||
}
|
||||
bool timestamp_t::operator > (const timestamp_t& other) const {
|
||||
return date > other.date || (date == other.date && time > other.time);
|
||||
}
|
||||
bool timestamp_t::operator < (const timestamp_t& other) const {
|
||||
return date < other.date || (date == other.date && time < other.time);
|
||||
}
|
||||
bool timestamp_t::operator >= (const timestamp_t& other) const {
|
||||
return date >= other.date || (date == other.date && time >= other.time);
|
||||
}
|
||||
bool timestamp_t::operator <= (const timestamp_t& other) const {
|
||||
return date <= other.date || (date == other.date && time <= other.time);
|
||||
}
|
||||
bool timestamp_t::operator == (const timestamp_t& other) const {
|
||||
return date == other.date && time == other.time;
|
||||
}
|
||||
bool timestamp_t::operator!= (const timestamp_t & other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
}
|
||||
|
||||
#include "utils.h"
|
||||
#include <random>
|
||||
template<class T>
|
||||
void print_datetime(const T&v){
|
||||
char buf[T::string_length()];
|
||||
std::cout<<v.toString(buf + T::string_length());
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, types::date_t & v)
|
||||
{
|
||||
print_datetime(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, types::time_t & v)
|
||||
{
|
||||
print_datetime(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, types::timestamp_t & v)
|
||||
{
|
||||
print_datetime(v);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
using std::string;
|
||||
string base62uuid(int l = 8) {
|
||||
using namespace std;
|
||||
|
||||
+21
-4
@@ -25,7 +25,27 @@ inline decltype(auto) print_hook<bool>(const bool& v) {
|
||||
return v? "true" : "false";
|
||||
}
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
extern char* gbuf;
|
||||
|
||||
void setgbuf(char* buf = 0);
|
||||
|
||||
template<>
|
||||
inline decltype(auto) print_hook<types::date_t>(const types::date_t& v) {
|
||||
*(gbuf += types::date_t::string_length()) = 0;
|
||||
|
||||
return v.toString(gbuf);
|
||||
}
|
||||
template<>
|
||||
inline decltype(auto) print_hook<types::time_t>(const types::time_t& v) {
|
||||
*(gbuf += types::time_t::string_length()) = 0;
|
||||
return v.toString(gbuf);
|
||||
}
|
||||
template<>
|
||||
inline decltype(auto) print_hook<types::timestamp_t>(const types::timestamp_t& v) {
|
||||
*(gbuf += types::timestamp_t::string_length()) = 0;
|
||||
return v.toString(gbuf);
|
||||
}
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
constexpr struct __int128__struct{
|
||||
uint64_t low, high;
|
||||
// constexpr bool operator==(__int128_t x) const{
|
||||
@@ -59,9 +79,7 @@ inline const char* get_uint128str(__uint128_t v, char* buf){
|
||||
} while(v);
|
||||
return buf;
|
||||
}
|
||||
extern char* gbuf;
|
||||
|
||||
void setgbuf(char* buf = 0);
|
||||
|
||||
template<>
|
||||
inline decltype(auto) print_hook<__int128_t>(const __int128_t& v) {
|
||||
@@ -77,5 +95,4 @@ inline decltype(auto) print_hook<__uint128_t>(const __uint128_t& v) {
|
||||
|
||||
#else
|
||||
|
||||
#define setgbuf()
|
||||
#endif
|
||||
|
||||
+63
-26
@@ -188,7 +188,10 @@ std::ostream& operator<<(std::ostream& os, const VT<T>& v)
|
||||
v.out();
|
||||
return os;
|
||||
}
|
||||
#ifdef __SIZEOF_INT128__
|
||||
std::ostream& operator<<(std::ostream& os, types::date_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::time_t & v);
|
||||
std::ostream& operator<<(std::ostream& os, types::timestamp_t & v);
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v);
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v);
|
||||
#endif
|
||||
@@ -329,14 +332,14 @@ struct TableInfo {
|
||||
print2_impl<rem_cols...>(func, i, args ..., print_hook(v));
|
||||
};
|
||||
if constexpr (is_vector_type<this_type>)
|
||||
for (int j = 0; j < this_value.size; ++j)
|
||||
for (uint32_t j = 0; j < this_value.size; ++j)
|
||||
next(this_value[j]);
|
||||
else
|
||||
next(this_value);
|
||||
}
|
||||
std::string get_header_string(const char* __restrict sep, const char* __restrict end) const{
|
||||
std::string header_string = std::string();
|
||||
for (int i = 0; i < sizeof...(Types); ++i)
|
||||
for (uint32_t i = 0; i < sizeof...(Types); ++i)
|
||||
header_string += std::string(this->colrefs[i].name) + sep + '|' + sep;
|
||||
const size_t l_sep = strlen(sep) + 1;
|
||||
if (header_string.size() - l_sep >= 0)
|
||||
@@ -359,18 +362,27 @@ struct TableInfo {
|
||||
header_string.resize(header_string.size() - l_sep);
|
||||
|
||||
const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
|
||||
#ifdef __SIZEOF_INT128__
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
constexpr auto num_hge = count_type<__int128_t, __uint128_t>((tuple_type*)(0));
|
||||
char cbuf[num_hge * 41];
|
||||
setgbuf(cbuf);
|
||||
#else
|
||||
constexpr auto num_hge = 0;
|
||||
#endif
|
||||
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()
|
||||
];
|
||||
setgbuf(cbuf);
|
||||
if(view)
|
||||
for (int i = 0; i < view->size; ++i){
|
||||
for (uint32_t i = 0; i < view->size; ++i){
|
||||
print2_impl<cols...>(f, (*view)[i], printf_string.c_str());
|
||||
setgbuf();
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < colrefs[0].size; ++i){
|
||||
for (uint32_t i = 0; i < colrefs[0].size; ++i){
|
||||
print2_impl<cols...>(f, i, printf_string.c_str());
|
||||
setgbuf();
|
||||
}
|
||||
@@ -465,10 +477,10 @@ inline void TableView<Types...>::print(const char* __restrict sep, const char* _
|
||||
std::string header_string = info.get_header_string(sep, end);
|
||||
std::cout << header_string.c_str();
|
||||
|
||||
int n_rows = 0;
|
||||
uint32_t n_rows = 0;
|
||||
if (info.colrefs[0].size > 0)
|
||||
n_rows = info.colrefs[0].size;
|
||||
for (int i = 0; i < n_rows; ++i) {
|
||||
for (uint32_t i = 0; i < n_rows; ++i) {
|
||||
print_impl(i);
|
||||
std::cout << end;
|
||||
}
|
||||
@@ -495,10 +507,10 @@ inline void TableInfo<Types...>::print(const char* __restrict sep, const char* _
|
||||
std::string header_string = get_header_string(sep, end);
|
||||
std::cout << header_string.c_str();
|
||||
|
||||
int n_rows = 0;
|
||||
uint32_t n_rows = 0;
|
||||
if (n_cols > 0 && colrefs[0].size > 0)
|
||||
n_rows = colrefs[0].size;
|
||||
for (int i = 0; i < n_rows; ++i) {
|
||||
for (uint32_t i = 0; i < n_rows; ++i) {
|
||||
print_impl(i);
|
||||
std::cout << end;
|
||||
}
|
||||
@@ -506,88 +518,112 @@ inline void TableInfo<Types...>::print(const char* __restrict sep, const char* _
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < rhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < rhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < rhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < lhs.size; ++i)
|
||||
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);
|
||||
for (int i = 0; i < rhs.size; ++i)
|
||||
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>
|
||||
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>
|
||||
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>
|
||||
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)
|
||||
ret[i] = lhs > rhs[i];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class ...Types>
|
||||
void print(const TableInfo<Types...>& v, const char* delimiter = " ", const char* endline = "\n") {
|
||||
v.print(delimiter, endline);
|
||||
@@ -598,10 +634,11 @@ void print(const TableView<Types...>& v, const char* delimiter = " ", const char
|
||||
}
|
||||
template <class T>
|
||||
void print(const T& v, const char* delimiter = " ") {
|
||||
std::cout<< v;
|
||||
std::cout<< v<< delimiter;
|
||||
// printf(types::printf_str[types::Types<T>::getType()], v);
|
||||
}
|
||||
#ifdef __SIZEOF_INT128__
|
||||
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter);
|
||||
template <>
|
||||
|
||||
+72
-15
@@ -2,9 +2,12 @@
|
||||
#define _TYPES_H
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#if defined(__SIZEOF_INT128__) and not defined(_WIN32)
|
||||
#define __AQ__HAS__INT128__
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __restrict__ __restrict
|
||||
#endif
|
||||
@@ -21,32 +24,85 @@ constexpr static bool is_vector_type = is_vector_impl<T>::value;
|
||||
namespace types {
|
||||
enum Type_t {
|
||||
AINT32, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, AINT64, AINT128, AINT16, ADATE, ATIME, AINT8,
|
||||
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, ABOOL, VECTOR, NONE, ERROR
|
||||
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, ABOOL, VECTOR, ATIMESTAMP, NONE, ERROR
|
||||
};
|
||||
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>", "NULL", "ERROR" };
|
||||
"%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", "BIGINT", "BOOL", "BIGINT", "NULL", "ERROR"};
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BIGINT", "BOOL", "BIGINT", "TIMESTAMP", "NULL", "ERROR"};
|
||||
|
||||
|
||||
// TODO: deal with data/time <=> str/uint conversion
|
||||
struct date_t {
|
||||
uint32_t val = 0;
|
||||
date_t(const char* d) {
|
||||
}
|
||||
std::string toString() const;
|
||||
struct date_t{
|
||||
unsigned char day = 0;
|
||||
unsigned char month = 0;
|
||||
short year = 0;
|
||||
|
||||
date_t() = default;
|
||||
date_t(unsigned char day, unsigned char month, short year) :
|
||||
day (day), month (month), year(year) {}
|
||||
date_t(const char*);
|
||||
date_t& fromString(const char*);
|
||||
bool validate() const;
|
||||
constexpr static unsigned string_length(){
|
||||
return 11;
|
||||
};
|
||||
char* toString(char* buf) const;
|
||||
bool operator > (const date_t&) const;
|
||||
bool operator < (const date_t&) const;
|
||||
bool operator >= (const date_t&) const;
|
||||
bool operator <= (const date_t&) const;
|
||||
bool operator == (const date_t&) const;
|
||||
bool operator != (const date_t&) const;
|
||||
};
|
||||
struct time_t {
|
||||
uint32_t val = 0;
|
||||
time_t(const char* d) {
|
||||
}
|
||||
std::string toString() const;
|
||||
|
||||
struct time_t{
|
||||
unsigned int ms = 0;
|
||||
unsigned char seconds = 0;
|
||||
unsigned char minutes = 0;
|
||||
unsigned char hours = 0;
|
||||
|
||||
time_t() = default;
|
||||
time_t(unsigned int ms, unsigned char seconds, unsigned char minutes, unsigned char hours) :
|
||||
ms (ms), seconds (seconds), minutes(minutes), hours(hours) {};
|
||||
time_t(const char*);
|
||||
time_t& fromString(const char*);
|
||||
bool validate() const;
|
||||
constexpr static unsigned string_length() {
|
||||
return 13;
|
||||
};
|
||||
char* toString(char* buf) const;
|
||||
bool operator > (const time_t&) const;
|
||||
bool operator < (const time_t&) const;
|
||||
bool operator >= (const time_t&) const;
|
||||
bool operator <= (const time_t&) const;
|
||||
bool operator == (const time_t&) const;
|
||||
bool operator != (const time_t&) const;
|
||||
};
|
||||
struct timestamp_t{
|
||||
date_t date;
|
||||
time_t time;
|
||||
timestamp_t() = default;
|
||||
timestamp_t(const date_t& d, const time_t& t) : date(d), time(t) {}
|
||||
timestamp_t(const char*);
|
||||
timestamp_t& fromString(const char*);
|
||||
bool validate() const;
|
||||
constexpr static unsigned string_length(){
|
||||
return date_t::string_length() + time_t::string_length();
|
||||
};
|
||||
char* toString(char* buf) const;
|
||||
bool operator > (const timestamp_t&) const;
|
||||
bool operator < (const timestamp_t&) const;
|
||||
bool operator >= (const timestamp_t&) const;
|
||||
bool operator <= (const timestamp_t&) const;
|
||||
bool operator == (const timestamp_t&) const;
|
||||
bool operator != (const timestamp_t&) const;
|
||||
};
|
||||
template <typename T>
|
||||
struct Types {
|
||||
typedef T type;
|
||||
constexpr Types() noexcept = default;
|
||||
#ifdef __SIZEOF_INT128__
|
||||
#ifdef __AQ__HAS__INT128__
|
||||
#define F_INT128(__F_) __F_(__int128_t, AINT128) \
|
||||
__F_(__uint128_t, AUINT128)
|
||||
#define ULL_Type __uint128_t
|
||||
@@ -73,6 +129,7 @@ namespace types {
|
||||
f(unsigned short, AUINT16) \
|
||||
f(unsigned char, AUINT8) \
|
||||
f(bool, ABOOL) \
|
||||
f(timestamp_t, ATIMESTAMP) \
|
||||
F_INT128(f)
|
||||
|
||||
inline constexpr static Type_t getType() {
|
||||
|
||||
+16
-1
@@ -9,7 +9,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
#include <iterator>
|
||||
#include <initializer_list>
|
||||
#include "types.h"
|
||||
|
||||
@@ -243,6 +243,21 @@ public:
|
||||
if (capacity > 0) free(container);
|
||||
container = 0; size = capacity = 0;
|
||||
}
|
||||
#define Compare(_op) \
|
||||
template<typename T> \
|
||||
inline vector_type<bool> operator _op (const T& v){ \
|
||||
vector_type<bool> res(size); \
|
||||
for (uint32_t i = 0; i < size; ++i) \
|
||||
res[i] = container[i] > v; \
|
||||
return res; \
|
||||
}
|
||||
// template <typename T>
|
||||
Compare(>)
|
||||
Compare(<)
|
||||
Compare(>=)
|
||||
Compare(<=)
|
||||
Compare(==)
|
||||
Compare(!=)
|
||||
#define Op(o, x) \
|
||||
template<typename T>\
|
||||
vector_type<typename types::Coercion<_Ty, T>::type> inline x(const vector_type<T>& r) const {\
|
||||
|
||||
Reference in New Issue
Block a user