vector<int> maOrderingFast(const vector<SplitEdge> &g, int s) { int addOne = cG(s, g) == 0 ? 1 : 0; int maxNodeInd = 0; for (unsigned i = 0; i < g.size(); i++) maxNodeInd = max(g[i].end0, max(g[i].end1, maxNodeInd)); maxNodeInd++; vector<bool> usedNodes(maxNodeInd, false); for (unsigned i = 0; i < g.size(); i++) { usedNodes[g[i].end0] = true; usedNodes[g[i].end1] = true; } int numNodes = 0; for (unsigned i = 0; i < usedNodes.size(); i++) numNodes += usedNodes[i]; vector<int> ordering; vector<bool> inOrdering; for (int i = 0; i < maxNodeInd; i++) inOrdering.push_back(false); ordering.push_back(s); inOrdering[s] = true; while (ordering.size() != numNodes + addOne) { vector<int> dels(maxNodeInd, 0); for (unsigned i = 0; i < g.size(); i++) { if (!inOrdering[g[i].end0] && inOrdering[g[i].end1]) dels[g[i].end0] += g[i].weight; if (!inOrdering[g[i].end1] && inOrdering[g[i].end0]) dels[g[i].end1] += g[i].weight; } for (int i = 0; i < maxNodeInd; i++) { if (!usedNodes[i]) dels[i] = -1; } int loc = -1; int maxDel = -1; for (unsigned i = 0; i < dels.size(); i++) { if (dels[i] > maxDel) { maxDel = dels[i]; loc = i; } } ordering.push_back(loc); inOrdering[loc] = true; } //verifyMAOrdering(g, ordering); return ordering; }
void TR::RegDepCopyRemoval::processRegDeps(TR::Node *deps, TR::TreeTop *depTT) { if (trace()) traceMsg(comp(), "processing GlRegDeps n%un\n", deps->getGlobalIndex()); TR_ASSERT(deps->getOpCodeValue() == TR::GlRegDeps, "processDeps: deps is not GlRegDeps\n"); _treetop = depTT; _regDeps = deps; clearRegDepInfo(); readRegDeps(); TR::NodeChecklist usedNodes(comp()); selectNodesToReuse(usedNodes); selectNodesToCopy(usedNodes); updateRegDeps(usedNodes); }
vector<int> maOrderingHeap(const vector<SplitEdge> &g, int s) { vector<pair<int, int>> heap; //fst is key/incidence, snd is node ind (matched in MACompare) int addOne = cG(s, g) == 0 ? 1 : 0; int maxNodeInd = 0; for (unsigned i = 0; i < g.size(); i++) maxNodeInd = max(g[i].end0, max(g[i].end1, maxNodeInd)); maxNodeInd++; vector<bool> usedNodes(maxNodeInd, false); for (unsigned i = 0; i < g.size(); i++) { usedNodes[g[i].end0] = true; usedNodes[g[i].end1] = true; } int numNodes = 0; for (unsigned i = 0; i < usedNodes.size(); i++) numNodes += usedNodes[i]; vector<int> ordering; vector<bool> inOrdering(maxNodeInd, false); ordering.push_back(s); inOrdering[s] = true; vector<vector<pair<int, int>>> adjacency; adjacency.reserve(maxNodeInd); for (int i = 0; i < maxNodeInd; i++) adjacency.push_back(vector<pair<int, int>>()); for (unsigned i = 0; i < g.size(); i++) { adjacency[g[i].end0].push_back(pair<int, int>(g[i].end1, g[i].weight)); adjacency[g[i].end1].push_back(pair<int, int>(g[i].end0, g[i].weight)); } heap.reserve(maxNodeInd); for (int i = 0; i < maxNodeInd; i++) heap.push_back(pair<int, int>(0, i)); for (unsigned i = 0; i < g.size(); i++) { if (g[i].end0 == s) heap[g[i].end1].first += g[i].weight; else if (g[i].end1 == s) heap[g[i].end0].first += g[i].weight; } vector<int>realValue; for (unsigned i = 0; i < heap.size(); i++) realValue.push_back(heap[i].first); make_heap(heap.begin(), heap.end(), MACompare()); while (ordering.size() != numNodes + addOne) { pair<int, int> next = heap.front(); pop_heap(heap.begin(), heap.end()); heap.pop_back(); while (realValue[next.second] != next.first || inOrdering[next.second] || !usedNodes[next.second]) //i.e. this value was changed. { next = heap.front(); pop_heap(heap.begin(), heap.end()); heap.pop_back(); } ordering.push_back(next.second); inOrdering[next.second] = true; for (unsigned i = 0; i < adjacency[next.second].size(); i++) { int n = adjacency[next.second][i].first; if (!inOrdering[n]) { realValue[n] += adjacency[next.second][i].second; pair<int, int> p(realValue[n], n); heap.push_back(p); push_heap(heap.begin(), heap.end()); } } } //verifyMAOrdering(g, ordering); return ordering; }