bug fixes
This commit is contained in:
@@ -172,13 +172,7 @@ decayed_t<VT, T> deltas(const VT<T>& arr) {
|
||||
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;
|
||||
return arr[arr.size - 1];
|
||||
}
|
||||
|
||||
// wrong behavior with count(0)
|
||||
|
||||
+35
-4
@@ -17,6 +17,39 @@ inline size_t append_bytes(const unsigned char* _First) noexcept {
|
||||
return _Val;
|
||||
}
|
||||
|
||||
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 {
|
||||
return std::hash<unsigned int>()(_Keyval.ms) ^
|
||||
std::hash<unsigned char>()(_Keyval.seconds) ^
|
||||
std::hash<unsigned char>()(_Keyval.minutes) ^
|
||||
std::hash<unsigned char>()(_Keyval.hours)
|
||||
;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct hash<types::timestamp_t>{
|
||||
size_t operator() (const types::timestamp_t& _Keyval) const noexcept {
|
||||
return std::hash<types::date_t>()(_Keyval.date) ^
|
||||
std::hash<types::time_t>()(_Keyval.time);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline size_t append_bytes(const astring_view& view) noexcept {
|
||||
return append_bytes(view.str);
|
||||
}
|
||||
@@ -32,10 +65,8 @@ struct hasher {
|
||||
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;
|
||||
if constexpr (is_cstr<current_type>())
|
||||
return append_bytes((const unsigned char*)std::get<i>(record)) ^ hashi<i + 1>(record);
|
||||
else
|
||||
return std::hash<current_type>()(std::get<i>(record)) ^ hashi<i+1>(record);
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user