bug fix on select distinct

dev
bill 2 years ago
parent 8eee000ad4
commit 1299733477

@ -17,19 +17,46 @@ inline size_t append_bytes(const unsigned char* _First) noexcept {
return _Val;
}
inline size_t append_bytes(const astring_view& view) noexcept {
return append_bytes(view.str);
}
template <class ...Types>
struct hasher {
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
size_t>::type hashi(const std::tuple<Types...>&) const {
return 534235245539ULL;
}
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);
}
size_t operator()(const std::tuple<Types...>& record) const {
return hashi(record);
}
};
namespace std{
template<>
struct hash<astring_view> {
size_t operator()(const astring_view& _Keyval) const noexcept {
return append_bytes(_Keyval.str);
}
};
template<>
struct hash<types::date_t> {
size_t operator() (const types::date_t& _Keyval) const noexcept {
return std::hash<unsigned int>()(*(unsigned int*)(&_Keyval));
}
};
template<>
struct hash<types::time_t> {
size_t operator() (const types::time_t& _Keyval) const noexcept {
@ -40,6 +67,7 @@ namespace std{
;
}
};
template<>
struct hash<types::timestamp_t>{
size_t operator() (const types::timestamp_t& _Keyval) const noexcept {
@ -48,27 +76,8 @@ namespace std{
}
};
}
inline size_t append_bytes(const astring_view& view) noexcept {
return append_bytes(view.str);
}
template <class ...Types>
struct hasher {
template <size_t i = 0> typename std::enable_if< i == sizeof...(Types),
size_t>::type hashi(const std::tuple<Types...>& record) const {
return 534235245539ULL;
}
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;
struct hash<std::tuple<Types...>> : public hasher<Types...>{ };
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);
}
};

@ -9,6 +9,8 @@
#include <string>
#include <algorithm>
#include "io.h"
#include "hasher.h"
#undef ERROR
template <typename T>
class vector_type;
@ -432,21 +434,21 @@ struct TableInfo {
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)), ...);
(assign_sz(get_col<Is>()), ...);
}
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], ...));
return std::forward_as_tuple(get_col<Is>()[i] ...);
}
template <size_t ...Is>
void inline
set_record(std::index_sequence<Is...>, tuple_type t) {
set_record(std::index_sequence<Is...>, const tuple_type& t, uint32_t i) {
const auto& assign_field =
[](auto& l, const auto& r){
l = r;
};
(assign_field(get_col<Is>(*this)[Is], std::get<Is>(t)), ...);
(assign_field(get_col<Is>()[i], std::get<Is>(t)), ...);
}
TableInfo<Types ...>* distinct() {
std::unordered_set<tuple_type> d_records;
@ -456,8 +458,9 @@ struct TableInfo {
d_records.insert(get_record(seq, j));
}
reserve(seq, d_records.size());
uint32_t i = 0;
for (const auto& dr : d_records) {
set_record(seq, dr);
set_record(seq, dr, i++);
}
return this;
}

Loading…
Cancel
Save