Value Filter::evaluate() const { Value result = m_expression->evaluate(); NodeSet& nodes = result.modifiableNodeSet(); nodes.sort(); EvaluationContext& evaluationContext = Expression::evaluationContext(); for (auto& predicate : m_predicates) { NodeSet newNodes; evaluationContext.size = nodes.size(); evaluationContext.position = 0; for (auto& node : nodes) { evaluationContext.node = node; ++evaluationContext.position; if (evaluatePredicate(*predicate)) newNodes.append(node.copyRef()); } nodes = WTFMove(newNodes); } return result; }
void ConfigFileWriter::writeRadiosFile(std::string filename, NodeSet& ns) { std::fstream out; out.open(filename.c_str(), std::fstream::out | std::fstream::trunc); NodeSet::iterator it = ns.begin(); while (it != ns.end()) { EntityStruct* ent = (*it)->entity; int len = strlen((char*)ent->marking.markingData); if (len == 0 || len > 11) { it++; continue; } RadioStruct* radio = (*it)->radio; if (radio) { out << (*it)->NodeId << ", "; out << ent->marking << ", "; out << radio->radioIndex << ", "; out << radio->relativePosition << ", "; out << radio->radioSystemType ; out << std::endl; } it++; } out.close(); }
void ConfigFileWriter::writeRouterModelFile(std::string filename, NodeSet& ns) { std::fstream out; std::set<std::string>::iterator it = ns.modelsUsed().begin(); if (it != ns.modelsUsed().end()) { out.open(filename.c_str(), std::fstream::out | std::fstream::trunc); } while (it != ns.modelsUsed().end()) { ParameterMap* parameters = Config::instance().getModelParameterList(*it); const Parameter& model = parameters->getParameter("ROUTER-MODEL"); if (model != Parameter::unknownParameter) { out << model << std::endl; ParameterMap::iterator pit = parameters->begin(); while (pit != parameters->end()) { if (pit->first != "ROUTER-MODEL") out << pit->second << std::endl; pit++; } out << std::endl; } it++; } }
void State::removeTrees(const NodeSet& a_nodeSet) { for (NodeSetConstIter iter = a_nodeSet.begin(); iter != a_nodeSet.end(); iter++) { removeTree(*iter); } }
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); }
void XemProcessor::resolveNodeAndPushToNodeSet ( NodeSet& result, const String& nodeIdStr ) { KeyId attributeKeyId = 0; ElementRef resolvedElement = resolveElementWithRole ( nodeIdStr, attributeKeyId ); if ( !resolvedElement ) { throwException ( Exception, "Could not resolve element fro '%s'.\n", nodeIdStr.c_str() ); } if ( attributeKeyId ) { AttributeRef attrRef = resolvedElement.findAttr ( attributeKeyId, AttributeType_String ); if ( ! attrRef ) { throwException ( Exception, "Could not get attr '%x' in element %s from '%s'\n", attributeKeyId, resolvedElement.generateVersatileXPath().c_str(), nodeIdStr.c_str() ); } Log_XemRoleBased ( "Pushing attribute '%s'\n", attrRef.generateVersatileXPath().c_str() ); result.pushBack ( attrRef ); } else { Log_XemRoleBased ( "Pushing element '%s'\n", resolvedElement.generateVersatileXPath().c_str() ); result.pushBack ( resolvedElement ); } }
/** * Gets the spelling alternatives to the specified query terms. * Returns a map with term as key and an Alternative object as value for each query term */ std::map<std::string, Alternative> getAlternatives() { if (!_alternatives.empty()) return _alternatives; _alternatives.clear(); NodeSet alternatives = doc->FindFast("cps:reply/cps:content/alternatives_list/alternatives", true); for (unsigned int i = 0; i < alternatives.size(); i++) { Node *el = alternatives[i]->getFirstChild(); Alternative alt; while (el != NULL) { std::string name = el->getName(); if (name == "to") alt.to = el->getContent(); else if (name == "count") alt.count = atoi(el->getContentPtr()); else if (name == "word") { Alternative::Word w; w.count = atoi(el->getAttribute("count")->getContentPtr()); w.h = atof(el->getAttribute("h")->getContentPtr()); w.idif = atof(el->getAttribute("idif")->getContentPtr()); w.cr = atof(el->getAttribute("cr")->getContentPtr()); w.content = el->getContent(); alt.words.push_back(w); } el = el->getNextSibling(); } _alternatives[alt.to] = alt; } return _alternatives; }
static bool check_range_set( EntityTopology type, NodeSet set, unsigned dim, bool value = true ) { const unsigned max_count[] = { NodeSet::NUM_CORNER_BITS, NodeSet::NUM_EDGE_BITS, NodeSet::NUM_FACE_BITS, NodeSet::NUM_REGION_BITS }; // test that any bits corresponding to some other dimension are not set. for (unsigned d = 0; d <= 3; ++d) { if (d == dim) continue; for (unsigned i = 0; i < max_count[d]; ++i) if (!set.node( Sample(d,i) ) != value) return false; } // test that any bits for this dimension beyond the number for this // type are not set for (unsigned i = TopologyInfo::adjacent( type, dim ); i < max_count[dim]; ++i) if (!set.node( Sample(dim,i) ) != value) return false; // test that any bits for the type and dimension are set for (unsigned i = 0; i < TopologyInfo::adjacent( type, dim ); ++i) if (set.node( Sample(dim,i) ) == value) return false; return true; }
void ActionChoiceWindow::createButtons( ActionNode* actions, const CEGUI::Point& center, float radius, float angle, float angleWidth) { PushButton* button = NULL; if (actions->isLeaf()) { button = createButton(actions->getAction()->getName(), center); } else { if (actions->getGroup() != NULL) { button = createButton(actions->getGroup()->getName(), center); } const NodeSet children = actions->getChildren(); float angleStep = angleWidth / (float)children.size(); float ang = children.size()>1 ? angle - angleWidth : angle - 180; for (NodeSet::const_iterator iter = children.begin(); iter != children.end(); iter++) { CEGUI::Point centerChild = getPositionOnCircle(center, radius, ang); createButtons(*iter, centerChild, radius, ang, 60); ang += angleStep; } } actions->setButton(button); if (button != NULL) mWindow->addChildWindow(button); }
void RegionGraph::constructCVM( const FactorGraph &fg, const std::vector<NodeSet> &cl) { using std::pair; DLOG(INFO) << "constructCVM called (" << fg.nrNodes() << " vars, " << fg.nrFactors() << " facs, " << cl.size() << " clusters)"; // Retain only maximal clusters DLOG(INFO) << " Constructing ClusterGraph"; ClusterGraph cg( cl ); DLOG(INFO) << " Erasing non-maximal clusters"; cg.eraseNonMaximal(); // Create inner regions - first pass DLOG(INFO) << " Creating inner regions (first pass)"; std::set<NodeSet> betas; for( size_t alpha = 0; alpha < cg.nrClusters(); alpha++ ) for( size_t alpha2 = alpha; (++alpha2) != cg.nrClusters(); ) { NodeSet intersection = cg.cluster(alpha) & cg.cluster(alpha2); if( intersection.size() > 0 ) betas.insert( intersection ); } // Create inner regions - subsequent passes DLOG(INFO) << " Creating inner regions (next passes)"; std::set<NodeSet> new_betas; do { new_betas.clear(); for (std::set<NodeSet>::const_iterator gamma = betas.begin(); gamma != betas.end(); gamma++ ) for (std::set<NodeSet>::const_iterator gamma2 = gamma; (++gamma2) != betas.end(); ) { NodeSet intersection = (*gamma) & (*gamma2); if( (intersection.size() > 0) && (betas.count(intersection) == 0) ) new_betas.insert( intersection ); } betas.insert(new_betas.begin(), new_betas.end()); } while( new_betas.size() ); // Create inner regions - final phase DLOG(INFO) << " Creating inner regions (final phase)"; std::vector<Region> irs; irs.reserve( betas.size() ); for (std::set<NodeSet>::const_iterator beta = betas.begin(); beta != betas.end(); beta++ ) irs.push_back( Region(*beta,0.0) ); // Create edges DLOG(INFO) << " Creating edges"; std::vector<std::pair<size_t,size_t> > edges; for( size_t beta = 0; beta < irs.size(); beta++ ) for( size_t alpha = 0; alpha < cg.nrClusters(); alpha++ ) if( cg.cluster(alpha) >> irs[beta] ) edges.push_back( pair<size_t,size_t>(alpha,beta) ); // Construct region graph DLOG(INFO) << " Constructing region graph"; construct( fg, cg.clusters(), irs, edges ); // Calculate counting numbers DLOG(INFO) << " Calculating counting numbers"; calcCVMCountingNumbers(); DLOG(INFO) << "Done."; }
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; }
Value LocationPath::evaluate() const { EvaluationContext& evaluationContext = Expression::evaluationContext(); EvaluationContext backupContext = evaluationContext; // http://www.w3.org/TR/xpath/ // Section 2, Location Paths: // "/ selects the document root (which is always the parent of the document element)" // "A / by itself selects the root node of the document containing the context node." // In the case of a tree that is detached from the document, we violate // the spec and treat / as the root node of the detached tree. // This is for compatibility with Firefox, and also seems like a more // logical treatment of where you would expect the "root" to be. Node* context = evaluationContext.node.get(); if (m_absolute && context->nodeType() != Node::DOCUMENT_NODE) { if (context->inDocument()) context = context->ownerDocument(); else context = context->highestAncestor(); } NodeSet nodes; nodes.append(context); evaluate(nodes); evaluationContext = backupContext; return Value(nodes, Value::adopt); }
void TriLagrangeShape::coefficients( Sample loc, NodeSet nodeset, double* coeff_out, size_t* indices_out, size_t& num_coeff, MsqError& err ) const { if (nodeset.have_any_mid_face_node()) { MSQ_SETERR(err)("TriLagrangeShape does not support mid-element nodes", MsqError::UNSUPPORTED_ELEMENT); return; } switch (loc.dimension) { case 0: num_coeff = 1; indices_out[0] = loc.number; coeff_out[0] = 1.0; break; case 1: if (nodeset.mid_edge_node(loc.number)) { // if mid-edge node is present num_coeff = 1; indices_out[0] = 3+loc.number; coeff_out[0] = 1.0; } else { // no mid node on edge num_coeff = 2; indices_out[0] = loc.number; indices_out[1] = (loc.number+1)%3; coeff_out[0] = 0.5; coeff_out[1] = 0.5; } break; case 2: num_coeff = 3; indices_out[0] = 0; indices_out[1] = 1; indices_out[2] = 2; coeff_out[0] = 1.0/3.0; coeff_out[1] = 1.0/3.0; coeff_out[2] = 1.0/3.0; for (int i = 0; i < 3; ++i) { // for each mid-edge node if (nodeset.mid_edge_node(i)) { // if node is present indices_out[num_coeff] = i+3; // coeff for mid-edge node coeff_out[num_coeff] = 4.0/9.0; // adjust coeff for adj corner nodes coeff_out[i] -= 2.0/9.0; coeff_out[(i+1)%3] -= 2.0/9.0; // update count ++num_coeff; } } break; default: MSQ_SETERR(err)(MsqError::UNSUPPORTED_ELEMENT, "Request for dimension %d mapping function value" "for a triangular element", loc.dimension); } }
Value Filter::evaluate() const { Value v = m_expr->evaluate(); NodeSet& nodes = v.modifiableNodeSet(); nodes.sort(); EvaluationContext& evaluationContext = Expression::evaluationContext(); for (unsigned i = 0; i < m_predicates.size(); i++) { NodeSet newNodes; evaluationContext.size = nodes.size(); evaluationContext.position = 0; for (unsigned j = 0; j < nodes.size(); j++) { Node* node = nodes[j]; evaluationContext.node = node; ++evaluationContext.position; if (m_predicates[i]->evaluate()) newNodes.append(node); } nodes.swap(newNodes); } return v; }
static void compare_coefficients( const double* coeffs, const size_t* indices, const double* expected_coeffs, size_t num_coeff, unsigned loc, NodeSet bits ) { // find the location in the returned list for each node size_t revidx[6]; double test_vals[6]; for (size_t i = 0; i < 6; ++i) { revidx[i] = std::find( indices, indices+num_coeff, i ) - indices; test_vals[i] = (revidx[i] == num_coeff) ? 0.0 : coeffs[revidx[i]]; } // Check that index list doesn't contain any nodes not actually // present in the element. CPPUNIT_ASSERT( bits.mid_edge_node(0) || (revidx[3] == num_coeff) ); CPPUNIT_ASSERT( bits.mid_edge_node(1) || (revidx[4] == num_coeff) ); CPPUNIT_ASSERT( bits.mid_edge_node(2) || (revidx[5] == num_coeff) ); // compare expected and actual coefficient values ASSERT_VALUES_EQUAL( expected_coeffs[0], test_vals[0], loc, bits ); ASSERT_VALUES_EQUAL( expected_coeffs[1], test_vals[1], loc, bits ); ASSERT_VALUES_EQUAL( expected_coeffs[2], test_vals[2], loc, bits ); ASSERT_VALUES_EQUAL( expected_coeffs[3], test_vals[3], loc, bits ); ASSERT_VALUES_EQUAL( expected_coeffs[4], test_vals[4], loc, bits ); ASSERT_VALUES_EQUAL( expected_coeffs[5], test_vals[5], loc, bits ); }
void TriLagrangeShape::derivatives( Sample loc, NodeSet nodeset, size_t* vertex_indices_out, MsqVector<2>* d_coeff_d_xi_out, size_t& num_vtx, MsqError& err ) const { if (!nodeset.have_any_mid_node()) { num_vtx = 3; get_linear_derivatives( vertex_indices_out, d_coeff_d_xi_out ); return; } if (nodeset.have_any_mid_face_node()) { MSQ_SETERR(err)("TriLagrangeShape does not support mid-element nodes", MsqError::UNSUPPORTED_ELEMENT); return; } switch (loc.dimension) { case 0: derivatives_at_corner( loc.number, nodeset, vertex_indices_out, d_coeff_d_xi_out, num_vtx ); break; case 1: derivatives_at_mid_edge( loc.number, nodeset, vertex_indices_out, d_coeff_d_xi_out, num_vtx ); break; case 2: derivatives_at_mid_elem( nodeset, vertex_indices_out, d_coeff_d_xi_out, num_vtx ); break; default: MSQ_SETERR(err)("Invalid/unsupported logical dimension",MsqError::INVALID_ARG); } }
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(); }
NodeSet<std::string> XPathDataModel::dataToNodeSet(const Data& data) { NodeSet<std::string> dataNodeSet; if (data.atom.length() > 0) { dataNodeSet.push_back(_doc.createTextNode(data.atom)); } return dataNodeSet; }
void Step::evaluate(EvaluationContext& evaluationContext, Node* context, NodeSet& nodes) const { evaluationContext.position = 0; nodesInAxis(evaluationContext, context, nodes); // Check predicates that couldn't be merged into node test. for (unsigned i = 0; i < m_predicates.size(); i++) { Predicate* predicate = m_predicates[i].get(); OwnPtrWillBeRawPtr<NodeSet> newNodes(NodeSet::create()); if (!nodes.isSorted()) newNodes->markSorted(false); for (unsigned j = 0; j < nodes.size(); j++) { Node* node = nodes[j]; evaluationContext.node = node; evaluationContext.size = nodes.size(); evaluationContext.position = j + 1; if (predicate->evaluate(evaluationContext)) newNodes->append(node); } nodes.swap(*newNodes); } }
NodeSet LinearPyramid::sample_points( NodeSet ) const { NodeSet result; result.set_all_corner_nodes(PYRAMID); result.clear_corner_node(4); return result; }
AttributeDeclarationSet DeclarationFactory::extractAttributes(Element* element__) { FE_TRACE(__F(("DeclarationFactory::extractAttributes - Extracting attributes for element %1%") % element__->get_name() )); NodeSet attributeSet = element__->find("*[local-name() = 'attribute']"); AttributeDeclarationSet attributeResults; for(Node* n : attributeSet) { Element* attributeElem = polymorphic_downcast<Element*>(n); if(!attributeElem->get_attribute_value("ref").empty()){ continue; } FE_TRACE(__F(("DeclarationFactory::extractAttributes - Extracting attribute %1%") % attributeElem->get_attribute_value("name") )); TypeDeclaration* typeDeclaration_; if(attributeElem->get_attribute_value("type").substr(0, 3) == "xs:") { typeDeclaration_ = createSimpleBaseTypeDeclaration(attributeElem->get_attribute_value("type")); } else { NodeSet simpleTypeSet = element__->find("//*[@name = '"+attributeElem->get_attribute_value("type")+"']"); typeDeclaration_ = createSimpleTypeDeclaration(polymorphic_downcast<Element*>(simpleTypeSet.front())); } string name_ = attributeElem->get_attribute_value("name"); bool required_ = attributeElem->get_attribute_value("use") == "required" ? true : false; bool fixed_ = attributeElem->get_attribute_value("fixed").empty() ? false : true; string defaultValue_ = ""; if(fixed_){ defaultValue_ = attributeElem->get_attribute_value("fixed"); } else{ defaultValue_ = attributeElem->get_attribute_value("default"); } attributeResults.push_back( new AttributeDeclaration(name_, typeDeclaration_, required_, defaultValue_, fixed_) ); } return attributeResults; }
void step(DhtRunner& dht, std::atomic_uint& done, std::shared_ptr<NodeSet> all_nodes, dht::InfoHash cur_h, unsigned cur_depth) { std::cout << "step at " << cur_h << ", depth " << cur_depth << std::endl; done++; dht.get(cur_h, [all_nodes](const std::vector<std::shared_ptr<Value>>& /*values*/) { return true; }, [&,all_nodes,cur_h,cur_depth](bool, const std::vector<std::shared_ptr<Node>>& nodes) { all_nodes->insert(nodes.begin(), nodes.end()); NodeSet sbuck {nodes.begin(), nodes.end()}; if (not sbuck.empty()) { unsigned bdepth = sbuck.size()==1 ? 0u : InfoHash::commonBits((*sbuck.begin())->id, (*std::prev(sbuck.end()))->id); unsigned target_depth = std::min(159u, bdepth+3u); std::cout << cur_h << " : " << nodes.size() << " nodes; target is " << target_depth << " bits deep (cur " << cur_depth << ")" << std::endl; for (unsigned b = cur_depth ; b < target_depth; b++) { auto new_h = cur_h; new_h.setBit(b, 1); step(dht, done, all_nodes, new_h, b+1); } } done--; std::cout << done.load() << " operations left, " << all_nodes->size() << " nodes found." << std::endl; cv.notify_one(); }); }
static void xemInstructionSetDocument ( __XProcHandlerArgs__ ) { if ( ! item.hasAttr(xem.href() ) ) { throwXemProcessorException ( "Instruction xem:set-document has no attribute xem:href\n" ); } if ( ! item.hasAttr(xem.select() ) ) { throwXemProcessorException ( "Instruction xem:set-document has no attribute xem:select\n" ); } String href = item.getEvaledAttr ( xproc, currentNode, xem.href() ); XPath selectXPath ( item, xem.select() ); NodeSet document; selectXPath.eval ( xproc, document, currentNode ); if ( ! document.isScalar() ) { throwXemProcessorException ( "Instruction xem:set-document : xem:select '%s' returns a non-scalar result !\n", item.getAttr (xem.select() ).c_str() ); } if ( ! document.front().isElement() ) { throwXemProcessorException ( "Instruction xem:set-document : xem:select '%s' returns a non-element result !\n", item.getAttr (xem.select() ).c_str() ); } ElementRef rootDocument = document.front().toElement(); xproc.setDocument ( href, rootDocument ); }
// 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; }
Value Filter::evaluate() const { Value result = m_expression->evaluate(); NodeSet& nodes = result.modifiableNodeSet(); nodes.sort(); EvaluationContext& evaluationContext = Expression::evaluationContext(); for (unsigned i = 0; i < m_predicates.size(); i++) { NodeSet newNodes; evaluationContext.size = nodes.size(); evaluationContext.position = 0; for (unsigned j = 0; j < nodes.size(); j++) { Node* node = nodes[j]; evaluationContext.node = node; ++evaluationContext.position; if (evaluatePredicate(*m_predicates[i])) newNodes.append(node); } nodes = WTF::move(newNodes); } return result; }
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; }
// ----------------------------------------------------------------------------- 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; }
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); }
explicit RemovePlaceholdersVisitor(AstNode* nodep) { iterate(nodep); for (NodeSet::const_iterator it = m_removeSet.begin(); it != m_removeSet.end(); ++it) { AstNode* np = *it; np->unlinkFrBack(); // Without next np->deleteTree(); VL_DANGLING(np); } }
void InterpreterDraft6::microstep(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) { #if VERBOSE std::cout << "Transitions: "; for (int i = 0; i < enabledTransitions.size(); i++) { std::cout << ((Element<std::string>)getSourceState(enabledTransitions[i])).getAttribute("id") << " -> " << std::endl; NodeSet<std::string> targetSet = getTargetStates(enabledTransitions[i]); for (int j = 0; j < targetSet.size(); j++) { std::cout << " " << ((Element<std::string>)targetSet[j]).getAttribute("id") << std::endl; } } std::cout << std::endl; #endif // --- MONITOR: beforeMicroStep ------------------------------ for(monIter_t monIter = _monitors.begin(); monIter != _monitors.end(); monIter++) { try { (*monIter)->beforeMicroStep(shared_from_this()); } USCXML_MONITOR_CATCH_BLOCK(beforeMicroStep) } exitStates(enabledTransitions); monIter_t monIter; for (int i = 0; i < enabledTransitions.size(); i++) { Element<std::string> transition(enabledTransitions[i]); // --- MONITOR: beforeTakingTransitions ------------------------------ for(monIter_t monIter = _monitors.begin(); monIter != _monitors.end(); monIter++) { try { (*monIter)->beforeTakingTransition(shared_from_this(), transition, (i + 1 < enabledTransitions.size())); } USCXML_MONITOR_CATCH_BLOCK(beforeTakingTransitions) } executeContent(transition); // --- MONITOR: afterTakingTransitions ------------------------------ for(monIter_t monIter = _monitors.begin(); monIter != _monitors.end(); monIter++) { try { (*monIter)->afterTakingTransition(shared_from_this(), transition, (i + 1 < enabledTransitions.size())); } USCXML_MONITOR_CATCH_BLOCK(afterTakingTransitions) } } enterStates(enabledTransitions); // --- MONITOR: afterMicroStep ------------------------------ for(monIter_t monIter = _monitors.begin(); monIter != _monitors.end(); monIter++) { try { (*monIter)->afterMicroStep(shared_from_this()); } USCXML_MONITOR_CATCH_BLOCK(afterMicroStep) } }