28#include "timemory/tpls/cereal/cereal.hpp"
55 template <
typename GraphT,
typename ItrT>
61 template <
typename Archive>
62 TIMEMORY_COLD
void save(Archive& ar,
const unsigned int)
const;
64 template <
typename Archive>
65 TIMEMORY_COLD
void load(Archive& ar,
const unsigned int);
79 return (lhs.m_value.hash() == rhs.m_value.hash());
93template <
typename GraphT,
typename ItrT>
97 using iterator_t =
typename GraphT::sibling_iterator;
98 using entry_type = std::decay_t<decltype(std::declval<ItrT>()->data())>;
101 iterator_t _begin = g.begin(root);
102 iterator_t _end = g.end(root);
103 auto nchildren = std::distance(_begin, _end);
106 m_children.reserve(nchildren);
107 for(
auto itr = _begin; itr != _end; ++itr)
109 if(!itr->is_dummy() &&
112 m_value.exclusive().data() -= itr->data();
113 m_value.exclusive().stats() -= itr->stats();
114 m_children.emplace_back(std::make_shared<child_type>());
115 m_children.back()->operator()(g, itr);
119 iterator_t _dbegin = g.begin(itr);
120 iterator_t _dend = g.end(itr);
121 for(
auto ditr = _dbegin; ditr != _dend; ++ditr)
123 if(!ditr->is_dummy())
125 m_children.emplace_back(std::make_shared<child_type>());
126 m_children.back()->operator()(g, ditr);
135template <
typename Tp>
141 m_value += rhs.m_value;
145 for(
auto& ritr : rhs.m_children)
146 m_children.insert(m_children.end(), ritr);
150 std::set<size_t> found{};
151 auto nitr = std::min<size_t>(m_children.size(), rhs.m_children.size());
153 for(
size_t i = 0; i < nitr; ++i)
155 if((*m_children.at(i)) == (*rhs.m_children.at(i)))
158 (*m_children.at(i)) += (*rhs.m_children.at(i));
162 for(
size_t i = 0; i < rhs.m_children.size(); ++i)
164 if(found.find(i) != found.end())
166 for(
size_t j = 0; j < m_children.size(); ++j)
168 if((*m_children.at(j)) == (*rhs.m_children.at(i)))
171 (*m_children.at(j)) += (*rhs.m_children.at(i));
176 for(
size_t i = 0; i < rhs.m_children.size(); ++i)
178 if(found.find(i) != found.end())
180 m_children.insert(m_children.end(), rhs.m_children.at(i));
186template <
typename Tp>
192 m_value -= rhs.m_value;
195 std::set<size_t> found{};
196 auto nitr = std::min<size_t>(m_children.size(), rhs.m_children.size());
198 for(
size_t i = 0; i < nitr; ++i)
200 if((*m_children.at(i)) == (*rhs.m_children.at(i)))
203 m_children.at(i) -= rhs.m_children.at(i);
207 for(
size_t i = 0; i < rhs.m_children.size(); ++i)
209 if(found.find(i) != found.end())
211 for(
size_t j = 0; j < m_children.size(); ++j)
213 if((*m_children.at(j)) == (*rhs.m_children.at(i)))
216 m_children.at(j) -= rhs.m_children.at(i);
223template <
typename Tp>
224template <
typename Archive>
230 for(
const auto& itr : m_children)
231 _children.emplace_back(*itr);
232 ar(cereal::make_nvp(
"node", m_value), cereal::make_nvp(
"children", _children));
235template <
typename Tp>
236template <
typename Archive>
242 ar(cereal::make_nvp(
"node", m_value), cereal::make_nvp(
"children", _children));
243 for(
auto&& itr : _children)
244 m_children.emplace_back(std::make_shared<child_type>(std::move(itr)));
Basic hierarchical tree implementation. Expects population from tim::graph.
const auto & get_value() const
void load(Archive &ar, const unsigned int)
this_type & operator()(const GraphT &g, ItrT root)
construction from tim::graph<Tp>
friend bool operator==(const this_type &lhs, const this_type &rhs)
friend bool operator!=(const this_type &lhs, const this_type &rhs)
this_type & operator-=(const this_type &rhs)
void save(Archive &ar, const unsigned int) const
std::shared_ptr< child_type > child_pointer
const auto & get_children() const
this_type & operator+=(const this_type &rhs)
basic_tree< Tp > this_type
auto & get_value()
return the current tree node
auto & get_children()
return the array of child nodes
std::vector< child_type > children_base
std::vector< child_pointer > children_type
This operation attempts to call a member function which provides whether or not the component is in a...