void EulerUtils::Display::printSet ( string itemName, const set<unsigned long long>& data ) { cout << endl << "Printing " << itemName << "..." << endl; for ( auto i = data.cbegin(); i != data.cend(); i++ ) { cout << ( i == data.cbegin() ? "" : ", " ) << *i ; } cout << endl; }
/** Extract masked detectors from a MaskWorkspace * @return vector of detector IDs of the detectors that are * masked */ std::vector<detid_t> ExtractMaskToTable::extractMaskFromMaskWorkspace() { // output vector std::vector<detid_t> maskeddetids; // Go through all spectra to find masked workspace MaskWorkspace_const_sptr maskws = boost::dynamic_pointer_cast<const MaskWorkspace>(m_dataWS); size_t numhist = maskws->getNumberHistograms(); for (size_t i = 0; i < numhist; ++i) { // Rule out the spectrum without mask if (maskws->readY(i)[0] < 1.0E-9) continue; // Get spectrum const API::ISpectrum *spec = maskws->getSpectrum(i); if (!spec) throw runtime_error( "Unable to get spectrum reference from mask workspace."); const set<detid_t> detidset = spec->getDetectorIDs(); std::copy(detidset.cbegin(), detidset.cend(), std::inserter(maskeddetids, maskeddetids.end())); } return maskeddetids; }
void BogglePlayer::buildLexicon(const set<string>& word_list){ string newWord; const int minimum_word_length = 3; set<string>::iterator wordlistBegin = word_list.cbegin(); set<string>::iterator wordlistEnd = word_list.cend(); std::srand(unsigned(time(0))); std::vector<string> vector; for(; wordlistBegin != wordlistEnd; ++wordlistBegin) { vector.push_back(*wordlistBegin); } std::random_shuffle(vector.begin(), vector.end()); for(auto it = vector.begin(); it != vector.end(); ++it) { newWord.assign(*it); if(newWord.length() >= minimum_word_length) { t->add(newWord); } } BogglePlayer::buildLexiconFlag = true; };
unsigned RelationManager::cleanSet(set<const Class *> &s) { unsigned deletedRecords = 0; for (auto it = s.cbegin(); it != s.cend();) { if ((*it) == nullptr) { s.erase(it++); ++deletedRecords; } else ++it; } return deletedRecords; }
unsigned select(const vector<unsigned> &S, const set<unsigned> &Suni, const string &mode) { unsigned res; auto Suni_it = Suni.cbegin(); if (mode == "uni") { advance(Suni_it, rand() % Suni.size()); res = *(Suni_it); } else if (mode == "pop") res = *(S.cbegin() + rand() % S.size()); return res; }
void Server::precomputeTransferPatterns() { // ProfilerStart("log/tp.perf"); if (loadTransferPatternsDB(&_tpdb)) { _log.info("Loaded transfer patterns."); } else { if (_tpdb.numGraphs() == 0) { _tpdb.init(_network.numStops(), _router.hubs()); } const int progId = _log.beginProg(); const size_t numStops = _network.numStops(); const int nThreads = _maxWorkers > omp_get_max_threads() ? omp_get_max_threads() : _maxWorkers; omp_set_num_threads(nThreads); int progress = 0; #pragma omp parallel { // NOLINT const TransitNetwork network = _network; const HubSet hubs = _router.hubs(); TPDB tpdb(network.numStops(), hubs); #pragma omp for schedule(dynamic, 3) for (size_t stop = 0; stop < numStops; ++stop) { const set<vector<int> > patterns = TransferPatternRouter::computeTransferPatterns(network, stop, hubs); for (auto it = patterns.cbegin(), end = patterns.cend(); it != end; ++it) tpdb.addPattern(*it); tpdb.finalise(stop); // clears construction cache #pragma omp critical(progress_message) if (progress < 100 || progress % (numStops / 100) == 0) _log.prog(progId, progress + 1, numStops, "computing transfer patterns (mt)", omp_get_num_threads()); #pragma omp atomic ++progress; } #pragma omp critical(reduction) { // NOLINT // combine and clear the local TPDB _tpdb += tpdb; tpdb = TransferPatternsDB(); } } // pragma omp parallel saveTransferPatternsDB(_tpdb); } _router.transferPatternsDB(_tpdb); // ProfilerStop(); }
static set<range> merge(const vector<range>& vr){ const set<range> sr(vr.cbegin(), vr.cend()); set<range> result; // doAlgo(vr.cbegin(), vr.cend(), res); if(sr.size() == 0){ return result; } auto iter = sr.cbegin(); range prev = *iter; while(++iter != sr.cend()){ range curr = *iter; if(prev.second < curr.first){ result.insert(prev); prev = curr; } else { prev = range(prev.first, max(prev.second, curr.second)); } } result.insert(prev); return result; }
set<M> operator+ (const set<M>& lhs, const set<M>& rhs){ set<M> U{lhs}; U.insert(rhs.cbegin(), rhs.cend()); return U; }
int main() { //the next few lines are to set unbuffered cin //it means you don't have to press [enter] in the keyboard // tcgetattr(STDIN_FILENO,&old_t);//gets the current terminal setings. new_t=old_t; new_t.c_lflag &=(~ICANON & ~ECHO);//disable ... tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered // ***************************************************** size_t number_partidas; size_t number_projects=0; while(1) { main1=&main2; char option=main1->menu(); bool ok; switch(option) { case 'w': //write a new partida /* restore the former settings */ tcsetattr(STDIN_FILENO,TCSANOW,&old_t);//buffered keyboard ok = true; try { main1 -> enter_data ();//we've filled a new object } catch(const char* e) { cout<<"errooooor !!!!!!"<<endl; cout << endl << e << endl; ok = false; } if(ok) { cont_main2.insert(main2); // int a=3; if(!project.size()) project.push_back(cont_main2); else { project.pop_back(); project.push_back(cont_main2); } } else cout << "I have inserted no partida"; tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered break; case 'p': //see a specific partida cout << "\n\n"; // string part=main2.partida; /* restore the former settings */ tcsetattr(STDIN_FILENO,TCSANOW,&old_t);//keyboard buffered cin>>main2.parti; tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered //converses string to float main2.find_partida(main2.parti);//find out the actual number cout << fixed << setprecision(2);//only 2 decimals // main2.find_partida(main2.partida); p=cont_main2.find(main2);//it is in cont_main2 if(p != cont_main2.cend()) { main2 = *p; main1 = &main2; //main1->print_partida(main2);//p contains a object (partida main1 -> print_partida(main2);//p contains a object (partida cout << "\nEdit ? (y/n)"; char ed; cin >> ed; if(ed == 'y' || ed == 'Y')main1->edit(); } else cout << "\n\nNot found !!!!" << endl; break; case 'e': //edit a specific partida break; case 's': //we want to save th whole set, not only one object file.open("prevision.bin",ios_base::out | ios_base::binary); if(file.is_open()) { number_partidas = cont_main2.size(); // static size_t number_projects=0; // number_projects=project.size(); //the first byte in disk will be the number of objects/partidas.. next the objects file.write(reinterpret_cast<const char*>(&(number_partidas)),sizeof(number_partidas)); //the second byte will contain the number of projectd // file.write(reinterpret_cast<const char*>(&(number_projects)),sizeof(number_projects)); p=cont_main2.cbegin();//point to the begining of the vector (dinamic array) main2=*p; main1=&main2; // main1 -> saveMonths(); for(size_t x = 0 ; x < number_partidas ; ++x) { main2 = *p; main1 -> save_file();//p contains an object a partida...saves ONE object/partida ++p;//next object ... next partida } } file.close(); cout << "\n*** FILE SAVED ***\n"; break; case 'l': file.open("prevision.bin",ios_base::in | ios_base::binary); if(file.is_open()) { cont_main2.erase(cont_main2.begin(),cont_main2.end()); int numberPartidas;//we read the number of objects/partidas file.read((char*)&numberPartidas,sizeof(numberPartidas) ); for(int x = 0;x < numberPartidas; ++x) main1 -> load_partida(); project.push_back(cont_main2); } file.close(); cout << "\n*** FILE LOADED ***\n"; break; case 'i': number_partidas = cont_main2.size(); p_project = project.begin(); // p=cont_main2.begin(); cout << endl << "List:" << endl; number_projects = project.size(); static size_t indexProjects; indexProjects=0; for(size_t proj = 0 ; proj < number_projects ; ++proj) { p = (*p_project).begin();//??????????????? cont_main2=*(project.begin()); p=cont_main2.begin();//ok !!!!!! // main1 -> headProjectMonth(indexProjects); for(size_t x = 0 ; x<number_partidas ; ++x) { main1 -> list();//writes one line/partida ++p; } cout << endl << endl; ++p_project; ++indexProjects; } cout << "\n\033[0;0mWould you like to create a monthly prevision from this list?" << "\033[?25h"; char a; cin.clear(); cout << "\033[?25l"; cin >> a; if(a =='y' || a =='Y') { project.push_back(cont_main2); //now we should save this container of containers on HDD //so..... ++number_projects; p_project=--project.end();//points past end so -- //no it point to the last set (the last budget) cont_main2 = *p_project;//a contains a set a month //we go to the begin(). The firs partida of this new monthly //budget.. Because the variable "month" is static. //only storing in the first line we are storing the month of //every partida. main2 = *cont_main2.begin();//main 2 contains a line a single partida main1 = &main2; cout << "\033[?25h"; char monthLastPrevision[] = "MArch"; buffered(); cout << "\nWhat month? "; cin >> monthLastPrevision; //we enter this month in the vector months main1 -> enterMonth (monthLastPrevision); unbuffered();//cin unbuffered (keyboard) cout << "\033[?25l";//hide cursor }