std::vector<int> compute_subtree_size( const AdjacencyList<EdgeType> &conn, int root) const { const int n = conn.size(); std::vector<int> subtree_size(n); std::vector<bool> passed(n), gathered(n); std::stack<pii> count_stack; count_stack.push(pii(root, 0)); while(!count_stack.empty()){ const pii p = count_stack.top(); count_stack.pop(); const int u = p.first, i = p.second; if(i == 0){ passed[u] = true; count_stack.push(pii(u, 1)); for(size_t j = 0; j < conn[u].size(); ++j){ const int v = conn[u][j].to; if(passed[v]){ continue; } count_stack.push(pii(v, 0)); } }else{ int sum = 1; gathered[u] = true; for(size_t j = 0; j < conn[u].size(); ++j){ const int v = conn[u][j].to; if(!gathered[v]){ continue; } sum += subtree_size[v]; } subtree_size[u] = sum; } } return subtree_size; }
//-------------------------------------------------------------------------------- void StatsReporter::run(const BoostPtree &request, BoostPtree &response) { LogStream log(__PRETTY_FUNCTION__); try { std::string stat_type = request.get<std::string>("type","current"); response.put("kcm-sts" , RQST_SUCCESS); if (stat_type == "full" ) { full (response); } else if (stat_type == "current" ) { current (response); } else /*(stat_type == "gathered")*/ { gathered(response); } } catch (boost::property_tree::ptree_bad_path &e) { log << "Exception: " << e.what() << manip::endl; response.put("kcm-sts", RQST_MISSING_PARAMETER); response.put("kcm-erm", e.what()); } catch (std::exception& e) { log << "Exception: " << e.what() << manip::endl; response.put("kcm-sts", RQST_UNKNOWN); response.put("kcm-erm", e.what()); } }