This commit is contained in:
2022-09-20 23:58:00 +08:00
33 changed files with 1312 additions and 179 deletions
+2 -1
View File
@@ -16,7 +16,8 @@ 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>
sum(const VT<T>& v) {
types::GetLongType<T> ret = 0;
for (const auto& _v : v)
ret += _v;
+3 -3
View File
@@ -181,7 +181,7 @@ namespace types {
return !operator==(other);
}
bool time_t::validate() const{
return hours < 24 && minutes < 60 && seconds < 60 && ms < 1000;
return hours < 24 && minutes < 60 && seconds < 60 && ms < 1000000;
}
timestamp_t::timestamp_t(const char* str) { fromString(str); }
@@ -244,13 +244,13 @@ std::ostream& operator<<(std::ostream& os, types::timestamp_t & v)
using std::string;
string base62uuid(int l = 8) {
string base62uuid(int l) {
using namespace std;
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
static uniform_int_distribution<uint64_t> u(0x10000, 0xfffff);
uint64_t uuid = (u(engine) << 32ull) + (chrono::system_clock::now().time_since_epoch().count() & 0xffffffff);
printf("%llu\n", uuid);
//printf("%llu\n", uuid);
string ret;
while (uuid && l-- >= 0) {
ret = string("") + base62alp[uuid % 62] + ret;
+6 -6
View File
@@ -100,10 +100,10 @@ void Context::end_session(){
void* Context::get_module_function(const char* fname){
auto fmap = static_cast<std::unordered_map<std::string, void*>*>
(this->module_function_maps);
printf("%p\n", fmap->find("mydiv")->second);
for (const auto& [key, value] : *fmap){
printf("%s %p\n", key.c_str(), value);
}
// printf("%p\n", fmap->find("mydiv")->second);
// for (const auto& [key, value] : *fmap){
// printf("%s %p\n", key.c_str(), value);
// }
auto ret = fmap->find(fname);
return ret == fmap->end() ? nullptr : ret->second;
}
@@ -188,9 +188,9 @@ int dll_main(int argc, char** argv, Context* cxt){
case 'F': // Register Function in Module
{
auto fname = n_recvd[i] + 1;
printf("F:: %s: %p, %p\n", fname, user_module_handle, dlsym(user_module_handle, fname));
//printf("F:: %s: %p, %p\n", fname, user_module_handle, dlsym(user_module_handle, fname));
module_fn_map->insert_or_assign(fname, dlsym(user_module_handle, fname));
printf("F::: %p\n", module_fn_map->find("mydiv") != module_fn_map->end() ? module_fn_map->find("mydiv")->second : nullptr);
//printf("F::: %p\n", module_fn_map->find("mydiv") != module_fn_map->end() ? module_fn_map->find("mydiv")->second : nullptr);
}
break;
case 'U': // Unload Module
+52 -2
View File
@@ -139,7 +139,9 @@ public:
const ColRef<_Ty>& orig;
constexpr Iterator_t(const uint32_t* val, const ColRef<_Ty>& orig) noexcept : val(val), orig(orig) {}
_Ty& operator*() { return orig[*val]; }
bool operator != (const Iterator_t& rhs) { return rhs.val != val; }
bool operator != (const Iterator_t& rhs) const { return rhs.val != val; }
bool operator == (const Iterator_t& rhs) const { return rhs.val == val; }
size_t operator - (const Iterator_t& rhs) const { return val - rhs.val; }
Iterator_t& operator++ () {
++val;
return *this;
@@ -180,6 +182,20 @@ public:
subvec[i] = operator[](i);
return subvec;
}
std::unordered_set<_Ty> distinct_common() {
return std::unordered_set<_Ty> {begin(), end()};
}
uint32_t distinct_size(){
return distinct_common().size();
}
ColRef<_Ty> distinct(){
auto set = distinct_common();
ColRef<_Ty> ret(set.size());
uint32_t i = 0;
for (auto& val : set)
ret.container[i++] = val;
return ret;
}
inline ColRef<_Ty> subvec(uint32_t start = 0) { return subvec_deep(start, size); }
};
template <template <class...> class VT, class T>
@@ -408,10 +424,43 @@ struct TableInfo {
applyIntegerSequence<sizeof...(Types), applier>::apply(*this, sep, end, view, fp);
}
TableInfo< Types... >* rename(const char* name) {
TableInfo<Types...>* rename(const char* name) {
this->name = name;
return this;
}
template <size_t ...Is>
void inline
reserve(std::index_sequence<Is...>, uint32_t size) {
const auto& assign_sz = [&size](auto& col){ col.size = size;};
(assign_sz(get_col<Is>(*this)), ...);
}
template <size_t ...Is>
decltype(auto) inline
get_record(std::index_sequence<Is...>, uint32_t i) {
return std::forward_as_tuple((get_col<Is>(*this)[i], ...));
}
template <size_t ...Is>
void inline
set_record(std::index_sequence<Is...>, tuple_type t) {
const auto& assign_field =
[](auto& l, const auto& r){
l = r;
};
(assign_field(get_col<Is>(*this)[Is], std::get<Is>(t)), ...);
}
TableInfo<Types ...>* distinct() {
std::unordered_set<tuple_type> d_records;
std::make_index_sequence<sizeof...(Types)> seq;
for (uint32_t j = 0; j < colrefs[0].size; ++j) {
d_records.insert(get_record(seq, j));
}
reserve(seq, d_records.size());
for (const auto& dr : d_records) {
set_record(seq, dr);
}
return this;
}
// defined in monetdb_conn.cpp
void monetdb_append_table(void* srv, const char* alt_name = nullptr);
};
@@ -419,6 +468,7 @@ struct TableInfo {
template<class ...Types>
struct TableView {
typedef std::tuple<Types...> tuple_type;
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) {}
+1 -1
View File
@@ -69,7 +69,7 @@ namespace types {
time_t& fromString(const char*);
bool validate() const;
constexpr static unsigned string_length() {
return 13;
return 16;
};
char* toString(char* buf) const;
bool operator > (const time_t&) const;
+3 -2
View File
@@ -1,5 +1,4 @@
#pragma once
#include <string>
#include <ctime>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
constexpr static bool cpp_17 = true;
@@ -13,4 +12,6 @@ inline const char* str(const T& v) {
template <>
inline const char* str(const bool& v) {
return v ? "true" : "false";
}
}
#include<string>
extern std::string base62uuid(int l = 6);
+30
View File
@@ -11,6 +11,8 @@
#include <cstdint>
#include <iterator>
#include <initializer_list>
#include <unordered_set>
#include "hasher.h"
#include "types.h"
#pragma pack(push, 1)
@@ -107,6 +109,34 @@ public:
return *this;
}
inline std::unordered_set<value_t> distinct_common(){
return std::unordered_set<value_t>(container, container + size);
}
vector_type<_Ty>& distinct_inplace(){
uint32_t i = 0;
for(const auto& v : distinct_common()){
container[i++] = v;
}
return *this;
}
vector_type<_Ty> distinct_copy(){
auto d_vals = distinct_common();
vector_type<_Ty> ret(d_vals.size());
uint32_t i = 0;
for(const auto& v : d_vals){
ret[i++] = v;
}
return ret;
}
uint32_t distinct_size(){
return distinct_common().size();
}
vector_type<_Ty> distinct(){
if (capacity)
return distinct_inplace();
else
return distinct_copy();
}
inline void grow() {
if (size >= capacity) { // geometric growth
uint32_t new_capacity = size + 1 + (size >> 1);