//Edge management void GVSubGraph::addEdge(const QString &source, const QString &target) { if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
bool TransCFG::hasArc(TransID srcId, TransID dstId) const { assertx(hasNode(srcId)); assertx(hasNode(dstId)); for (auto arc : outArcs(srcId)) { if (arc->dst() == dstId) return true; } return false; }
void GVSkeletonGraph::addEdge(const QString &source, const QString &target) { setlocale(LC_NUMERIC,"en_US.UTF-8"); // Débug séparateur de décimales en version française if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
void TransCFG::addArc(TransID srcId, TransID dstId, int64_t weight) { assertx(hasNode(srcId)); assertx(hasNode(dstId)); size_t srcIdx = m_idToIdx[srcId]; size_t dstIdx = m_idToIdx[dstId]; Arc* arc = new Arc(srcId, dstId, weight); m_nodeInfo[srcIdx].addOutArc(arc); m_nodeInfo[dstIdx].addInArc(arc); }
void GVSkeletonGraph::addEdge(const QString &source, const QString &target) { setlocale(LC_NUMERIC,"en_US.UTF-8"); if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
bool DirectedGraph::hasEdge(int fromNodeId, int toNodeId) { if (!hasNode(fromNodeId) || !hasNode(toNodeId)) return false; ListType* toNeighbors = outNeighborsTable[fromNodeId]; for (ListType::iterator neighbor = toNeighbors->begin(); neighbor != toNeighbors->end(); neighbor++) { if (*neighbor == toNodeId) return true; } return false; }
bool DirectedGraph::addEdge(int fromNodeId, int toNodeId) { if (hasEdge(fromNodeId, toNodeId)) return false; if (!hasNode(fromNodeId)) addNode(fromNodeId); if (!hasNode(toNodeId)) addNode(toNodeId); ListType* fromNeighbors = inNeighborsTable[toNodeId]; fromNeighbors->push_back(fromNodeId); ListType* toNeighbors = outNeighborsTable[fromNodeId]; toNeighbors->push_back(toNodeId); edgeCount++; return true; }
set<E> Graph<E>::getConnected(E e) { set<E> s; if (hasNode(e)) s.insert(graph[e].begin(), graph[e].end()); return s; }
TransCFG::TransCFG(FuncId funcId, const ProfData* profData, const SrcDB& srcDB, const TcaTransIDMap& jmpToTransID) { assertx(profData); // add nodes for (auto tid : profData->funcProfTransIDs(funcId)) { assertx(profData->transRegion(tid) != nullptr); // This will skip DV Funclets if they were already // retranslated w/ the prologues: if (!profData->optimized(profData->transSrcKey(tid))) { int64_t weight = profData->absTransCounter(tid); addNode(tid, weight); } } // add arcs for (TransID dstId : nodes()) { SrcKey dstSK = profData->transSrcKey(dstId); RegionDesc::BlockPtr dstBlock = profData->transRegion(dstId)->entry(); FTRACE(5, "TransCFG: adding incoming arcs in dstId = {}\n", dstId); TransIDSet predIDs = findPredTrans(dstId, profData, srcDB, jmpToTransID); for (auto predId : predIDs) { if (hasNode(predId)) { auto predPostConds = profData->transRegion(predId)->blocks().back()->postConds(); SrcKey predSK = profData->transSrcKey(predId); if (preCondsAreSatisfied(dstBlock, predPostConds) && predSK.resumed() == dstSK.resumed()) { FTRACE(5, "TransCFG: adding arc {} -> {} ({} -> {})\n", predId, dstId, showShort(predSK), showShort(dstSK)); addArc(predId, dstId, TransCFG::Arc::kUnknownWeight); } } } } // infer arc weights bool changed; do { changed = false; for (TransID tid : nodes()) { int64_t nodeWeight = weight(tid); if (inferredArcWeight(inArcs(tid), nodeWeight)) changed = true; if (inferredArcWeight(outArcs(tid), nodeWeight)) changed = true; } } while (changed); // guess weight for non-inferred arcs for (TransID tid : nodes()) { for (auto arc : outArcs(tid)) { if (arc->weight() == Arc::kUnknownWeight) { arc->setGuessed(); int64_t arcWgt = std::min(weight(arc->src()), weight(arc->dst())) / 2; arc->setWeight(arcWgt); } } } }
void Player::conquerNode(Node *node) { if(!hasNode(node)) { if(node->owner != Model::getSelf()->nullPlayer) node->owner->surrenderNode(node); myNodes[nodesOwned+1] = node; switch(node->type) { case TYPE_WATER: waterNodesOwned++; break; case TYPE_EARTH: earthNodesOwned++; break; case TYPE_WIND: windNodesOwned++; break; case TYPE_FIRE: fireNodesOwned++; break; case TYPE_DARK: darkNodesOwned++; break; } nodesOwned++; node->owner = this; } }
unsigned int TagTree::getSubNodePos( const std::string nodeKey, const std::string parentKey, int skip ) { Node* parent = NULL; if( parentKey.empty() ) { parent = &rootNode.children.front(); } else { if ( ! hasNode( parentKey ) ) Log::error( "parent key %s does not exist", parentKey.c_str() ); parent = tagMap[parentKey]; } unsigned int pos = 1; NodeListIter iter; for( iter = parent->children.begin(); iter != parent->children.end() && ( !( (iter->key == (parentKey.empty() ? nodeKey : parentKey + nodeKey)) && skip--<=0 )) ; iter++, pos++ ); if( iter == parent->children.end() ) pos = 0; return pos; }
bool DirectedGraph::addNode(int nodeId) { if (!hasNode(nodeId)) { inNeighborsTable[nodeId] = new ListType(); outNeighborsTable[nodeId] = new ListType(); return true; } return false; }
bool SkinContext::selectBool(const QDomNode& node, const QString& nodeName, bool defaultValue) const { if (hasNode(node, nodeName)) { QString stringValue = selectString(node, nodeName); return stringValue.contains("true", Qt::CaseInsensitive); } return defaultValue; }
void DirectedGraph::sort() { for (int id = 0; id != maxNodeId + 1; id++) { if (hasNode(id)) { ListType* fromNeighbors = inNeighborsTable[id]; ListType* toNeighbors = outNeighborsTable[id]; std::sort(fromNeighbors->begin(), fromNeighbors->end()); std::sort(toNeighbors->begin(), toNeighbors->end()); } } }
BayesNet::Node* BayesNet::createNode( int attribIndex, int numValues ) { mlAssert( attribIndex >= 0 ); mlAssert( numValues >= 2 ); mlAssert( !hasNode(attribIndex) ); Node* node = new Node( attribIndex, numValues ); mNodes.insert( std::make_pair( attribIndex, node ) ); return node; }
DirectedGraph::~DirectedGraph() { if (outNeighborsTable == NULL && inNeighborsTable == NULL) return; for (int nodeId = 0; nodeId != maxNodeId + 1; nodeId++) { if (hasNode(nodeId)) { delete inNeighborsTable[nodeId]; delete outNeighborsTable[nodeId]; } } delete[] inNeighborsTable; delete[] outNeighborsTable; }
TransCFG::TransCFG(FuncId funcId, const ProfData* profData, const SrcDB& srcDB, const TcaTransIDMap& jmpToTransID) { assert(profData); // add nodes for (TransID tid = 0; tid < profData->numTrans(); tid++) { if (profData->transKind(tid) == TransProfile && profData->transRegion(tid) != nullptr && profData->transFuncId(tid) == funcId) { int64_t counter = profData->transCounter(tid); int64_t weight = RuntimeOption::EvalJitPGOThreshold - counter; addNode(tid, weight); } } // add arcs for (TransID dstId : nodes()) { SrcKey dstSK = profData->transSrcKey(dstId); const SrcRec* dstSR = srcDB.find(dstSK); FTRACE(5, "TransCFG: adding incoming arcs in dstId = {}\n", dstId); TransIDSet predIDs = findPredTrans(dstSR, jmpToTransID); for (auto predId : predIDs) { if (hasNode(predId)) { FTRACE(5, "TransCFG: adding arc {} -> {}\n", predId, dstId); addArc(predId, dstId, TransCFG::Arc::kUnknownWeight); } } } // infer arc weights bool changed; do { changed = false; for (TransID tid : nodes()) { int64_t nodeWeight = weight(tid); if (inferredArcWeight(inArcs(tid), nodeWeight)) changed = true; if (inferredArcWeight(outArcs(tid), nodeWeight)) changed = true; } } while (changed); // guess weight or non-inferred arcs for (TransID tid : nodes()) { for (auto arc : outArcs(tid)) { if (arc->weight() == Arc::kUnknownWeight) { arc->setGuessed(); int64_t arcWgt = std::min(weight(arc->src()), weight(arc->dst())) / 2; arc->setWeight(arcWgt); } } } }
bool AStarLiteOpen::insert(const AStarLiteNode& node) { int nodeId = node.m_id; // can't have multiple nodes with same id if(hasNode(nodeId)) return false; // insert NodeSetIter nodeIter = m_openSet.insert(node); m_nodeMap[nodeId] = nodeIter; return true; }
bool OsmDataMemory::hasEntity( const OsmStructures::EntityReference &ref) const { bool result; switch (ref.type) { case OsmStructures::EnumOsmNode: result = hasNode(ref.id); break; case OsmStructures::EnumOsmWay: result = hasWay(ref.id); break; case OsmStructures::EnumOsmRelation: result = hasRelation(ref.id); break; } return result; }
UndirectedGraph* DirectedGraph::convertToUndirectedGraph() { UndirectedGraph* result = new UndirectedGraph(maxNodeId); for (int i = 0; i != maxNodeId + 1; i++) { if (!hasNode(i)) continue; ListType* neighborsList = inNeighborsTable[i]; for (ListType::iterator neighbor = neighborsList->begin(); neighbor != neighborsList->end(); neighbor++) { result->addEdge(*neighbor, i); } neighborsList = outNeighborsTable[i]; for (ListType::iterator neighbor = neighborsList->begin(); neighbor != neighborsList->end(); neighbor++) { result->addEdge(*neighbor, i); } } result->sort(); return result; }
void insertAfter(List* list, Node* a, Node* b){ if(!hasNode(list, a)){ return; } if(a == NULL){ b->prev = NULL; b->next = list->head; list->head = b; }else{ b->prev = a; b->next = a->next; a->next = b; } if(b->next == NULL){ list->tail = b; } }
void removeNode(List* list, Node* n){ if(!hasNode(list, n)){ return; } Node* prev = n->prev; Node* next = n->next; if(prev == NULL){ list->head = next; }else{ prev->next = next; } if(next == NULL){ list->tail = prev; }else{ next->prev = prev; } n->prev = NULL; n->next = NULL; }
const TransCFG::ArcPtrVec& TransCFG::outArcs(TransID id) const { assertx(hasNode(id)); size_t idx = folly::get_default(m_idToIdx, id); return m_nodeInfo[idx].outArcs(); }
int64_t TransCFG::weight(TransID id) const { assertx(hasNode(id)); size_t idx = folly::get_default(m_idToIdx, id); return m_nodeInfo[idx].weight(); }
TransCFG::TransCFG(FuncId funcId, const ProfData* profData, bool inlining /* = false */) { assertx(profData); // add nodes for (auto const tid : profData->funcProfTransIDs(funcId)) { auto const rec = profData->transRec(tid); assertx(rec->region() != nullptr); // This will skip DV Funclets if they were already // retranslated w/ the prologues: if (inlining || !profData->optimized(rec->srcKey())) { int64_t weight = profData->transCounter(tid); addNode(tid, weight); } } // add arcs for (auto const dstId : nodes()) { auto const rec = profData->transRec(dstId); auto const dstSK = rec->srcKey(); auto const dstBlock = rec->region()->entry(); FTRACE(5, "TransCFG: adding incoming arcs in dstId = {}\n", dstId); TransIDSet predIDs = findPredTrans(dstId, profData); for (auto predId : predIDs) { if (hasNode(predId)) { auto const predRec = profData->transRec(predId); auto const predBlock = predRec->region()->blocks().back(); auto const& postConds = predBlock->postConds(); auto predPostConds = postConds.changed; predPostConds.insert(predPostConds.end(), postConds.refined.begin(), postConds.refined.end()); auto const predSK = predRec->srcKey(); if (preCondsAreSatisfied(dstBlock, predPostConds) && predSK.resumed() == dstSK.resumed()) { FTRACE(5, "TransCFG: adding arc {} -> {} ({} -> {})\n", predId, dstId, showShort(predSK), showShort(dstSK)); addArc(predId, dstId, TransCFG::Arc::kUnknownWeight); } } } } // infer arc weights bool changed; do { changed = false; for (auto const tid : nodes()) { auto const nodeWeight = weight(tid); if (inferredArcWeight(inArcs(tid), nodeWeight)) changed = true; if (inferredArcWeight(outArcs(tid), nodeWeight)) changed = true; } } while (changed); // guess weight for non-inferred arcs for (auto const tid : nodes()) { for (auto arc : outArcs(tid)) { if (arc->weight() == Arc::kUnknownWeight) { arc->setGuessed(); auto arcWgt = std::min(weight(arc->src()), weight(arc->dst())) / 2; arc->setWeight(arcWgt); } } } }
int64_t TransCFG::weight(TransID id) const { assert(hasNode(id)); size_t idx = mapGet(m_idToIdx, id); return m_nodeInfo[idx].weight(); }
// static QuerySolution* QueryPlannerAnalysis::analyzeDataAccess(const CanonicalQuery& query, const QueryPlannerParams& params, QuerySolutionNode* solnRoot) { auto_ptr<QuerySolution> soln(new QuerySolution()); soln->filterData = query.getQueryObj(); verify(soln->filterData.isOwned()); soln->ns = query.ns(); soln->indexFilterApplied = params.indexFiltersApplied; solnRoot->computeProperties(); // solnRoot finds all our results. Let's see what transformations we must perform to the // data. // If we're answering a query on a sharded system, we need to drop documents that aren't // logically part of our shard (XXX GREG elaborate more precisely) if (params.options & QueryPlannerParams::INCLUDE_SHARD_FILTER) { // XXX TODO: use params.shardKey to do fetch analysis instead of always fetching. if (!solnRoot->fetched()) { FetchNode* fetch = new FetchNode(); fetch->children.push_back(solnRoot); solnRoot = fetch; } ShardingFilterNode* sfn = new ShardingFilterNode(); sfn->children.push_back(solnRoot); solnRoot = sfn; } solnRoot = analyzeSort(query, params, solnRoot, &soln->hasSortStage); // This can happen if we need to create a blocking sort stage and we're not allowed to. if (NULL == solnRoot) { return NULL; } // If we can (and should), add the keep mutations stage. // We cannot keep mutated documents if: // // 1. The query requires an index to evaluate the predicate ($text). We can't tell whether // or not the doc actually satisfies the $text predicate since we can't evaluate a // text MatchExpression. // // 2. The query implies a sort ($geoNear). It would be rather expensive and hacky to merge // the document at the right place. // // 3. There is an index-provided sort. Ditto above comment about merging. // XXX; do we want some kind of static init for a set of stages we care about & pass that // set into hasNode? bool cannotKeepFlagged = hasNode(solnRoot, STAGE_TEXT) || hasNode(solnRoot, STAGE_GEO_NEAR_2D) || hasNode(solnRoot, STAGE_GEO_NEAR_2DSPHERE) || (!query.getParsed().getSort().isEmpty() && !soln->hasSortStage); // Only these stages can produce flagged results. A stage has to hold state past one call // to work(...) in order to possibly flag a result. bool couldProduceFlagged = hasNode(solnRoot, STAGE_GEO_2D) || hasNode(solnRoot, STAGE_AND_HASH) || hasNode(solnRoot, STAGE_AND_SORTED) || hasNode(solnRoot, STAGE_FETCH); bool shouldAddMutation = !cannotKeepFlagged && couldProduceFlagged; if (shouldAddMutation && (params.options & QueryPlannerParams::KEEP_MUTATIONS)) { KeepMutationsNode* keep = new KeepMutationsNode(); // We must run the entire expression tree to make sure the document is still valid. keep->filter.reset(query.root()->shallowClone()); if (STAGE_SORT == solnRoot->getType()) { // We want to insert the invalidated results before the sort stage, if there is one. verify(1 == solnRoot->children.size()); keep->children.push_back(solnRoot->children[0]); solnRoot->children[0] = keep; } else { keep->children.push_back(solnRoot); solnRoot = keep; } } // Project the results. if (NULL != query.getProj()) { QLOG() << "PROJECTION: fetched status: " << solnRoot->fetched() << endl; QLOG() << "PROJECTION: Current plan is:\n" << solnRoot->toString() << endl; if (query.getProj()->requiresDocument()) { QLOG() << "PROJECTION: claims to require doc adding fetch.\n"; // If the projection requires the entire document, somebody must fetch. if (!solnRoot->fetched()) { FetchNode* fetch = new FetchNode(); fetch->children.push_back(solnRoot); solnRoot = fetch; } } else { QLOG() << "PROJECTION: requires fields\n"; const vector<string>& fields = query.getProj()->getRequiredFields(); bool covered = true; for (size_t i = 0; i < fields.size(); ++i) { if (!solnRoot->hasField(fields[i])) { QLOG() << "PROJECTION: not covered cuz doesn't have field " << fields[i] << endl; covered = false; break; } } QLOG() << "PROJECTION: is covered?: = " << covered << endl; // If any field is missing from the list of fields the projection wants, // a fetch is required. if (!covered) { FetchNode* fetch = new FetchNode(); fetch->children.push_back(solnRoot); solnRoot = fetch; } } // We now know we have whatever data is required for the projection. ProjectionNode* projNode = new ProjectionNode(); projNode->children.push_back(solnRoot); projNode->fullExpression = query.root(); projNode->projection = query.getParsed().getProj(); solnRoot = projNode; } else { // If there's no projection, we must fetch, as the user wants the entire doc. if (!solnRoot->fetched()) { FetchNode* fetch = new FetchNode(); fetch->children.push_back(solnRoot); solnRoot = fetch; } } if (0 != query.getParsed().getSkip()) { SkipNode* skip = new SkipNode(); skip->skip = query.getParsed().getSkip(); skip->children.push_back(solnRoot); solnRoot = skip; } // When there is both a blocking sort and a limit, the limit will // be enforced by the blocking sort. // Otherwise, we need to limit the results in the case of a hard limit // (ie. limit in raw query is negative) if (0 != query.getParsed().getNumToReturn() && !soln->hasSortStage && !query.getParsed().wantMore()) { LimitNode* limit = new LimitNode(); limit->limit = query.getParsed().getNumToReturn(); limit->children.push_back(solnRoot); solnRoot = limit; } soln->root.reset(solnRoot); return soln.release(); }
std::string TagTree::getComment(const std::string key) { if ( !hasNode(key) ) Log::error("key %s does not exist",key.c_str()); return tagMap[key]->comment; }
const TransCFG::ArcPtrVec& TransCFG::outArcs(TransID id) const { assert(hasNode(id)); size_t idx = mapGet(m_idToIdx, id); return m_nodeInfo[idx].outArcs(); }
BayesNet::Node* BayesNet::getNode( int attribIndex ) const { mlAssert( hasNode(attribIndex) ); return mNodes.find(attribIndex)->second; }