diff --git a/server/hasher.h b/server/hasher.h index 2de5555..526c168 100644 --- a/server/hasher.h +++ b/server/hasher.h @@ -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 +struct hasher { + template typename std::enable_if< i == sizeof...(Types), + size_t>::type hashi(const std::tuple&) const { + return 534235245539ULL; + } + + template typename std::enable_if < i < sizeof ...(Types), + size_t>::type hashi(const std::tuple& record) const { + using current_type = typename std::decay>::type>::type; + + return std::hash()(std::get(record)) ^ hashi(record); + } + size_t operator()(const std::tuple& record) const { + return hashi(record); + } +}; + + namespace std{ + template<> struct hash { size_t operator()(const astring_view& _Keyval) const noexcept { return append_bytes(_Keyval.str); } }; + template<> struct hash { size_t operator() (const types::date_t& _Keyval) const noexcept { return std::hash()(*(unsigned int*)(&_Keyval)); } }; + template<> struct hash { size_t operator() (const types::time_t& _Keyval) const noexcept { @@ -40,6 +67,7 @@ namespace std{ ; } }; + template<> struct hash{ size_t operator() (const types::timestamp_t& _Keyval) const noexcept { @@ -48,27 +76,8 @@ namespace std{ } }; -} + template + struct hash> : public hasher{ }; -inline size_t append_bytes(const astring_view& view) noexcept { - return append_bytes(view.str); } - -template -struct hasher { - template typename std::enable_if< i == sizeof...(Types), - size_t>::type hashi(const std::tuple& record) const { - return 534235245539ULL; - } - - template typename std::enable_if< i < sizeof ...(Types), - size_t>::type hashi(const std::tuple& record) const { - using current_type = typename std::decay>::type>::type; - - return std::hash()(std::get(record)) ^ hashi(record); - } - size_t operator()(const std::tuple& record) const { - return hashi(record); - } -}; diff --git a/server/table.h b/server/table.h index f96c0e6..eab5f9d 100644 --- a/server/table.h +++ b/server/table.h @@ -9,6 +9,8 @@ #include #include #include "io.h" +#include "hasher.h" + #undef ERROR template class vector_type; @@ -432,21 +434,21 @@ struct TableInfo { void inline reserve(std::index_sequence, uint32_t size) { const auto& assign_sz = [&size](auto& col){ col.size = size;}; - (assign_sz(get_col(*this)), ...); + (assign_sz(get_col()), ...); } template decltype(auto) inline get_record(std::index_sequence, uint32_t i) { - return std::forward_as_tuple((get_col(*this)[i], ...)); + return std::forward_as_tuple(get_col()[i] ...); } template void inline - set_record(std::index_sequence, tuple_type t) { + set_record(std::index_sequence, const tuple_type& t, uint32_t i) { const auto& assign_field = [](auto& l, const auto& r){ l = r; }; - (assign_field(get_col(*this)[Is], std::get(t)), ...); + (assign_field(get_col()[i], std::get(t)), ...); } TableInfo* distinct() { std::unordered_set 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; }