void addWire(Group *g1, Group *g2) { if(g1==g2) return; if(g1->set==g2->set && g1->set!=NULL) return; if(g1->set==NULL&&g2->set==NULL) makeSet(g1, g2); else if(g1->set!=NULL&&g2->set==NULL) addToSet(g1->set, g2); else if(g1->set==NULL&&g2->set!=NULL) addToSet(g2->set, g1); else if(g1->set!=NULL&&g2->set!=NULL) joinSets(g1, g2); return; }
int TextMatrix::keepCol(const std::vector<std::string>& name) { const int nc = ncol(); const int nr = nrow(); std::vector<int> indexToRemove; std::set<std::string> keep; makeSet(name, &keep); for (int i = 0; i < nc; ++i) { if (keep.count(colName[i])) continue; indexToRemove.push_back(i); } removeByIndex(indexToRemove, &colName); for (int i = 0; i < nr; ++i) { removeByIndex(indexToRemove, &mat[i]); } return 0; }
int main() { char w; int n_edge, n_v, res, q, a, b; while(scanf("%d", &n_v) != EOF) { n_edge = build_graph(n_v); makeSet(n_v); scanf("%d", &q); while(q--) { scanf("%d %d", &a, &b); unionSet(a, b); } res = kruskal(e, n_edge, n_v); printf("%d\n", res); } return 0; }
void kruskal(Graph & G, bool bench) { int largestNode = getLargestNode(G); std::vector<disjointTreeNode*> disjointNodes(largestNode); std::vector<SnapEdge> result; std::deque<SnapEdge> Q; for(SnapNode NI = G->BegNI(); NI < G->EndNI(); NI++) { disjointTreeNode* x = new disjointTreeNode(); x->id = NI.GetDat(); makeSet(x); disjointNodes[x->id-1] = x; } for (SnapEdge NI = G->BegEI(); NI < G->EndEI(); NI++) { Q.push_back(NI); } while (! Q.empty()) { std::sort(Q.begin(), Q.end(), sortClusters); SnapEdge e = Q.front(); Q.pop_front(); disjointTreeNode* u = Find(disjointNodes[e.GetSrcNDat()-1]); disjointTreeNode* v = Find(disjointNodes[e.GetDstNDat()()-1]); if ( u != v ) { result.push_back(e); Union(disjointNodes[e.GetSrcNDat()-1], disjointNodes[e.GetDstNDat()-1]); } } if(!bench) { for(int i = 0; i<result.size(); i++) { std::cout << result[i].GetSrcNDat() << " --> " << result[i].GetDstNDat() << " peso: " << result[i].GetDat() << std::endl; } } }
int main() { char c; int ncase, i, a, b, m, n; int oppos[N]; scanf("%d", &ncase); while(ncase--) { makeSet(); memset(oppos, -1, sizeof(oppos)); scanf("%d %d", &n, &m); for(i = 0;i < m;i++) { getchar(); scanf("%c %d %d", &c, &a, &b); if(c == 'A') { if (oppos[a] == -1 || oppos[b] == -1) printf("Not sure yet.\n"); else if (getF(a) == getF(b)) printf("In the same gang.\n"); else if (getF(a) == getF(oppos[b]) || getF(b) == getF(oppos[a])) printf("In different gangs.\n"); else printf("Not sure yet.\n"); } else { if (oppos[a] == -1) oppos[a] = b; if (oppos[b] == -1) oppos[b] = a; Union(a, oppos[b]); Union(b, oppos[a]); } } } return 0; }
void Image::generer(int largeur, int hauteur, int pourcentageNoir) { // Initialisation des attributs de this m_largeur = largeur; m_hauteur = hauteur; m_pixels.clear(); for (int i=0; i<m_largeur*m_hauteur; i++) { int noir = rand() % 100; Pixel* pix; if (noir <= pourcentageNoir) { // Si la variable aléatoire est comprise dans le pourcentage de pixels noirs, on crée un *Pixel noir pix = new Pixel(); } else { // Sinon, on crée un *Pixel coloré aléatoirement pix = new Pixel(rand()%NB_COULEURS, rand()%NB_COULEURS, rand()%NB_COULEURS); } // Le pixel est son propre représentant au début de l'algorithme ; on l'ajoute au tableau de *Pixels makeSet(pix); m_pixels.push_back(pix); } }
void RefsGroup::fillSgpd(SampleGroupDescriptionBox* sgpd) { allotId(); makeSet(); sgpd->FullBox::setVersion(1); sgpd->setGroupingType(mGroupingType); for (auto entry : mEntrySet) { std::uint32_t tag; Vector<std::uint32_t> refs; std::tie(tag, refs) = entry; UniquePtr<DirectReferenceSamplesList, SampleGroupDescriptionEntry> refsEntry( CUSTOM_NEW(DirectReferenceSamplesList, ())); refsEntry->setSampleId(tag); refsEntry->setDirectReferenceSampleIds(refs); sgpd->addEntry(std::move(refsEntry)); mIdxEntry.push_back(std::make_tuple(tag, refs)); } }
int loadRangeFile(const char* fn, const char* givenRangeName, OrderedMap<std::string, RangeList>* rangeMap) { std::set<std::string> rangeSet; makeSet(givenRangeName, ',', &rangeSet); OrderedMap<std::string, RangeList>& m = *rangeMap; LineReader lr(fn); int lineNo = 0; std::vector<std::string> fd; while (lr.readLineBySep(&fd, "\t ")) { ++lineNo; if (fd.size() < 2) { logger->error( "Skip lines [ %d ] (short of columns) when reading range file [ %s " "].", lineNo, fn); continue; } if (rangeSet.size() && rangeSet.find(fd[0]) == rangeSet.end()) continue; if (fd[0].empty()) { logger->warn( "Skip line [ %d ] (first column is empty) when reading range file [ " "%s ].", lineNo, fn); continue; } if (fd[1].empty()) { logger->warn( "Skip line [ %d ] (second column is empty) when reading range file [ " "%s ].", lineNo, fn); continue; } m[fd[0]].addRangeList(fd[1].c_str()); } return m.size(); }
/** Parse with one token worth of look-ahead, return the expression object representing the syntax parsed. @param tok next token from the input. @param fp file subsequent tokens are being read from. @return the expression object constructed from the input. */ Expr *parse( char *tok, FILE *fp ) { // Create a literal token for anything that looks like a number. { long dummy; int pos; // See if the whole token parses as a long int. if ( sscanf( tok, "%ld%n", &dummy, &pos ) == 1 && pos == strlen( tok ) ) { // Copy the literal to a dynamically allocated string, since makeLiteral wants // a string it can keep. char *str = (char *) malloc( strlen( tok ) + 1 ); return makeLiteral( strcpy( str, tok ) ); } } // Create a literal token for a quoted string, without the quotes. if ( tok[ 0 ] == '"' ) { // Same as above, make a dynamically allocated copy of the token that the literal // expression can keep as long as at wants to. int len = strlen( tok ); char *str = (char *) malloc( len - 1 ); strncpy( str, tok + 1, len - 2 ); str[ len - 2 ] = '\0'; return makeLiteral( str ); } // Handle compound statements if ( strcmp( tok, "{" ) == 0 ) { int len = 0; int cap = INITIAL_CAPACITY; Expr **eList = (Expr **) malloc( cap * sizeof( Expr * ) ); // Keep parsing subexpressions until we hit the closing curly bracket. while ( strcmp( expectToken( tok, fp ), "}" ) != 0 ) { if ( len >= cap ) eList = (Expr **) realloc( eList, ( cap *= 2 ) * sizeof( Expr * ) ); eList[ len++ ] = parse( tok, fp ); } return makeCompound( eList, len ); } // Handle language operators (reserved words) if ( strcmp( tok, "print" ) == 0 ) { // Parse the one argument to print, and create a print expression. Expr *arg = parse( expectToken( tok, fp ), fp ); return makePrint( arg ); } if ( strcmp( tok, "set" ) == 0 ) { // Parse the two operands, then make a set expression with them. char *str = expectToken( tok, fp ); int len = strlen( str ); char *name = (char *) malloc( len + 1 ); strcpy( name, str ); name[ len ] = '\0'; if ( !isalpha(name[0]) || strlen( name ) > MAX_VAR || strchr( name, LEFT_BRACKET ) || strchr( name, RIGHT_BRACKET ) || strchr( name, POUND ) ) { // Complain if we can't make sense of the variable. fprintf( stderr, "line %d: invalid variable name \"%s\"\n", linesRead(), name ); exit( EXIT_FAILURE ); } Expr *expr = parse( expectToken( tok, fp ), fp ); Expr *set = makeSet ( name, expr ); free(name); return set; } if ( strcmp( tok, "add" ) == 0 ) { // Parse the two operands, then make an add expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeAdd( op1, op2 ); } if ( strcmp( tok, "sub" ) == 0 ) { // Parse the two operands, then make a sub expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeSub( op1, op2 ); } if ( strcmp( tok, "mul" ) == 0 ) { // Parse the two operands, then make a mul expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeMul( op1, op2 ); } if ( strcmp( tok, "div" ) == 0 ) { // Parse the two operands, then make a div expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeDiv ( op1, op2 ); } if ( strcmp( tok, "equal" ) == 0 ) { // Parse the two operands, then make an equal expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeEqual ( op1, op2 ); } if ( strcmp( tok, "less" ) == 0 ) { // Parse the two operands, then make a less expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeLess ( op1, op2 ); } if ( strcmp( tok, "not" ) == 0 ) { // Parse the operand, then make a not expression with it. Expr *op = parse( expectToken( tok, fp ), fp ); return makeNot ( op ); } if ( strcmp( tok, "and" ) == 0 ) { // Parse the two operands, then make an and expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeAnd ( op1, op2 ); } if ( strcmp( tok, "or" ) == 0 ) { // Parse the two operands, then make an or expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeOr ( op1, op2 ); } if ( strcmp( tok, "if" ) == 0 ) { // Parse the two operands, then make an if expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeIf ( op1, op2 ); } if ( strcmp( tok, "while" ) == 0 ) { // Parse the two operands, then make a while expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeWhile ( op1, op2 ); } if ( strcmp( tok, "concat" ) == 0 ) { // Parse the two operands, then make a concatenation expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); return makeConcat ( op1, op2 ); } if ( strcmp( tok, "substr" ) == 0 ) { // Parse the three operands, then make a substring expression with them. Expr *op1 = parse( expectToken( tok, fp ), fp ); Expr *op2 = parse( expectToken( tok, fp ), fp ); Expr *op3 = parse( expectToken( tok, fp ), fp ); return makeSubstr ( op1, op2, op3 ); } // Handle variables if ( isalpha(tok[0]) && strlen( tok ) <= MAX_VAR && !strchr( tok, LEFT_BRACKET ) && !strchr( tok, RIGHT_BRACKET ) && !strchr( tok, POUND ) ) { // Parse the variable name and make a variable expression. char *str = tok; int len = strlen( str ); char *name = (char *) malloc( len + 1 ); strcpy( name, str ); name[ len ] = '\0'; Expr *var = makeVariable( name ); free(name); return var; } // Complain if we can't make sense of the token. fprintf( stderr, "line %d: invalid token \"%s\"\n", linesRead(), tok ); exit( EXIT_FAILURE ); // Never reached. return NULL; }
void initStatement() { ifLastWithSet = makeSet(ifHook, lastHook, withHook); lastWithSet = makeSet(lastHook, withHook); withSet = makeSet(withHook); }
void union_find(pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr cloud, int K, std::vector<int>& inliers){ if (cloud->size()==0){ return; } if(K==0){ ROS_WARN("parameter K for K nearest neighbor is 0, aborting"); return; } std::vector<union_find_node*> forest; std::vector<union_find_node*> model(cloud->size(),NULL);//init to NULL std::vector<int> knnindices(K); //stores indices of the last K nearest neighbors search std::vector<float> knnSqDistances(K); //sotres squared distance of the last KNN search int knncount=0; //KDTree pcl::KdTreeFLANN<pcl::PointXYZRGBA> kdtree; kdtree.setInputCloud (cloud); for (int i=0;i<cloud->size();i++){ //if point is not yet visited if(model[i]==NULL){ //find K nearest neighbors of the curent point knncount = kdtree.nearestKSearch(cloud->at(i),K,knnindices,knnSqDistances); //union them to the curent point for (int result_i=0;result_i<knncount;result_i++){ //create the point in the model if it do not exists if (model[knnindices[result_i]]==NULL){ model[knnindices[result_i]] = new union_find_node; makeSet(model[knnindices[result_i]]); } //actualy do the union union_nodes(model[i],model[knnindices[result_i]]); } //add the root to the forest (check if do not already exists) addToForest(forest,find(model[i])); } } //now we have to find the biggest tree if(forest.size()!=0){ size_t max_size=0, biggest_tree_i=0; for (size_t i=0;i<forest.size();i++){ if( forest[i]->children_n > max_size){ max_size = forest[i]->children_n; biggest_tree_i = i; } } union_find_node* the_root = forest[biggest_tree_i]; //we add to the inliers all the points that have the_root as root for (int i=0; i < cloud->size(); i++){ if(find(model[i])==the_root){ inliers.push_back(i); } } for (int i=0;i<model.size();i++) delete model[i]; } }
int rmst(int k) { memset(choose, 0, sizeof(choose)); memset(linkTo, -1, sizeof(linkTo)); makeSet(); sort(edges, edges + m); for (int i = 0; i < m; i++) { if (!edges[i].u) continue; int x = findSet(edges[i].u), y = findSet(edges[i].v); if (x == y) continue; parent[x] = y; choose[i] = 1; } int components = 0; best[0] = INF; for (int i = 1; i < n; i++) if (findSet(i) == i) { components++; best[i] = INF; } if (components > k) return INF; for (int i = 0; i < m; i++) { if (edges[i].u) continue; linkTo[edges[i].v] = i; int x = findSet(edges[i].v); if (edges[i].w < best[x]) { best[x] = edges[i].w; candidate[x] = i; } } for (int i = 1; i < n; i++) if (findSet(i) == i) { if (best[i] == INF) return INF; choose[candidate[i]] = 1; } for (int i = 0; i < n; i++) g[i].clear(); for (int i = 0; i < m; i++) if (choose[i]) addEdge(i); while (components < k) { dfs(-1, 0); int tmpBest = INF, tmpCandidate; for (int i = 1; i < n; i++) { if (linkTo[i] == -1 || best[i] == -INF) continue; int beta = edges[linkTo[i]].w - best[i]; if (beta < tmpBest) { tmpBest = beta; tmpCandidate = i; } } if (tmpBest == INF) return INF; choose[candidate[tmpCandidate]] = 0; choose[linkTo[tmpCandidate]] = 1; addEdge(linkTo[tmpCandidate]); components++; } int sumOfWeight = 0; for (int i = 0; i < m; i++) if (choose[i]) sumOfWeight += edges[i].w; return sumOfWeight; }
Connection::Connection(TCPsocket& newUserSocket) : pimpl_(new ConnectionImpl){ ++pimpl_->refCount; pimpl_->userSocket = newUserSocket; makeSet(1); }
int Connection::init(const std::string& host, int port){ if( connect(host, port) == -1 ){ return -1; } makeSet(1); return 1; }
int Connection::init(IPaddress *ip){ if( connect(ip) == -1 ){ return -1; } makeSet(1); return 1; }
/** * Extract covaraite from file @param fn. * Only samples included in @param includedSample will be processed * If some samples appear more than once, only the first appearance will be * readed * Only covaraites provided in @param covNameToUse will be included * Missing values will be imputed to the mean columnwise. * Result will be put to @param mat (sample by covariate) and @param * sampleToDrop * @return number of sample loaded (>=0); or a minus number meaning error * @param sampleToDrop: store samples that are not found in covariate. */ int extractCovariate(const std::string& fn, const std::vector<std::string>& sampleToInclude, const std::vector<std::string>& covNameToUse, DataLoader::HandleMissingCov handleMissingCov, SimpleMatrix* mat, std::set<std::string>* sampleToDrop) { std::set<std::string> includeSampleSet; makeSet(sampleToInclude, &includeSampleSet); if (includeSampleSet.size() != sampleToInclude.size()) { logger->warn( "Some samples have appeared more than once, and we record covariate " "for its first appearance"); } std::vector<std::string> noPhenotypeSample; std::map<std::string, int> processed; // record how many times a sample is processed std::set<std::pair<int, int> > missing; // record which number is covaraite is missing. int missingCovariateWarning = 0; // record how many times a missing warning is geneated. bool missingValueInLine; // record whether there is missing value in the // line int missingLines = 0; // record how many lines has missing values std::vector<int> columnToExtract; std::vector<std::string> extractColumnName; std::vector<std::string> fd; LineReader lr(fn); int lineNo = 0; int fieldLen = 0; while (lr.readLineBySep(&fd, "\t ")) { ++lineNo; if (lineNo == 1) { // header line fieldLen = fd.size(); if (fieldLen < 2) { logger->error( "Insufficient column number (<2) in the first line of covariate " "file!"); return -1; }; if (tolower(fd[0]) != "fid" || tolower(fd[1]) != "iid") { logger->error("Covariate file header should begin with \"FID IID\"!"); return -1; } std::map<std::string, int> headerMap; makeMap(fd, &headerMap); if (fd.size() != headerMap.size()) { logger->error("Covariate file have duplicated header!"); return -1; } // specify which covariates to extract if (covNameToUse.size()) { for (size_t i = 0; i < covNameToUse.size(); ++i) { if (headerMap.count(covNameToUse[i]) == 0) { logger->error( "The covariate [ %s ] you specified cannot be found from " "covariate file!", covNameToUse[i].c_str()); continue; } columnToExtract.push_back(headerMap[covNameToUse[i]]); extractColumnName.push_back(covNameToUse[i]); } } else { for (size_t i = 2; i < fd.size(); ++i) { columnToExtract.push_back(headerMap[fd[i]]); extractColumnName.push_back(fd[i]); } } } else { // body lines if (fd.empty() || (fd[0].empty() && fd.size() == 1)) { // skip empty lines continue; } if ((int)fd.size() != fieldLen) { logger->error( "Inconsistent column number in covariate file line [ %d ] - skip " "this file!", lineNo); return -1; } if (includeSampleSet.find(fd[1]) == includeSampleSet.end()) { // does not have phenotype noPhenotypeSample.push_back(fd[1]); continue; }; processed[fd[1]]++; if (processed[fd[1]] > 1) { logger->info("Duplicate sample [ %s ] in covariate file, skipping", fd[1].c_str()); continue; }; int idx = (*mat).nrow(); (*mat).resize(idx + 1, columnToExtract.size()); (*mat).setRowName(idx, fd[1]); missingValueInLine = false; for (int i = 0; i < (int)columnToExtract.size(); ++i) { double d; if (str2double(fd[columnToExtract[i]], &d)) { (*mat)[idx][i] = d; } else { // found missing missingValueInLine = true; ++missingCovariateWarning; if (missingCovariateWarning <= 10) { if (handleMissingCov == DataLoader::COVARIATE_IMPUTE) { logger->warn( "Covariate file line [ %d ] has non-numerical value [ %s " "], " "we will impute to its mean", lineNo, fd[columnToExtract[i]].c_str()); } else if (handleMissingCov == DataLoader::COVARIATE_DROP) { logger->warn( "Covariate file line [ %d ] has non-numerical value [ %s " "], " "we will skip this sample", lineNo, fd[columnToExtract[i]].c_str()); } } (*mat)[idx][i] = 0.0; // will later be updated missing.insert(std::make_pair(idx, i)); }; } if (!missing.empty() && handleMissingCov == DataLoader::COVARIATE_DROP) { // drop row and row name (*mat).deleteRow((*mat).nrow() - 1); missing.clear(); } missingLines += missingValueInLine ? 1 : 0; } } if (missingCovariateWarning > 10) { if (handleMissingCov == DataLoader::COVARIATE_IMPUTE) { logger->warn( "Total [ %d ] lines in covariate file contain non-numerical " "values, " "we will impute these to their mean", missingLines); } else if (handleMissingCov == DataLoader::COVARIATE_DROP) { logger->warn( "Total [ %d ] lines in covariate file contain non-numerical " "values, " "we will skip these lines", missingLines); } } // output samples in covaraite but without phenotype for (size_t i = 0; i < noPhenotypeSample.size(); ++i) { if (i == 0) logger->warn( "Total [ %zu ] samples are skipped from covariate file due to " "missing phenotype", noPhenotypeSample.size()); if (i > 10) { logger->warn( "Skip outputting additional [ %d ] samples from covariate file " "with " "missing phenotypes", ((int)noPhenotypeSample.size() - 10)); break; } logger->warn( "Skip sample [ %s ] from covariate file due to missing phenotype", (noPhenotypeSample)[i].c_str()); } // set up labels for (size_t i = 0; i < extractColumnName.size(); ++i) { mat->setColName(i, extractColumnName[i]); } for (size_t i = 0; i < sampleToInclude.size(); i++) { if (processed.find(sampleToInclude[i]) == processed.end()) { logger->warn("Covariate file does not contain sample [ %s ]", sampleToInclude[i].c_str()); sampleToDrop->insert(sampleToInclude[i]); }; } if (handleMissingCov == DataLoader::COVARIATE_DROP) { assert(missing.empty()); return (*mat).nrow(); } // impute missing covariates to mean by column for (int col = 0; col < mat->ncol(); ++col) { double sum = 0; int nonZero = 0; for (int row = 0; row < (*mat).nrow(); ++row) { if (missing.count(std::make_pair(row, col))) continue; // missing sum += (*mat)[row][col]; ++nonZero; } if (nonZero == 0) { // all column are missing, drop column logger->info( "Covariate [ %s ] is missing for all samples. Exclude please " "before " "continue!", mat->getColName()[col].c_str()); return -1; } // some elements are missing double mean = sum / nonZero; for (int row = 0; row < (*mat).nrow(); ++row) { if (missing.count(std::make_pair(row, col))) { (*mat)[row][col] = mean; } } } return (*mat).nrow(); } // end extractCovariate
jobject CAstWrapper::makeFieldEntity(jobject declaringClass, jobject name, bool isStatic, list<jobject> *modifiers) { jobject entity = env->NewObject(NativeFieldEntity, fieldEntityInit, getConstantValue(name), makeSet(modifiers), isStatic, declaringClass); THROW_ANY_EXCEPTION(java_ex); return entity; }
int Image::read(string filepath) throw(ExceptionTP1) { // Ouverture du fichier .pbm std::ifstream ifs; ifs.open (filepath, ifstream::in); // Initialisation de l'aléatoire // time(NULL) renvoie le nb de secondes depuis le 1/01/1970, ce qui change à chaque run, et nous prenons ainsi un nouveau seed de random srand((unsigned int) time(NULL)); if (ifs.is_open()) { try { // Initialisation des variables utiles à la lecture du fichier m_pixels.clear(); string bufferLigne = ""; int numeroLigne = 0; char c = ifs.get(); while (ifs.good()) { bufferLigne += c; // Lecture du header (largeur et hauteur notamment) if (c == '\n') { if (numeroLigne == 1) { size_t pos = bufferLigne.find(" "); m_largeur = stoi(bufferLigne.substr(0, pos)); m_hauteur = stoi(bufferLigne.substr(pos)); } numeroLigne++; bufferLigne = ""; } // Lecture des pixels de l'image if ((c == '0' || c == '1' ) && numeroLigne >= 2) { Pixel* pix; if (c == '0') { // Création d'un pointeur sur Pixel coloré aléatoirement si le pixel était blanc pix = new Pixel(rand()%NB_COULEURS, rand()%NB_COULEURS, rand()%NB_COULEURS); } else { // Création d'un pointeur sur Pixel noir si le pixel était noir pix = new Pixel(); } // Le pixel est son propre représentant au début de l'algorithme ; il est donc le seul de son ensemble makeSet(pix); } else if (c != '0' && c != '1' && c != ' ' && c != '\n' && numeroLigne >= 2) { throw ExceptionTP1(ERREUR_FORMAT); } c = ifs.get(); } } catch (exception e) { throw ExceptionTP1(ERREUR_FORMAT); } } else { throw ExceptionTP1(ERREUR_LECTURE); } // Fermeture du fichier .pbm ifs.close(); return 0; }
DisjointSet(const int size) : count(size), table(nullptr), rank(nullptr) { makeSet(size); }