draft: new group by, avoid small allocation

This commit is contained in:
2022-12-23 15:03:28 +08:00
parent 853b129343
commit 529c5cb6a8
14 changed files with 741 additions and 46 deletions
+14
View File
@@ -186,6 +186,20 @@ decayed_t<VT, types::GetLongType<T>> sumw(uint32_t w, const VT<T>& arr) {
return ret;
}
template<class T, template<typename ...> class VT>
void avgw(uint32_t w, const VT<T>& arr, decayed_t<vector_type, types::GetFPType<types::GetLongType<T>>>& ret) {
typedef types::GetFPType<types::GetLongType<T>> FPType;
const uint32_t& len = arr.size;
uint32_t i = 0;
types::GetLongType<T> s{};
w = w > len ? len : w;
if (len) 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;
}
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;
+4
View File
@@ -132,3 +132,7 @@ namespace ankerl::unordered_dense{
struct hash<std::tuple<Types...>> : public hasher<Types...>{ };
}
struct aq_hashtable_value_t {
uint32_t id;
uint32_t cnt;
};
+2 -2
View File
@@ -1,5 +1,5 @@
#include "pch_msc.hpp"
//#define TESTMAIN
#include <iostream>
#include <string>
#include <chrono>
@@ -645,7 +645,7 @@ int launcher(int argc, char** argv){
str = std::string("cd ") + pwd + std::string("&& python3 ./prompt.py ") + str;
return system(str.c_str());
}
#if true || !( defined(_MSC_VER) && defined(_DEBUG) )
#if !defined(TESTMAIN) && !( defined(_MSC_VER) && defined(_DEBUG) )
extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
#ifdef __AQ_BUILD_LAUNCHER__
return launcher(argc, argv);
+12 -12
View File
@@ -147,18 +147,18 @@ public:
return *this;
}
// ColView<_Ty> operator [](vector_type<uint32_t>& idxs) const {
// return ColView<_Ty>(*this, std::move(idxs));
// }
// ColView<_Ty> operator [](const vector_type<uint32_t>& idxs) const {
// return ColView<_Ty>(*this, idxs);
// }
vector_type<_Ty> operator[](vector_type<uint32_t>& idxs) const {
vector_type<_Ty> ret(idxs.size);
for (uint32_t i = 0; i < idxs.size; ++i)
ret.container[i] = this->container[idxs[i]];
return ret;
}
ColView<_Ty> operator [](vector_type<uint32_t>& idxs) const {
return ColView<_Ty>(*this, std::move(idxs));
}
ColView<_Ty> operator [](const vector_type<uint32_t>& idxs) const {
return ColView<_Ty>(*this, idxs);
}
//vector_type<_Ty> operator[](vector_type<uint32_t>& idxs) const {
// vector_type<_Ty> ret(idxs.size);
// for (uint32_t i = 0; i < idxs.size; ++i)
// ret.container[i] = this->container[idxs[i]];
// return ret;
//}
vector_type<_Ty> operator [](const std::vector<bool>& idxs) const {
vector_type<_Ty> ret (this->size);
uint32_t i = 0;
+11 -1
View File
@@ -1059,6 +1059,16 @@ public:
return do_insert_or_assign(std::move(key), std::forward<M>(mapped)).first;
}
template <class K>
unsigned hashtable_push(K&& key) {
auto it_isinserted = try_emplace(std::forward<K>(key), 1);
if (!it_isinserted.second) {
++ it_isinserted.first->second;
return static_cast<unsigned>(it_isinserted.first - begin());
}
return static_cast<unsigned>(end() - begin() - 1);
}
template <typename K,
typename M,
typename Q = T,
@@ -1409,7 +1419,7 @@ public:
}
// nonstandard API: expose the underlying values container
[[nodiscard]] auto values() const noexcept -> value_container_type const& {
[[nodiscard]] auto values() noexcept -> value_container_type & {
return m_values;
}
+8 -2
View File
@@ -88,6 +88,12 @@ public:
constexpr vector_type(const uint32_t size, void* data) :
size(size), capacity(0), container(static_cast<_Ty*>(data)) {}
void init_from(const uint32_t size, void* data) {
this->container = static_cast<_Ty*>(data);
this->size = size;
this->capacity = 0;
}
vector_type<_Ty>& operator =(const _Ty& vt) {
if (!container) {
container = (_Ty*)malloc(sizeof(_Ty));
@@ -134,7 +140,7 @@ public:
container[i++] = v;
}
return *this;
}
}
vector_type<_Ty> distinct_copy(){
auto d_vals = distinct_common();
vector_type<_Ty> ret(d_vals.size());
@@ -325,7 +331,7 @@ public:
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) const { return subvec_deep(start, size); }
vector_type<_Ty> getRef() { return vector_type<_Ty>(container, size); }
~vector_type() {
if (capacity > 0) GC::gc_handle->reg(container, sizeof(_Ty) * capacity);//free(container);
if (capacity > 0);// GC::gc_handle->reg(container, sizeof(_Ty) * capacity);//free(container);
container = 0; size = capacity = 0;
}
#define Compare(_op) \