本文整理汇总了C++中NodeSet::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeSet::insert方法的具体用法?C++ NodeSet::insert怎么用?C++ NodeSet::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeSet
的用法示例。
在下文中一共展示了NodeSet::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsReachable
bool IsReachable(ControlFlowNode *head, ControlFlowNode *tail)
{
if (head == tail)
{
return true;
}
NodeSet visited;
visited.insert(tail);
stack<ControlFlowNode*> toProcess;
toProcess.push(tail);
while (!toProcess.empty())
{
ControlFlowNode *node = toProcess.top();
toProcess.pop();
for (ControlFlowNode *pred : node->Predecessors())
{
if (pred == head)
{
return true;
}
if (!visited.contains(pred))
{
visited.insert(pred);
toProcess.push(pred);
}
}
}
return false;
}
示例2: runtime_error
// -----------------------------------------------------------------------------
Graph *SpanningTree::create_spanning_tree(Graph* g, Node* root) {
if(root == NULL)
throw std::runtime_error("create_spanning_tree NULL exception");
Graph *t = new Graph(FLAG_DAG);
NodeSet visited;
NodeStack node_stack;
node_stack.push(root);
while(!node_stack.empty()) {
Node* n = node_stack.top();
node_stack.pop();
visited.insert(n);
Node* tree_node1 = t->add_node_ptr(n->_value);
EdgePtrIterator* eit = n->get_edges();
Edge* e;
while((e = eit->next()) != NULL) {
Node* inner_node = e->traverse(n);
if(inner_node != NULL && visited.count(inner_node) == 0) {
Node* tree_node2 = t->add_node_ptr(inner_node->_value);
t->add_edge(tree_node1, tree_node2, e->weight, e->label);
node_stack.push(inner_node);
visited.insert(inner_node);
}
}
delete eit;
}
return t;
}
示例3: getLeftNeighbours
NodeSet* getLeftNeighbours(NodeSet &scanline,Node *v) {
NodeSet *leftv = new NodeSet;
NodeSet::iterator i=scanline.find(v);
while(i--!=scanline.begin()) {
Node *u=*(i);
if(u->r->overlapX(v->r)<=0) {
leftv->insert(u);
return leftv;
}
if(u->r->overlapX(v->r)<=u->r->overlapY(v->r)) {
leftv->insert(u);
}
}
return leftv;
}
示例4: getRightNeighbours
NodeSet* getRightNeighbours(NodeSet &scanline,Node *v) {
NodeSet *rightv = new NodeSet;
NodeSet::iterator i=scanline.find(v);
for(++i;i!=scanline.end(); ++i) {
Node *u=*(i);
if(u->r->overlapX(v->r)<=0) {
rightv->insert(u);
return rightv;
}
if(u->r->overlapX(v->r)<=u->r->overlapY(v->r)) {
rightv->insert(u);
}
}
return rightv;
}
示例5: CollectNodesBetween
// Returns the set of all nodes between tail and head, assuming
// head and tail form a single entry and exit point.
// Possible is there just for debugging. There should be no nodes outside possible
NodeSet CollectNodesBetween(ControlFlowNode *head, ControlFlowNode *tail, NodeSet possible)
{
NodeSet collection;
stack<ControlFlowNode*> toProcess;
toProcess.push(tail);
while (!toProcess.empty())
{
ControlFlowNode *node = toProcess.top();
toProcess.pop();
collection.insert(node);
if (node != head)
{
for (ControlFlowNode *pred : node->Predecessors())
{
if (!collection.contains(pred)) // Haven't already visited it
{
assert(possible.contains(pred));// We could just filter these, but let's assert for now to catch bad callers.
toProcess.push(pred);
}
}
}
}
return collection;
}
示例6: separateConnectedComponents
void LazyConstraintCallback::separateConnectedComponents( Graph const & g
, GraphVariables const & vars
, Graph::Node const & root
, NodeSetVector const & nonZeroNodesComponents
, int & nCuts
) {
IloExpr rhs( getEnv() );
for ( const NodeSet& S : nonZeroNodesComponents ) {
// only consider the non-zero components that don't contain the root
auto it = S.find( root );
if ( it == S.end() || it->componentIndex() != root.componentIndex() ) {
// determine dS
NodeSet dS;
for ( Graph::Node i : S ) {
for ( Graph::Edge e : g.incEdges( i ) ) {
Graph::Node j = g.oppositeNode( i, e );
if ( S.find( j ) == S.end() )
{
dS.insert( j );
}
}
}
constructRHS( vars, dS, S, rhs );
for ( Graph::Node i : S ) {
assert( isValid( g, i, dS, S ) );
add( vars.xVars[vars.nodeToIndex[i]] <= rhs, IloCplex::UseCutPurge ).end();
++nCuts;
}
}
}
rhs.end();
}
示例7: functionGreaterEqual
void State::functionGreaterEqual(const string& a_name, int a_value)
{
NodeSet* parentSet = getVariableNodes(a_name);
if (parentSet == NULL)
{
error("State::functionGreaterEqual - variable " + a_name + " doesn't exist" , false);
return;
}
NodeSet removedRoots;
for (NodeSetConstIter iter = parentSet->begin(); iter != parentSet->end(); iter++)
{
if ((*iter) == NULL)
{
error("State::functionGreaterEqual - iterator for variable " + a_name + " is NULL", false);
continue;
}
if ((*iter)->getMaxValue() < a_value)
{
debug("State::functionGreaterEqual - Adding " + a_name + "'s root to removedRoots set");
removedRoots.insert((*iter)->getRoot());
continue;
}
if ((*iter)->getMinValue() < a_value)
{
(*iter)->setMinValue(a_value);
}
}
debug("State::functionGreaterEqual - removing trees");
removeTrees(removedRoots);
}
示例8: isValid
bool Callback::isValid( Graph const & g
, Graph::Node const & i
, NodeSet const & dS
, NodeSet const & S) const {
if ( S.find( i ) == S.end() ) {
// i must be in S
return false;
}
if ( dS.find( i ) != dS.end() ) {
// i must not be in dS
return false;
}
// determine dS again
NodeSet ddS;
for ( Graph::Node i : S ) {
for ( Graph::Edge e : g.incEdges( i) ) {
Graph::Node j = g.oppositeNode( i, e );
if ( S.find( j ) == S.end() )
{
ddS.insert( j );
}
}
}
return dS == ddS;
}
示例9: reset
Item::Ptr UTransform::TransformResult::next(DynamicContext *context)
{
context->testInterrupt();
AutoVariableStoreReset reset(context, &scope_);
if(toDo_) {
toDo_ = false;
NodeSet copiedNodes = NodeSet(nodecompare(context));
VectorOfCopyBinding::const_iterator end = transform_->getBindings()->end();
for(VectorOfCopyBinding::const_iterator it = transform_->getBindings()->begin();
it != end; ++it) {
if((*it)->qname_ == 0) continue;
Sequence values = (*it)->expr_->createResult(context)->toSequence(context);
// Keep a record of the nodes that have been copied
Result valIt = values;
Item::Ptr val;
while((val = valIt->next(context)).notNull()) {
copiedNodes.insert((Node*)val.get());
}
scope_.setVar((*it)->uri_, (*it)->name_, values);
}
// Get the pending update list
PendingUpdateList pul = transform_->getModifyExpr()->createUpdateList(context);
// Check that the targets of the pending updates are copied nodes
for(PendingUpdateList::const_iterator i = pul.begin(); i != pul.end(); ++i) {
Node::Ptr target = i->getTarget();
while(copiedNodes.find(target) == copiedNodes.end()) {
target = target->dmParent(context);
if(target.isNull()) {
XQThrow3(StaticErrorException,X("UTransform::staticTyping"),
X("The target node of an update expression in the transform expression is not a node from the copy clauses [err:XUDY0014]"), &(*i));
}
}
}
// Apply the updates
AutoDelete<UpdateFactory> ufactory(context->createUpdateFactory());
ufactory->applyUpdates(pul, context, transform_->getRevalidationMode());
// Execute the return expression
result_ = transform_->getReturnExpr()->createResult(context);
}
Item::Ptr result = result_->next(context);
if(result.isNull()) {
result_ = 0;
return 0;
}
return result;
}
示例10:
void ActionChoiceWindow::ActionNode::getAllNodes(ActionNode* treeRoot, NodeSet& nodes)
{
nodes.insert(treeRoot);
const NodeSet children = treeRoot->getChildren();
for (NodeSet::const_iterator iter = children.begin(); iter != children.end(); iter++)
getAllNodes(*iter, nodes);
}
示例11: nodes_for_root
static void nodes_for_root(GepNode *Root, NodeChildrenMap &NCM,
NodeSet &Nodes) {
NodeVect Work;
Work.push_back(Root);
Nodes.insert(Root);
while (!Work.empty()) {
NodeVect::iterator First = Work.begin();
GepNode *N = *First;
Work.erase(First);
NodeChildrenMap::iterator CF = NCM.find(N);
if (CF != NCM.end()) {
Work.insert(Work.end(), CF->second.begin(), CF->second.end());
Nodes.insert(CF->second.begin(), CF->second.end());
}
}
}
示例12: getAllReachedUses
NodeSet Liveness::getAllReachedUses(RegisterRef RefRR,
NodeAddr<DefNode*> DefA, const RegisterAggr &DefRRs) {
NodeSet Uses;
// If the original register is already covered by all the intervening
// defs, no more uses can be reached.
if (DefRRs.hasCoverOf(RefRR))
return Uses;
// Add all directly reached uses.
// If the def is dead, it does not provide a value for any use.
bool IsDead = DefA.Addr->getFlags() & NodeAttrs::Dead;
NodeId U = !IsDead ? DefA.Addr->getReachedUse() : 0;
while (U != 0) {
auto UA = DFG.addr<UseNode*>(U);
if (!(UA.Addr->getFlags() & NodeAttrs::Undef)) {
RegisterRef UR = UA.Addr->getRegRef(DFG);
if (PRI.alias(RefRR, UR) && !DefRRs.hasCoverOf(UR))
Uses.insert(U);
}
U = UA.Addr->getSibling();
}
// Traverse all reached defs. This time dead defs cannot be ignored.
for (NodeId D = DefA.Addr->getReachedDef(), NextD; D != 0; D = NextD) {
auto DA = DFG.addr<DefNode*>(D);
NextD = DA.Addr->getSibling();
RegisterRef DR = DA.Addr->getRegRef(DFG);
// If this def is already covered, it cannot reach anything new.
// Similarly, skip it if it is not aliased to the interesting register.
if (DefRRs.hasCoverOf(DR) || !PRI.alias(RefRR, DR))
continue;
NodeSet T;
if (DFG.IsPreservingDef(DA)) {
// If it is a preserving def, do not update the set of intervening defs.
T = getAllReachedUses(RefRR, DA, DefRRs);
} else {
RegisterAggr NewDefRRs = DefRRs;
NewDefRRs.insert(DR);
T = getAllReachedUses(RefRR, DA, NewDefRRs);
}
Uses.insert(T.begin(), T.end());
}
return Uses;
}
示例13: DefRRs
std::pair<NodeSet,bool>
Liveness::getAllReachingDefsRecImpl(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
NodeSet &Visited, const NodeSet &Defs, unsigned Nest, unsigned MaxNest) {
if (Nest > MaxNest)
return { NodeSet(), false };
// Collect all defined registers. Do not consider phis to be defining
// anything, only collect "real" definitions.
RegisterAggr DefRRs(PRI);
for (NodeId D : Defs) {
const auto DA = DFG.addr<const DefNode*>(D);
if (!(DA.Addr->getFlags() & NodeAttrs::PhiRef))
DefRRs.insert(DA.Addr->getRegRef(DFG));
}
NodeList RDs = getAllReachingDefs(RefRR, RefA, false, true, DefRRs);
if (RDs.empty())
return { Defs, true };
// Make a copy of the preexisting definitions and add the newly found ones.
NodeSet TmpDefs = Defs;
for (NodeAddr<NodeBase*> R : RDs)
TmpDefs.insert(R.Id);
NodeSet Result = Defs;
for (NodeAddr<DefNode*> DA : RDs) {
Result.insert(DA.Id);
if (!(DA.Addr->getFlags() & NodeAttrs::PhiRef))
continue;
NodeAddr<PhiNode*> PA = DA.Addr->getOwner(DFG);
if (Visited.count(PA.Id))
continue;
Visited.insert(PA.Id);
// Go over all phi uses and get the reaching defs for each use.
for (auto U : PA.Addr->members_if(DFG.IsRef<NodeAttrs::Use>, DFG)) {
const auto &T = getAllReachingDefsRecImpl(RefRR, U, Visited, TmpDefs,
Nest+1, MaxNest);
if (!T.second)
return { T.first, false };
Result.insert(T.first.begin(), T.first.end());
}
}
return { Result, true };
}
示例14: getAllReachedUses
NodeSet Liveness::getAllReachedUses(RegisterRef RefRR,
NodeAddr<DefNode*> DefA, const RegisterSet &DefRRs) {
NodeSet Uses;
// If the original register is already covered by all the intervening
// defs, no more uses can be reached.
if (RAI.covers(DefRRs, RefRR, DFG))
return Uses;
// Add all directly reached uses.
NodeId U = DefA.Addr->getReachedUse();
while (U != 0) {
auto UA = DFG.addr<UseNode*>(U);
if (!(UA.Addr->getFlags() & NodeAttrs::Undef)) {
auto UR = UA.Addr->getRegRef();
if (RAI.alias(RefRR, UR, DFG) && !RAI.covers(DefRRs, UR, DFG))
Uses.insert(U);
}
U = UA.Addr->getSibling();
}
// Traverse all reached defs.
for (NodeId D = DefA.Addr->getReachedDef(), NextD; D != 0; D = NextD) {
auto DA = DFG.addr<DefNode*>(D);
NextD = DA.Addr->getSibling();
auto DR = DA.Addr->getRegRef();
// If this def is already covered, it cannot reach anything new.
// Similarly, skip it if it is not aliased to the interesting register.
if (RAI.covers(DefRRs, DR, DFG) || !RAI.alias(RefRR, DR, DFG))
continue;
NodeSet T;
if (DFG.IsPreservingDef(DA)) {
// If it is a preserving def, do not update the set of intervening defs.
T = getAllReachedUses(RefRR, DA, DefRRs);
} else {
RegisterSet NewDefRRs = DefRRs;
NewDefRRs.insert(DR);
T = getAllReachedUses(RefRR, DA, NewDefRRs);
}
Uses.insert(T.begin(), T.end());
}
return Uses;
}
示例15: numNodes
uint64_t CVC4::theory::bv::utils::numNodes(TNode node, NodeSet& seen) {
if (seen.find(node) != seen.end())
return 0;
uint64_t size = 1;
for (unsigned i = 0; i < node.getNumChildren(); ++i) {
size += numNodes(node[i], seen);
}
seen.insert(node);
return size;
}