本文整理汇总了C++中NodeStack::top方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeStack::top方法的具体用法?C++ NodeStack::top怎么用?C++ NodeStack::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeStack
的用法示例。
在下文中一共展示了NodeStack::top方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: topologicalSortExecutionNetwork
void Network::topologicalSortExecutionNetwork() {
// Note: we don't need to do a full-fledged topological sort here, as we do not
// have any DAG, we actually have a dependency tree. This way we can just do a
// depth-first search, with ref-counting to account for diamond shapes in the tree.
// this is similar to the wavefront design pattern used in parallelization
// Using DFS here also has the advantage that it makes as much as possible use
// of cache locality
// 1- get all the nodes and count the number of refs they have
NodeVector nodes = depthFirstSearch(_executionNetworkRoot);
map<NetworkNode*, int> refs;
// this initialization should be useless, but let's do it anyway for clarity
for (int i=0; i<(int)nodes.size(); i++) refs[nodes[i]] = 0;
// count the number of refs for each node
for (int i=0; i<(int)nodes.size(); i++) {
const NodeVector& children = nodes[i]->children();
for (int j=0; j<(int)children.size(); j++) {
refs[children[j]] += 1;
}
}
// 2- do DFS again, manually this time and only visit node which have no refs anymore
_toposortedNetwork.clear();
NodeStack toVisit;
toVisit.push(_executionNetworkRoot);
refs[_executionNetworkRoot] = 1;
while (!toVisit.empty()) {
NetworkNode* currentNode = toVisit.top();
toVisit.pop();
if (--refs[currentNode] == 0) {
_toposortedNetwork.push_back(currentNode->algorithm()); // keep this node, it is good
const NodeVector& children = currentNode->children();
for (int i=0; i<(int)children.size(); i++) {
toVisit.push(children[i]);
}
}
}
E_DEBUG(ENetwork, "-------------------------------------------------------------------------------------------");
for (int i=0; i<(int)_toposortedNetwork.size(); i++) {
E_DEBUG_NONL(ENetwork, " → " << _toposortedNetwork[i]->name());
}
E_DEBUG(ENetwork, ""); // for adding a newline
E_DEBUG(ENetwork, "-------------------------------------------------------------------------------------------");
}
示例2: fromCaseOperator
Node PicklerPrivate::fromCaseOperator(Kind k, uint32_t nchildren) {
kind::MetaKind m = metaKindOf(k);
bool parameterized = (m == kind::metakind::PARAMETERIZED);
uint32_t npops = nchildren + (parameterized? 1 : 0);
NodeStack aux;
while(npops > 0) {
Assert(!d_stack.empty());
Node top = d_stack.top();
aux.push(top);
d_stack.pop();
--npops;
}
NodeBuilder<> nb(d_nm, k);
while(!aux.empty()) {
Node top = aux.top();
nb << top;
aux.pop();
}
return nb;
}