InvokeEntry* lookupInvokeEntry(ObjectPtr callable, llvm::ArrayRef<TypePtr> argsKey, llvm::ArrayRef<ValueTempness> argsTempness, MatchFailureError &failures) { InvokeSet* invokeSet = lookupInvokeSet(callable, argsKey); map<vector<ValueTempness>,InvokeEntry*>::iterator iter = invokeSet->tempnessMap.find(argsTempness); if (iter != invokeSet->tempnessMap.end()) return iter->second; MatchResultPtr interfaceResult; if (invokeSet->interface != NULL) { interfaceResult = matchInvoke(invokeSet->interface, invokeSet->callable, invokeSet->argsKey); if (interfaceResult->matchCode != MATCH_SUCCESS) { failures.failedInterface = true; failures.failures.push_back(make_pair(invokeSet->interface, interfaceResult)); return NULL; } } MatchSuccessPtr match; vector<ValueTempness> tempnessKey; vector<uint8_t> forwardedRValueFlags; unsigned i = 0; while ((match = getMatch(invokeSet,i,failures)).ptr() != NULL) { if (matchTempness(match->code, argsTempness, match->callByName, tempnessKey, forwardedRValueFlags)) { break; } ++i; } if (!match) return NULL; iter = invokeSet->tempnessMap2.find(tempnessKey); if (iter != invokeSet->tempnessMap2.end()) { invokeSet->tempnessMap[argsTempness] = iter->second; return iter->second; } InvokeEntry* entry = newInvokeEntry(invokeSet, match, (MatchSuccess*)interfaceResult.ptr()); entry->forwardedRValueFlags = forwardedRValueFlags; invokeSet->tempnessMap2[tempnessKey] = entry; invokeSet->tempnessMap[argsTempness] = entry; return entry; }
// lookup - determine which bucket; determine if there // is a value with the given key in that bucket void *lookup(Hashtable *h, Hashkey key, compare mf) { int index = hash(key, h->num_buckets); void *data = NULL; List *bucket = h->buckets[index]; if (bucket != NULL) { data = getMatch(bucket, mf, key); } return data; }
/** implementation of depth first search */ bool RamMaxMatching::dfSearch(SearchColumns u) { if (u != 0) { Edges& children = graph[u]; for (Edges::iterator it = children.begin(); it != children.end(); ++it) { SearchColumns v = *it; if (getDistance(getMatch(v)) == getDistance(u)+1) { if (dfSearch(getMatch(v))) { match[u] = v; match[v] = u; return true; } } } distance[u] = INF; return false; } return true; }
// Join the edge pEdge into this edge, adding to the start void Edge::join(const Edge* pEdge) { // Update the match coordinate Match m12 = pEdge->getMatch(); Match m23 = getMatch(); m_matchCoord = m12.inverseTranslate(m23.coord[0]); if(pEdge->getComp() == EC_REVERSE) flip(); // Now, update the twin of this edge to extend to the twin of pEdge m_pTwin->extend(pEdge->getTwin()); }
/** implementation of bredth first search */ bool RamMaxMatching::bfSearch() { SearchColumns u; std::queue<SearchColumns> bfQueue; // Build layers for (Graph::iterator it = graph.begin(); it != graph.end(); ++it) { if (getMatch(it->first) == NIL) { distance[it->first] = 0; bfQueue.push(it->first); } else { distance[it->first] = INF; } } distance[NIL] = INF; while (!bfQueue.empty()) { u = bfQueue.front(); bfQueue.pop(); ASSERT(u != NIL); const Edges& children = graph[u]; for (Edges::iterator it = children.begin(); it != children.end(); ++it) { SearchColumns mv = getMatch(*it); if (getDistance(mv) == INF) { distance[mv] = getDistance(u) + 1; if (mv != NIL) bfQueue.push(mv); } } } return (getDistance(0) != INF); }
std::string DidYouMean::getMatchAsString(std::string input, int prefixNewLines, int suffixNewLines) { std::vector<std::string> matches = getMatch(input); std::ostringstream oss; if (matches.size() > 0) { while (prefixNewLines-- > 0) { oss << std::endl; } if (matches.size() == 1) { oss << "Did you mean this?"; } else { oss << "Did you mean any of these?"; } for (unsigned i = 0; i < matches.size(); ++i) { oss << "\n " << matches[i]; } while (suffixNewLines-- > 0) { oss << std::endl; } } return oss.str(); }
uint8_t ADMVideoTelecide::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t uvlen; uint32_t dummylen; uint8_t motion; uint32_t cmatch,nmatch,n2match; ADMImage *cur,*next; if(frame>=_info.nb_frames) return 0; uvlen= _info.width*_info.height; *len=uvlen+(uvlen>>1); cur=vidCache->getImage(frame); if(!cur) return 0; data->copyInfo(cur); if(!frame || frame==_info.nb_frames-1) { data->duplicate(cur); vidCache->unlockAll(); return 1; } next=vidCache->getImage(frame-1); if(!next) { vidCache->unlockAll(); return 0; } // for u & v , no action -> copy it as is memcpy(UPLANE(data),UPLANE(cur),uvlen>>2); memcpy(VPLANE(data),VPLANE(cur),uvlen>>2); data->copyInfo(cur); // No interleaving detected if(!(motion=hasMotion(data)) ) { printf("\n Not interlaced !\n"); memcpy(YPLANE(data),YPLANE(cur),uvlen); vidCache->unlockAll(); return 1; // over ! } // else cmatch is the current match cmatch=getMatch(cur); /* ------------------------------------------------------------------------------------ Try to complete with next frame fields ----------------------------------------------------------------------------------- */ // Interleav next in even field interleave(cur,_uncompressed,1); interleave(next,_uncompressed,0); nmatch=getMatch(_uncompressed); interleave(cur,_uncompressed,0); interleave(next,_uncompressed,1); n2match=getMatch(_uncompressed); printf(" Cur : %lu \n",cmatch); printf(" Next : %lu \n",nmatch); printf(" NextP: %lu \n",n2match); if((cmatch<nmatch)&&(cmatch<n2match)) { printf("\n __ pure interlaced __\n"); interleave(cur,_uncompressed,0); interleave(cur,_uncompressed,1); hasMotion(_uncompressed); doBlend(_uncompressed,data); vidCache->unlockAll(); return 1; } if( nmatch > n2match) { printf("\n -------Shifted-P is better \n"); if(hasMotion(_uncompressed)) { doBlend(_uncompressed,data); printf(" but there is still motion \n"); } else data->duplicate(_uncompressed); } else { printf("\n -------Shifted-O is better \n"); interleave(cur,_uncompressed,1); interleave(next,_uncompressed,0); if(hasMotion(_uncompressed)) { doBlend(_uncompressed,data); printf(" but there is still motion \n"); } else data->duplicate(_uncompressed); } // which chroma is better ? from current or from next ? // search for a transition and see if there is also one ? vidCache->unlockAll(); return 1; }
// The overlap structure implied by this edge Overlap Edge::getOverlap() const { return Overlap(getStartID(), getEndID(), getMatch()); }
bool ComplexExplanation::isMatch() { return getMatch(); }
uint8_t ADMVideoTelecide::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, uint8_t *data, uint32_t *flags) { uint32_t uvlen; uint32_t dummylen; uint8_t motion; uint32_t cmatch,nmatch,n2match; assert(frame<_info.nb_frames); assert(_uncompressed); uvlen= _info.width*_info.height; *len=uvlen+(uvlen>>1); if(_instock!=frame) { // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, &dummylen,_uncompressed,flags)) return 0; } else { memcpy(_uncompressed,_next,*len); } // for u & v , no action -> copy it as is memcpy(data,_uncompressed,(uvlen*3)>>1); if(frame==_info.nb_frames-1) return 1; // No interleaving detected if(!(motion=hasMotion()) ) { printf("\n Not interlaced !\n"); return 1; // over ! } cmatch=getMatch(); /* ------------------------------------------------------------------------------------ Try to complete with next frame fields ------------------------------------------------------------------------------------ */ if(!_in->getFrameNumberNoAlloc(frame+1, &dummylen,_next,flags)) return 0; _instock=frame+1; interleave(_next,0); nmatch=getMatch(); memcpy(_uncompressed,data,_info.width*_info.height); interleave(_next,1); n2match=getMatch(); printf(" Cur : %lu \n",cmatch); printf(" Next : %lu \n",nmatch); printf(" NextP: %lu \n",n2match); if((cmatch<nmatch)&&(cmatch<n2match)) { printf("\n __ pure interlaced __\n"); memcpy(_uncompressed,data,_info.width*_info.height); hasMotion(); doBlend(data); return 1; } if( nmatch > n2match) { printf("\n -------Shifted-P is better \n"); if(hasMotion()) { doBlend(data); printf(" but there is still motion \n"); } } else { printf("\n -------Shifted-O is better \n"); memcpy(_uncompressed,data,_info.width*_info.height); interleave(_next,0); if(hasMotion()) { doBlend(data); printf(" but there is still motion \n"); } } // which chroma is better ? from current or from next ? // search for a transition and see if there is also one ? return 1; }
InvokeEntry* lookupInvokeEntry(ObjectPtr callable, llvm::ArrayRef<PVData> args, MatchFailureError &failures) { vector<TypePtr> argTypes; vector<bool> argRValues; argTypes.reserve(args.size()); argRValues.reserve(args.size()); for (llvm::ArrayRef<PVData>::const_iterator arg = args.begin(); arg != args.end(); ++arg) { argTypes.push_back(arg->type); argRValues.push_back(arg->isRValue); } InvokeSet* invokeSet = lookupInvokeSet(callable, argTypes); if (invokeSet->evaluatingPredicate) { // matchInvoke calls the same lookupInvokeEntry error("predicate evaluation loop"); } invokeSet->evaluatingPredicate = true; FinallyClearEvaluatingPredicate FinallyClearEvaluatingPredicate(invokeSet); map<vector<bool>, InvokeEntry*>::iterator iter1 = invokeSet->tempnessMap.find(argRValues); if (iter1 != invokeSet->tempnessMap.end()) return iter1->second; MatchResultPtr interfaceResult; if (invokeSet->interface != NULL) { interfaceResult = matchInvoke(invokeSet->interface, invokeSet->callable, invokeSet->argsKey); if (interfaceResult->matchCode != MATCH_SUCCESS) { failures.failedInterface = true; failures.failures.push_back(make_pair(invokeSet->interface, interfaceResult)); return NULL; } } MatchSuccessPtr match; vector<ValueTempness> tempnessKey; vector<uint8_t> forwardedRValueFlags; unsigned i = 0; while ((match = getMatch(invokeSet,i,failures)).ptr() != NULL) { tempnessKey.clear(); forwardedRValueFlags.clear(); if (matchTempness(match->overload->code, argRValues, match->overload->callByName, tempnessKey, forwardedRValueFlags)) { break; } ++i; } if (!match) return NULL; map<vector<ValueTempness>, InvokeEntry*>::iterator iter2 = invokeSet->tempnessMap2.find(tempnessKey); if (iter2 != invokeSet->tempnessMap2.end()) { invokeSet->tempnessMap[argRValues] = iter2->second; return iter2->second; } InvokeEntry* entry = newInvokeEntry(invokeSet, match, (MatchSuccess*)interfaceResult.ptr()); entry->forwardedRValueFlags = forwardedRValueFlags; invokeSet->tempnessMap2[tempnessKey] = entry; invokeSet->tempnessMap[argRValues] = entry; if (_finalOverloadsEnabled) { MatchSuccessPtr match2; vector<ValueTempness> tempnessKey2; vector<uint8_t> forwardedRValueFlags2; unsigned j = invokeSet->nextOverloadIndex; while ((match2 = findMatchingInvoke(callableOverloads(callable), j, callable, argTypes, failures)).ptr() != NULL) { if (matchTempness(match2->overload->code, argRValues, match2->overload->callByName, tempnessKey2, forwardedRValueFlags2)) { break; } ++j; } if (match2 != NULL && !match2->overload->isDefault) { failures.ambiguousMatch = true; return NULL; } } return entry; }
int SearchDialog::find() { QRegExp searchTextRegExp; QDltMsg msg; QByteArray buf; QString text; int searchLine; int searchBorder; if(file->sizeFilter()==0) return 0; //setSearchColour(QColor(0,0,0),QColor(255,255,255)); if(getMatch() || getSearchFromBeginning()==false){ QModelIndexList list = table->selectionModel()->selection().indexes(); if(list.count()<=0) { QMessageBox::critical(0, QString("DLT Viewer"),QString("No message selected")); setMatch(false); //table->clearSelection(); //setSearchColour(QColor(255,255,255),QColor(255,102,102)); return 0; } QModelIndex index; for(int num=0; num < list.count();num++) { index = list[num]; if(index.column()==0) { break; } } setStartLine(index.row()); } searchLine = getStartLine(); searchBorder = getStartLine();; if(searchBorder < 0){ if(getNextClicked()){ searchBorder = file->sizeFilter()==0?0:file->sizeFilter()-1; }else{ searchBorder = 0; } } if(getRegExp()) { searchTextRegExp.setPattern(getText()); searchTextRegExp.setCaseSensitivity(getCaseSensitive()?Qt::CaseSensitive:Qt::CaseInsensitive); if (!searchTextRegExp.isValid()) { QMessageBox::warning(0, QString("Search"), QString("Invalid regular expression!")); //setSearchColour(QColor(255,255,255),QColor(255,102,102)); return 0; } } QProgressDialog fileprogress("Searching...", "Abort", 0, file->sizeFilter(), this); fileprogress.setWindowTitle("DLT Viewer"); fileprogress.setWindowModality(Qt::WindowModal); fileprogress.show(); do { if(getNextClicked()){ searchLine++; if(searchLine >= file->sizeFilter()){ searchLine = 0; //QMessageBox::information(0, QString("Search"),QString("End of file reached. Search start from top.")); } }else{ searchLine--; if(searchLine <= -1){ searchLine = file->sizeFilter()-1; //QMessageBox::information(0, QString("Search"),QString("Top of file reached. Search start from bottom.")); } } //qDebug()<<"startLine: "<<getStartLine(); //qDebug()<<"searchBorder: "<<searchBorder; //qDebug()<<"searchLine: "<<searchLine; if(getNextClicked()){ fileprogress.setValue(searchLine+1); }else{ fileprogress.setValue(file->sizeFilter()-searchLine); } /* get the message with the selected item id */ buf = file->getMsgFilter(searchLine); msg.setMsg(buf); for(int num2 = 0; num2 < plugin->topLevelItemCount (); num2++) { PluginItem *item = (PluginItem*)plugin->topLevelItem(num2); if(item->getMode() != item->ModeDisable && item->plugindecoderinterface && item->plugindecoderinterface->isMsg(msg,1)) { item->plugindecoderinterface->decodeMsg(msg,1); break; } } bool pluginFound = false; /* search header */ if(!pluginFound || text.isEmpty()) { text += msg.toStringHeader(); } if(getHeader()) { if (getRegExp()) { if(text.contains(searchTextRegExp)) { table->selectRow(searchLine); setStartLine(searchLine); setMatch(true); break; }else { setMatch(false); } } else { if(text.contains(getText(),getCaseSensitive()? Qt::CaseSensitive : Qt::CaseInsensitive )) { table->selectRow(searchLine); setStartLine(searchLine); setMatch(true); break; }else { setMatch(false); } } } /* search payload */ text.clear(); if(!pluginFound || text.isEmpty()) { text += msg.toStringPayload(); } if(getPayload()) { if (getRegExp()) { if(text.contains(searchTextRegExp)) { table->selectRow(searchLine); setMatch(true); setStartLine(searchLine); break; }else { setMatch(false); } } else { if(text.contains(getText(),getCaseSensitive()?Qt::CaseSensitive:Qt::CaseInsensitive)) { table->selectRow(searchLine); setMatch(true); setStartLine(searchLine); break; } else { setMatch(false); } } } }while(searchBorder != searchLine); if(getMatch()) { return 1; } //table->clearSelection(); //setSearchColour(QColor(255,255,255),QColor(255,102,102)); return 0; }
int main_part2(void) { //firstly execute a test for centrality metrics on small graphs int m = 2; int c = 3; testBetweennessCentrality(m, c); testClosenessCentrality(m, c); //small example for trust graph estimation testTidalTrust(m, c); /*create graph from file*/ int bucketsNumber = 5; int bucketSize = 10; Graph* g = loadGraph(bucketsNumber, bucketSize); //graph metrics calls //plot the graph degree distribution degreeDistribution(g, false); int diam = diameter(g); CHECKINT("Graph diameter", diam, 14); double avgPthLgth = averagePathLength(g); CHECKDOUBLE("Graph average path length", avgPthLgth, 5.0753); int ccNumber = numberOfCCs(g); CHECKINT("Graph number of components ", ccNumber, 1); int maximumCC = maxCC(g); CHECKINT("Graph maximum connected component ", maximumCC, 111); double dense = density(g); CHECKDOUBLE("Graph density ", dense, 0.073); /* * WRONG CALCULATIONS - only considering neighbors and not multi-step paths! int closenessIds[5] = { 1734, 38, 8899, 3501, 75}; float closenessIdsRes[5] = {0.109, 0.090, 0.072, 0.045, 0.009}; for (i = 0; i < 5; ++i) { int nodeID = closenessIds[i]; Node* node = lookupNode(nodeID, g); double closCentrty = closenessCentrality(node, g); CHECKDOUBLE("Graph closeness centrality ", closCentrty, closenessIdsRes[i]); } */ int i, k; int betweennessIds[5] = { 1734, 38, 8899, 9900, 75}; float betweennessIdsRes[5] = { 0.306, 0.053, 0.018, 0.005, 0.000}; for (i = 0; i < 5; ++i) { int nodeID = betweennessIds[i]; Node* node = lookupNode(nodeID, g); double betwCentrty = betweennessCentrality(node, g); CHECKDOUBLE("Graph betweenness centrality ", betwCentrty, betweennessIdsRes[i]); } //graph queries calls // Query 1 // Matches* match; Node *dateNode = lookupNode(3755, g); int commonInterests = 1, ageDiff = 30, acquaintanceHops = 3, matchesNum = 1; match = matchSuggestion(dateNode, commonInterests, acquaintanceHops, ageDiff, matchesNum, g); //match result : 7107 - work_at_organization: 1650 //get first pair's person ids int id1 = getMatch(0, match); CHECKINT("Query 1: Date result 1st id", id1, 7107); delete match; // Query 2 // //estimate stalkers graph with closeness centrality Graph* stalkersGraphCloseCentr; int stalkersNum = 7, likesNumber = 1, centralityMode = 1; Stalkers* stalkersCloseCentr = new Stalkers(stalkersNum); stalkersGraphCloseCentr = getTopStalkers(stalkersNum, likesNumber, centralityMode, g, stalkersCloseCentr); int stalkersResultsIds[] = {347, 495, 7768, 8354, 8403, 8899, 9633}; int stalkerResultSize = 7; int stalkerID; int counter = 0; for (int i = 0; i < stalkersNum; ++i) { stalkerID = getStalkerID(i, stalkersCloseCentr); if (stalkerID != -1) { ++counter; } for (k = 0; k < stalkerResultSize; ++k) { if (stalkersResultsIds[k] == stalkerID) { break; } } if (k == stalkerResultSize) { printf("You wrongly labeled person with id %d as Stalker\n", stalkerID); } } CHECKINT("Query 2: Stalker closeness results size", stalkerResultSize, counter); //run metrics on stalker-graph stalkersGraphRunMetrics(stalkersGraphCloseCentr); //estimate stalkers graph with betweenness centrality Graph* stalkersGraphBetwCentr; Stalkers* stalkersBetwCentr = new Stalkers(stalkersNum); centralityMode = 2; stalkersGraphBetwCentr = getTopStalkers(stalkersNum, likesNumber, centralityMode, g, stalkersBetwCentr); counter = 0; for (int i = 0; i < stalkersNum; ++i) { stalkerID = getStalkerID(i, stalkersBetwCentr); if (stalkerID != -1) { ++counter; } for (k = 0; k < stalkerResultSize; ++k) { if (stalkersResultsIds[k] == stalkerID) { break; } } if (k == stalkerResultSize) { printf("You wrongly labeled person with id %d as Stalker\n", stalkerID); } } CHECKINT("Query 2: Stalker betweenness results size", stalkerResultSize, counter); //run metrics on stalker-graph stalkersGraphRunMetrics(stalkersGraphBetwCentr); // Query 3 - Correct// int trendsNum = 4; //allocate result tables before calling query and pass them as parameters char** womenTrends; womenTrends = (char**) malloc(trendsNum * sizeof (char*)); char** menTrends; menTrends = (char**) malloc(trendsNum * sizeof (char*)); findTrends(trendsNum, g, &womenTrends, &menTrends); printf("Top Women - Men Trends\n"); int j; char* menTrendsResults[4] = {"Sun_Yat-sen", "Constantine_the_Great","Sigmund_Freud", "Hussein_of_Jordan"}; //IDS: {417,11622,468,1398} char* womenTrendsResults[4] = {"Adolf_Hitler", "Chiang_Kai-shek", NULL, NULL}; //IDS: {138,416,null,null} int counterW = 0, counterM = 0; for (j = 0; j < 4; ++j) { if (menTrends[j] != NULL) { ++counterM; for (k = 0; k < 4; ++k) { if (strcmp(menTrends[j], menTrendsResults[k]) == 0) { break; } } if (k == 4) { printf("You wrongly labeled tag with %s as top trend\n", menTrends[j]); } } } CHECKINT("Query 3: Mens Trends result size", 4, counterM); for (j = 0; j < 4; ++j) { if (womenTrends[j] != NULL) { ++counterW; for (k = 0; k < 2; ++k) { if (strcmp(womenTrends[j], womenTrendsResults[k]) == 0) { break; } } if (k == 2) { printf("You wrongly labeled tag with %s as top trend\n", menTrends[j]); } } } CHECKINT("Query 3: Women Trends result size", 2, counterW); cout<<"_____________________________________"<<endl; // Query 4 // // int forumID = 34680; char *forumName = "Wall of Xiomara Fernandez"; Graph *trustGraph = buildTrustGraph(forumName, g); int trustANodeId = 30; int trustBNodeId = 9805; int trustCNodeId = 9700; Node *ta = lookupNode(trustANodeId, trustGraph); assert(ta != NULL); Node *tb = lookupNode(trustBNodeId, trustGraph); assert(tb != NULL); Node *tc = lookupNode(trustCNodeId, trustGraph); assert(tc != NULL); double trustAB; trustAB = estimateTrust(ta, tb, trustGraph); printf("Trust between nodes (%d,%d) is %f\n", trustANodeId, trustBNodeId, trustAB); CHECKDOUBLE("Trust: (30,9805) ", trustAB, 0.134); cout<<"_____________________________________"<<endl; double trustAC; trustAC = estimateTrust(ta,tc, trustGraph); printf("Trust between nodes (%d,%d) is %f\n", trustANodeId, trustCNodeId, trustAC); CHECKDOUBLE("Trust: (30,9700) ", trustAC, 0.15); return EXIT_SUCCESS; }