1
0
Fork 0

Update assoc_heap.hh

This commit is contained in:
Ariel 2024-02-02 22:39:35 +08:00 committed by GitHub
parent c4fcd050a2
commit 01ec8c04e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 6 deletions

View File

@ -5,15 +5,16 @@ private:
template <typename T> static constexpr auto __map_types(T _t) { template <typename T> static constexpr auto __map_types(T _t) {
return make_tuple(std::priority_queue<_Tp, _Sequence, T>(_t)); return make_tuple(std::priority_queue<_Tp, _Sequence, T>(_t));
} }
template <typename T, typename... U> static constexpr auto __map_types(T _t, U... _o) { template <typename T, typename... U> static constexpr auto __map_types(T _t, U... _o) {
return tuple_cat(make_tuple(std::priority_queue<_Tp, _Sequence, T>(_t)), __map_types(_o...)); return tuple_cat(make_tuple(std::priority_queue<_Tp, _Sequence, T>(_t)), __map_types(_o...));
} }
template <typename T> static constexpr void __push(_Tp _val, T& _c) { template <typename T> static constexpr void __push(const _Tp& _val, T& _c) {
_c.push(_val); _c.push(_val);
} }
template <typename T, typename... U> static constexpr void __push(_Tp _val, T& _c, U&... _o) { template <typename T, typename... U> static constexpr void __push(const _Tp& _val, T& _c, U&... _o) {
__push(_val, _c); __push(_val, _c);
__push(_val, _o...); __push(_val, _o...);
} }
@ -41,12 +42,12 @@ private:
template <size_t i> constexpr void pop() { template <size_t i> constexpr void pop() {
__roll<i>(); __roll<i>();
_count[get<i>(_content).top()] -= 1; _count[top<i>()] -= 1;
--_size; --_size;
get<i>(_content).pop(); get<i>(_content).pop();
} }
constexpr void push(_Tp __val) { constexpr void push(const _Tp& __val) {
_count[__val] += 1; _count[__val] += 1;
++_size; ++_size;
apply([&] (auto&... cs) { __push(__val, cs...); }, _content); apply([&] (auto&... cs) { __push(__val, cs...); }, _content);
@ -60,7 +61,7 @@ private:
return !_size; return !_size;
} }
template <typename... T> constexpr void emplace(T... _val) { template <typename... T> constexpr void emplace(const T&... _val) {
push(_Tp(_val...)); push(_Tp(_val...));
} }
}; };
@ -68,6 +69,6 @@ private:
public: public:
template<typename... _T_cs> static auto make(tuple<_T_cs...> _comp) { template<typename... _T_cs> static auto make(tuple<_T_cs...> _comp) {
auto _container = apply([&](auto... all) { return __map_types(all...); }, _comp); auto _container = apply([&](auto... all) { return __map_types(all...); }, _comp);
return __assoc_heap<decltype(_container), tuple<_T_cs...>>(_container, _comp); return __assoc_heap<decltype(_container), tuple<_T_cs...>>(_container, std::move(_comp));
} }
}; };