Graph::Graph(const vector<Disc*>& discs) { for(size_t i = 0 ; i < discs.size() ; ++i) { Node node; node.index = i; node.disc = discs[i]; node.indexes.resize(node.disc->discsToHavePassed.size()); for(size_t j = 0 ; j < node.indexes.size() ; ++j) { node.indexes[j] = findIndex(discs[i]->discsToHavePassed[j],discs); } this->nodes.push_back(node); } }
void Document::setRichText(bool rich_text) { // Get new file name m_old_states[m_text->document()->availableUndoSteps()] = qMakePair(m_filename, m_rich_text); if (!m_filename.isEmpty()) { QString filename = m_filename; int suffix_index = filename.lastIndexOf(QChar('.')); int file_index = filename.lastIndexOf(QChar('/')); if (suffix_index > file_index) { filename.chop(filename.length() - suffix_index); } filename.append(rich_text ? ".proseup" : ".txt"); QString selected; m_filename = QFileDialog::getSaveFileName(window(), tr("Save File As"), filename, fileFilter(filename), &selected); if (!m_filename.isEmpty()) { m_filename = fileNameWithExtension(m_filename, selected); clearIndex(); } else { findIndex(); } } // Set file type m_rich_text = rich_text; m_text->setAcceptRichText(m_rich_text); // Always remove formatting to have something to undo QTextCursor cursor(m_text->document()); cursor.beginEditBlock(); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); cursor.setBlockFormat(QTextBlockFormat()); cursor.setCharFormat(QTextCharFormat()); cleanUpDocument(); cursor.endEditBlock(); m_old_states[m_text->document()->availableUndoSteps()] = qMakePair(m_filename, m_rich_text); // Save file if (!m_filename.isEmpty()) { save(); updateState(); m_text->document()->setModified(false); } emit changedName(); emit formattingEnabled(m_rich_text); }
bool SpriteSheet::reloadData(const JSONReader& loader) { int categories[256]; int num = loader.get_categories(categories, 256); for (int i = 0; i < num; ++i) { Rect r; loader.get(categories[i], "rect", &r); const char* sn = loader.get_string(categories[i], "name"); int idx = findIndex(sn); if (idx == -1) { add(sn, r); } else { SheetEntry& se = _entries[idx]; se.texture = Texture(r); } } return true; }
Foam::mappedWallPolyPatch::mappedWallPolyPatch ( const word& name, const dictionary& dict, const label index, const polyBoundaryMesh& bm, const word& patchType ) : wallPolyPatch(name, dict, index, bm, patchType), mappedPatchBase(*this, dict) { // mapped is not constraint type so add mapped group explicitly if (findIndex(inGroups(), mappedPolyPatch::typeName) == -1) { inGroups().append(mappedPolyPatch::typeName); } }
IndexAlgorithm* IndexFactory::index(const char* db, const char* ns, const std::set<std::string>& keys) { listAlgorithmsTypePtr algorithms = findAlgorithms(db, ns); IndexAlgorithm* indexImpl = findIndex(algorithms, keys); if (indexImpl == NULL) { int len = strlen(db) + strlen(ns) + strlen(".ixp") + 20; char* indexFileName = (char*)malloc(len); memset(indexFileName, 0, len); sprintf(indexFileName, "%s/%s.ixp", db, ns), //indexImpl = new BPlusIndex(keys); indexImpl = new BPlusIndexP(indexFileName); indexImpl->setKeys(keys); algorithms->push_back(indexImpl); free(indexFileName); } return indexImpl; }
Foam::wallPolyPatch::wallPolyPatch ( const word& name, const label size, const label start, const label index, const polyBoundaryMesh& bm, const word& patchType ) : polyPatch(name, size, start, index, bm, patchType) { // wall is not constraint type so add wall group explicitly if (findIndex(inGroups(), typeName) == -1) { inGroups().append(typeName); } }
QModelIndex ModelDescriptorListWidget::findIndex(const QUuid &uid, const QModelIndex &parent) const { QString uidString = uid.toString(); QModelIndex modelIndex; for(int row = 0; row < proxyModel()->rowCount(parent); row++) { modelIndex = proxyModel()->index(row, 0, parent); if(modelIndex.isValid() && modelIndex.data(Qt::UserRole).toString() == uidString) { break; } else { modelIndex = findIndex(uid, modelIndex); if(modelIndex.isValid()) { break; } } } return modelIndex; }
void getMutationFrequency(TIntegerMatrix* originalMutationMatrix, vector<int>* mutationFrequency, vector<int>* genesMut) { int totalSamples = originalMutationMatrix->at(0).size(); int totalMutatedGenes = genesMut->size(); for (int i = 0; i < totalMutatedGenes; ++i) { int currentMutatedGeneId = genesMut->at(i); int currentRowIdInMutationMatrix = findIndex(genesMut, currentMutatedGeneId); for (int j = 0; j < totalSamples; ++j) { if (originalMutationMatrix->at(currentRowIdInMutationMatrix)[j] > 0) { mutationFrequency->at(currentMutatedGeneId)++;} } } }
void TreeItemModel::revert() { qDebug("revert changes"); while (!_uncommited.isEmpty()){ TreeItem * item = _uncommited.dequeue(); if(item->id()==-1){//not saved to the database qDebug("Reverting unsaved item (n)"); QModelIndex parentIndex = findIndex(item->parent()->id()); int idx = item->row(); beginRemoveRows(parentIndex,idx,idx); item->parent()->removeChildren(idx,1); endRemoveRows(); } else{ qDebug("Reverting item (n)"); } } }
//Creates a random number of edges from Vertex edgeInd within the adjacency matrix void createEdges(Board *B, int edgeInd){ int numEdges = 0; numEdges = rand() % 3 +3; //random number of edges from 3-5 //numEdges = 3; //random number of edges from 1-3 int j = findIndex(B, edgeInd); mergeSort(B->Vertices, B->num - 1, (double)B->Vertices[j].x, (double)B->Vertices[j].y); for (int i = 1; i <= numEdges; i++) { if (degree(B, B->Vertices[i].edgeInd) < 5){ if (!overlaps(B, edgeInd, B->Vertices[i].edgeInd)){ B->edges[edgeInd][B->Vertices[i].edgeInd] = stdArc; B->edges[B->Vertices[i].edgeInd][edgeInd] = stdArc; } } } }
void MotionPlayer::initMotions() { std::map<std::string, MappedMotion>::iterator motionIt; for (motionIt = m_motionNames.begin(); motionIt != m_motionNames.end(); ++motionIt) { MappedMotion& motion = motionIt->second; std::vector<std::string> jointList = motion.jointList; motion.motionToModel.resize(jointList.size()); for (unsigned i = 0; i < jointList.size(); i++) { motion.motionToModel[i] = findIndex(jointList[i]); } motion.reqState = model()->registerState(motion.preState); motion.transState = model()->registerState(motion.playState); motion.resState = model()->registerState(motion.postState); motion.initPlayer(); } }
double CoinPackedVectorBase::operator[](int i) const { if (!testedDuplicateIndex_) duplicateIndex("operator[]", "CoinPackedVectorBase"); // Get a reference to a map of full storage indices to // packed storage location. const std::set< int > &sv = *indexSet("operator[]", "CoinPackedVectorBase"); #if 1 if (sv.find(i) == sv.end()) return 0.0; return getElements()[findIndex(i)]; #else // LL: suggested change, somthing is wrong with this const size_t ind = std::distance(sv.begin(), sv.find(i)); return (ind == sv.size()) ? 0.0 : getElements()[ind]; #endif }
Foam::mappedWallPolyPatch::mappedWallPolyPatch ( const word& name, const label size, const label start, const label index, const polyBoundaryMesh& bm, const word& patchType ) : wallPolyPatch(name, size, start, index, bm, patchType), mappedPatchBase(static_cast<const polyPatch&>(*this)) { // mapped is not constraint type so add mapped group explicitly if (findIndex(inGroups(), mappedPolyPatch::typeName) == -1) { inGroups().append(mappedPolyPatch::typeName); } }
void OcFeedsModelNew::feedMarkedRead(const int &id) { int idx = findIndex(id, 0); if (idx != -999) { QLOG_INFO() << "Combined model: feed at index " << idx << " was marked as read"; m_items.at(idx)->unreadCount = 0; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) emit dataChanged(index(idx), index(idx), QVector<int>(1, UnreadCountRole)); #else emit dataChanged(index(idx), index(idx)); #endif queryAndSetTotalUnread(); } }
void CreateChain(AdjGraph *adjGraph,char a[M],char b[M][M],int c[M][M]) { int i,j; ArcNode *arcNode=NULL; ArcNode *nodeHead=NULL; ArcNode *nodePre=NULL; ArcList *arcList=NULL; ArcList *listHead=NULL; ArcList *listPre=NULL; for(i=0;i<adjGraph->vexnum;i++) { arcNode=(ArcNode *)malloc(sizeof(ArcNode)); if(i==0) { nodeHead=(ArcNode *)malloc(sizeof(ArcNode)); nodePre=(ArcNode *)malloc(sizeof(ArcNode)); nodeHead->nextnode=NULL; nodePre=nodeHead; } arcNode->data=a[i]; for(j=0;j<strlen(b[i]);j++) { if(j==0) { listHead=(ArcList *)malloc(sizeof(ArcList)); listPre=(ArcList *)malloc(sizeof(ArcList)); listHead->nextlistnode=NULL; listPre=listHead; } arcList=(ArcList *)malloc(sizeof(ArcList)); arcList->index=findIndex(a,adjGraph->vexnum,b[i][j]); arcList->tflen=c[i][j]; listPre->nextlistnode=arcList; listPre=arcList; } listPre->nextlistnode=NULL; arcNode->arclist=listHead; nodePre->nextnode=arcNode; nodePre=arcNode; } nodePre->nextnode=NULL; adjGraph->arcGraph=nodeHead; }
void Population::select( std::vector<Chromosome>& inElems, std::vector<Chromosome>& outElems ) { /* method as described on page 59 */ /* each chromosome has been evaluated, counting the sum of evaluation marks */ float ratioSum = 0.0; for(Chromosome& c : inElems) ratioSum += c.getRatio(); /* computing selection probability */ size_t sz = family.getPopSz(); size_t maxInd = sz-1; float selectionProb[sz]; float cumulativeProb[sz]; for(size_t i=0; i<sz; i++) { /* selectionProb and cumulativeProb are in ascending order, whereas inElems is in * descending order so subsequent values are inserted from the largest to the smallest * index */ selectionProb[maxInd-i] = inElems[i].getRatio() / ratioSum; cumulativeProb[maxInd-i] = 0.0; /* computing the cumulative distribution of ratios */ for(size_t j=0; j<=i; j++) cumulativeProb[maxInd-i] += selectionProb[maxInd-j]; } /* all needed computation have been made, roulette can run */ std::uniform_real_distribution<float> urd(0, 1); size_t howManySelected = family.getPopSz() - family.getAncCount() - family.getGenSz(); for(size_t i=0; i<howManySelected; i++) { /* c++11 version uniformly distributed random number */ float rf = urd(gen); /* function that gets random value and returns the proper index based on cumulative * probability distribution table computed before */ size_t genId = findIndex(cumulativeProb, maxInd, rf); outElems.push_back(inElems[genId]); } }
/* closes res but does not free resultsManually */ static void verifyResult(UEnumeration* res, const UBool *resultsManually) { UBool* resultsFromSystem = (UBool*) uprv_malloc(gCountAvailable * sizeof(UBool)); const char* name; UErrorCode status = U_ZERO_ERROR; int32_t i; /* fill the bool for the selector results! */ uprv_memset(resultsFromSystem, 0, gCountAvailable); while ((name = uenum_next(res,NULL, &status)) != NULL) { resultsFromSystem[findIndex(name)] = TRUE; } for(i = 0 ; i < gCountAvailable; i++) { if(resultsManually[i] != resultsFromSystem[i]) { log_err("failure in converter selector\n" "converter %s had conflicting results -- manual: %d, system %d\n", gAvailableNames[i], resultsManually[i], resultsFromSystem[i]); } } uprv_free(resultsFromSystem); uenum_close(res); }
REAL addtoItem(sparseVector *sparse, int targetIndex, REAL value) { int idx; if(targetIndex > 0) idx = findIndex(targetIndex, sparse->index, sparse->count, BLAS_BASE); else { idx = -targetIndex; if(idx > sparse->count) /* Index error; ignore item */ return(0.0); } if(idx <=0 ) value = putItem(sparse, targetIndex, value); else { value += sparse->value[idx]; putItem(sparse, -idx, value); } return(value); }
void OcFeedsModelNew::feedRenamed(const QString &newName, const int &feedId) { if (m_items.isEmpty()) return; int idx = findIndex(feedId, 0); if (idx != -999) { QLOG_INFO() << "Feeds model: feed at index " << idx << " was renamed to " << newName; m_items.at(idx)->title = newName; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) emit dataChanged(index(idx), index(idx), QVector<int>(1, TitleRole)); #else emit dataChanged(index(idx), index(idx)); #endif } }
void subst_enc(unsigned char *input, unsigned char *alphabet, unsigned char *key, unsigned char *output) { stringToUpper(input); int i,letterCount,j,input_len,key_len,indexInKey; j=0; input_len = strlen(input); key_len = strlen(key); for(i = 0; i < input_len;i++) { indexInKey = findIndex(alphabet, input[i],key_len); if (indexInKey != -1) { output[j] = key[indexInKey]; j++; } else { if (input[i] == '\n') { output[j] = input[i]; j++; } } } output[j] = '\0'; }
static PERF_COUNTER_DEFINITION *findCounter( PERF_OBJECT_TYPE *obj, char *str ) { PERF_COUNTER_DEFINITION *counter; DWORD i; DWORD index; if( obj == NULL ) return( NULL ); index = findIndex( str ); if( index == -1 ) return( NULL ); counter = (PERF_COUNTER_DEFINITION *) ( (char *)obj + obj->HeaderLength ); for( i=0; i < obj->NumCounters; i++ ) { if( counter->CounterNameTitleIndex == index ) { return( counter ); } counter = (PERF_COUNTER_DEFINITION *) ( (char *)counter + counter->ByteLength ); } return( NULL ); }
void dsmcDiffuseCatalyticWallPatch::setProperties() { velocity_ = propsDict_.lookup("velocity"); temperature_ = readScalar(propsDict_.lookup("temperature")); // set the molecules/atoms to be catalysed typeIds ------------ const List<word> inputMolecules (propsDict_.lookup("moleculesToBeCatalysed")); catalysisTypeIds_.setSize(inputMolecules.size(), -1); forAll(catalysisTypeIds_, i) { catalysisTypeIds_[i] = findIndex(cloud_.typeIdList(), inputMolecules[i]); // check that input molecules belong to the typeIdList (constant/dsmcProperties) if(catalysisTypeIds_[i] == -1) { FatalErrorIn("dsmcDiffuseCatalyticWallPatch::setProperties()") << "Cannot find type id: " << inputMolecules[i] << nl << exit(FatalError); } }
void subst_dec(unsigned char *input, unsigned char *alphabet, unsigned char *key, unsigned char *output) { stringToUpper(input); int i,j,input_len,key_len,alphabet_len,indexInAlpha; j = 0; input_len = strlen(input); key_len = strlen(key); alphabet_len = strlen(alphabet); for(i = 0; i < input_len;i++) { indexInAlpha = findIndex(key,input[i],alphabet_len); if (indexInAlpha != -1) { output[j] = ALPHABET[indexInAlpha]; j++; } else { if(input[i] == '\n') { output[j] = input[i]; j++; } } } output[j] = '\0'; }
/* * findObject */ static PERF_OBJECT_TYPE *findObject( char *data, char *str ) { DWORD index; PERF_OBJECT_TYPE *obj; PERF_DATA_BLOCK *dblock; DWORD i; if( data == NULL ) return( NULL ); index = findIndex( str ); if( index == -1 ) return( NULL ); dblock = (PERF_DATA_BLOCK *)data; obj = (PERF_OBJECT_TYPE *) ( data + dblock->HeaderLength ); for( i=0; i < dblock->NumObjectTypes; i++ ) { if( obj->ObjectNameTitleIndex == index ) { return( obj ); } data = (char *)obj; obj = (PERF_OBJECT_TYPE *) ( data + obj->TotalByteLength ); } return( NULL ); }
bool BPlusIndexP::update(const BSONObj& elem, const djondb::string documentId, long filePos) { Index* index = new Index(); index->key = new BSONObj(elem); index->documentId = documentId; index->posData = filePos; index->indexPos = 0; // Not in use anymore djondb::string key = index->key->getDJString("_id"); //char* key = index->key->toChar(); IndexPage* pageFound = findIndexPage(_head, key); Index* current = findIndex(pageFound, key); bool found = false; if (current != NULL) { found = true; current->posData = filePos; persistPage(pageFound); } delete index; return found; }
int areParanthesisCorrect(char* data){ ArrayUtil util = initialize(); char *actual = (char*)util.base; char ch; int length = strlen(data); int i,found,res; char* topElement; Stack *stack = New(sizeof(char),20); for(i=0;i<length;i++){ ch = data[i]; found = findIndex(util,&ch); if(found>-1 && found<3) res = push(stack,&ch); if(found>=3 && found<6){ topElement = (char*)top(stack); if(topElement != NULL){ if(*topElement == actual[found-3]){ topElement = (char*)pop(stack); } else{ dispose(util); disposeStack(stack); return 0; } } else return 0; } } if(isEmpty(stack)){ dispose(util); disposeStack(stack); return 1; } dispose(util); disposeStack(stack); return 0; }
forAllConstIter(Map<label>, splitMap, iter) { label masterI = iter.key(); label newCellI = iter(); while (origCell[masterI] != -1 && origCell[masterI] != masterI) { masterI = origCell[masterI]; } if (masterI >= addedCells_.size()) { FatalErrorIn ( "multiDirRefinement::addCells(const primitiveMesh&" ", const Map<label>&" ) << "Map of added cells contains master cell " << masterI << " which is not a valid cell number" << endl << "This means that the mesh is not consistent with the" << " done refinement" << endl << "newCell:" << newCellI << abort(FatalError); } labelList& added = addedCells_[masterI]; if (added.empty()) { added.setSize(2); added[0] = masterI; added[1] = newCellI; } else if (findIndex(added, newCellI) == -1) { label sz = added.size(); added.setSize(sz + 1); added[sz] = newCellI; } }
int choose(int i, int lt) { if (i > n) return 0; // Choose xi(t[2i]). t[2*i] = cntTour.p[lt - 1]; if (inY[t[2*i-1]][t[2*i]]) return 0; inX[t[2*i-1]][t[2*i]] = 1; inX[t[2*i]][t[2*i-1]] = 1; reorg(cntTour.p, lt); if (cntTour.length - dist[t[2*i-1]][t[2*i]] + dist[t[2*i]][t[1]] < bestTour.length) { cntTour.length -= (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[1]]); bestTour = cntTour; return 1; } // Choose yi(t[2i+1]). int r, find = 0; for (r = 2; r <= n; r ++) { t[2*i+1] = nearest[t[2*i]][r]; if (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[2*i+1]] > 0 && !inX[t[2*i]][t[2*i+1]]) { find = 1; break; } } if (!find) { inX[t[2*i-1]][t[2*i]] = 0; inX[t[2*i]][t[2*i-1]] = 0; return 0; } inY[t[2*i]][t[2*i+1]] = 1; inY[t[2*i+1]][t[2*i]] = 1; lt = findIndex(cntTour.p, t[2*i+1]); cntTour.length -= (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[2*i+1]]); if (choose(i + 1, lt)) return 1; else { inY[t[2*i]][t[2*i+1]] = 0; inY[t[2*i+1]][t[2*i]] = 0; return 0; } }
// type number 7 void handler_ConfirmDevice( struct Oblify *oblify ) { DEBUG_PRINT(("handler_ConfirmDevice\n")); if (oblify->deviceID == 65535) { int index = findIndex( oblify->payload ); if (strncmp( mac , (char *)(oblify->payload + index) , strlen( mac )) == 0) { char *devID = strndup( oblify->payload , index - 1 ); if (devID == NULL) devID = "99"; oblify->deviceID = (unsigned short)strtol( devID , (char **)NULL , 10 ); oblify->payload = mac; oblify->payloadSize = strlen( mac ); oblify->type = RegisterDevice; if (deviceID != oblify->deviceID) { sendPacketFromOblify( *oblify , 35813 ); deviceID = oblify->deviceID; } } }else DEBUG_PRINT(("error ConfirmDevice\n")); }
Foam::wordList Foam::selectRegionNames(const argList& args, const Time& runTime) { const bool allRegions = args.optionFound("allRegions"); wordList regionNames; if (allRegions) { const regionProperties rp(runTime); forAllConstIter(HashTable<wordList>, rp, iter) { const wordList& regions = iter(); forAll(regions, i) { if (findIndex(regionNames, regions[i]) == -1) { regionNames.append(regions[i]); } } } } else {