static bool build_url(const string &line) // line from the input file { try { oodles::url::URL url(line); cout << "Tokenised URL: " << url << endl; cout << "Domain, Path and Page document IDs: " << url.domain_id() << ", " << url.path_id() << ", " << url.page_id() << endl; cout << "Testing iterator access..."; if (find(url.begin(), url.end(), "http") != url.end()) cout << "(http scheme), "; if (find(url.begin(), url.end(), "index.html") != url.end()) cout << "(.html index page), "; if (count(url.begin(), url.end(), "www") > 0) cout << "(www host)."; cout << endl; cout << "Testing bidirectional iteratation..."; for (oodles::url::URL::iterator i = url.end() ; i != url.begin() ; ) cout << *(--i) << ","; cout << endl << endl; } catch (const exception &e) { cerr << e.what(); return false; } return true; }
virtual const std::string do_type() const throw () { // // A real application should use OS facilities for this. This // is a crude hack. // using std::find; using std::string; using boost::algorithm::iequals; using boost::next; string media_type = "application/octet-stream"; const string::const_reverse_iterator dot_pos = find(this->url_.rbegin(), this->url_.rend(), '.'); if (dot_pos == this->url_.rend() || next(dot_pos.base()) == this->url_.end()) { return media_type; } const string::const_iterator hash_pos = find(next(dot_pos.base()), this->url_.end(), '#'); const string ext(dot_pos.base(), hash_pos); if (iequals(ext, "wrl")) { media_type = "model/vrml"; } else if (iequals(ext, "x3dv")) { media_type = "model/x3d+vrml"; } else if (iequals(ext, "png")) { media_type = "image/png"; } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) { media_type = "image/jpeg"; } return media_type; }
virtual const std::string do_type() const throw () { // // A real application should use OS facilities for this. This // is a crude hack because sdl-viewer uses std::filebuf in // order to remain simple and portable. // using std::find; using std::string; using boost::algorithm::iequals; using boost::next; string media_type = "application/octet-stream"; const string::const_reverse_iterator dot_pos = find(this->url_.rbegin(), this->url_.rend(), '.'); if (dot_pos == this->url_.rend() || next(dot_pos.base()) == this->url_.end()) { return media_type; } const string::const_iterator hash_pos = find(next(dot_pos.base()), this->url_.end(), '#'); const string ext(dot_pos.base(), hash_pos); if (iequals(ext, "wrl")) { media_type = openvrml::vrml_media_type; } else if (iequals(ext, "x3dv")) { media_type = openvrml::x3d_vrml_media_type; } else if (iequals(ext, "png")) { media_type = "image/png"; } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) { media_type = "image/jpeg"; } return media_type; }
inline void unite(int x, int y) { x = find(x), y = find(y); if(x == y) { ans++; return; } if(rank[x] < rank[y]) { par[x] = y; } else { par[y] = x; rank[x] += rank[x] == rank[y]; } }
int main() { //input int a, b; scanf("%d%d", &n, &m); memset(g, false, sizeof(g)); for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); g[a][b] = true; } //floyd for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (g[i][k] && g[k][j]) g[i][j] = true; for (int i = 1; i <= n; i++) g[i][i] = true; //find all subsets of H find_h(1); //h[0]: empty set //h[1]: Max(X) swap(h[1], *find(h, h+num_h, max(H(true)))); /** * pre-computing * * The results of the operations between items in H, consist a close * group of itself. This means that the results are also in H. */ for (int i = 0; i < num_h; i++) { for (int j = 0; j < num_h; j++) { h_equalgreater[i][j] = find(h, h+num_h, equalgreater(h[i], h[j])) - h; h_intersection[i][j] = find(h, h+num_h, intersection(h[i], h[j])) - h; h_unionset[i][j] = find(h, h+num_h, unionset(h[i], h[j])) - h; } } //processing int k; scanf("%d\n", &k); while (k-- > 0) { cin.getline(s, MAXL); memset(alphabeta, -1, sizeof(alphabeta)); for (char *p = s; *p; ++p) { if (isupper(*p)) alphabeta[*p-'A'] = 0; else if (*p == '>') //simplify the input, "=>" --> ">" *(p-1) = ' '; } printf(solve(0)?"valid\n":"invalid\n"); } return 0; }
void Mesh::connect_face(int u, int v) { if (u == v) return; if (find(adj_face[u].begin(), adj_face[u].end(), v) != adj_face[u].end()) return; adj_face[u].push_back(v); }
void World::removeEntity(const shared_ptr<Entity> &entity) { auto it = find(m->entities.begin(), m->entities.end(), entity); if (it == m->entities.end()) { throw std::runtime_error("Entity is not there to remove!"); } m->entities.erase(it); }
/* * Fetches a tile from a specific set specified by set_number * Returns the fetched tile. */ shared_ptr<Tile> Model::fetch_tile_from_set( int set_number, string tile_name ){ Set* set = get_set_from_table( set_number ); shared_ptr<Tile> tile = set->get_and_erase_tile( tile_name ); if (tile->is_joker()) { tile->reset_joker(); } cout << "Fetched " << tile->get_name() << " from set " << set_number << endl; // If there is only one tile left in set, fetch the remaining tile if (set->size() == 1) { string last_tile_name = set->get_tiles().front()->get_name(); cout << "Automatically fecthed last tile " << last_tile_name << " from set " << set_number << " to hand" << endl; shared_ptr<Tile> last_tile = set->get_and_erase_tile( last_tile_name ); if (last_tile->is_joker()) { last_tile->reset_joker(); } Model::get_instance().add_fetched_tile_to_hand( last_tile ); // Remove set since all tiles have been fetched auto it = find(table.begin(), table.end(), set); table.erase(it); } return tile; }
bool contains(const table& tbl, int val) { // return true if tbl contains val int hash_val = hash(val) % tbl.size(); bucket::const_iterator first = tbl[hash_val].begin(); bucket::const_iterator last = tbl[hash_val].end(); return find(first, last, val) != last; }
bool goal(const TCandidate &candidate, const string::const_iterator &query_end, float &min_suggestion_prob, vector<string> &suggestions) { if (candidate.node->sub_trees.size() > 0) // leaf has no subtrees return false; if (candidate.query != query_end) // query must be already matched at trie leaf return true; // remove string delimiter in trie string suggestion(candidate.suggestion.substr(0, candidate.suggestion.size() - 1)); // no duplicates in results allowed if (find(suggestions.begin(), suggestions.end(), suggestion) == suggestions.end()) { // set criterion that P(solution) must be greater that P(best solution) / 100 if (suggestions.empty()) min_suggestion_prob = candidate.probability / (float)100.; suggestions.push_back(suggestion); } return true; }
void HelpConfigDialog::Rename(wxCommandEvent &event) { wxListBox *lst = XRCCTRL(*this, "lstHelp", wxListBox); wxString orig = lst->GetString(lst->GetSelection()); wxString text = wxGetTextFromUser(_("Rename this help file title:"), _("Rename title"), orig); if (!text.IsEmpty()) { HelpCommon::HelpFilesVector::iterator logEnd = m_Vector.end() - HelpCommon::getNumReadFromIni(); HelpCommon::HelpFilesVector::iterator it = find(m_Vector.begin(), logEnd, text); if (it != logEnd) { cbMessageBox(_("This title is already in use."), _("Warning"), wxICON_WARNING); return; } if (text.Find(_T('/')) != -1 || text.Find(_T('\\')) != -1) { cbMessageBox(_("Slashes and backslashes cannot be used to name a help file."), _("Warning"), wxICON_WARNING); return; } m_Vector[lst->GetSelection()].first = text; lst->SetString(lst->GetSelection(), text); } }
TFile* histfiles::initializeTFile(const char *processor_name, bool debug) { stringstream _name; _name << processor_name; if(_name.str()=="") _name.str("cafe"); Config config(_name.str().c_str()); string _output = config.get("Output", "result.root"); if(debug) cout << "histfiles::initializeTFile:" << " PROCESSOR_NAME=" << _name.str() << " OUTPUT_FILE=" << _output << endl; if (_output=="") return NULL; // keep track of rootuples that have been already created during this session TFile *f = NULL; if (find(_histfiles_created.begin(), _histfiles_created.end(), _output) == _histfiles_created.end()) { if(debug) cout << "histfiles::initializeTFile: Output file has not been opened yet" << endl; f = new TFile(_output.c_str(),"RECREATE"); if (f!=NULL) { _histfiles_created.push_back(_output); } } else { if(debug) cout << "histfiles::initializeTFile: Output file has been already created" << endl; f = new TFile(_output.c_str(),"UPDATE"); } return f; }
bool release(ObjectType* theInstance) { #if !defined(XALAN_NO_STD_NAMESPACE) using std::find; #endif typedef typename VectorType::iterator IteratorType; const IteratorType i = find( m_busyList.begin(), m_busyList.end(), theInstance); if (i == m_busyList.end()) { return false; } else { m_resetFunctor(theInstance); m_availableList.push_back(theInstance); m_busyList.erase(i); return true; } }
auto operator()(const T & t, const C<T> & c) const { using std::find; auto found = find(c.begin(), c.end(), t); return found != c.end(); }
void UpdateIndicies(Device const& device) { vector<DWORD>& channelIndicies = m_channelsIndicies[device.DeviceID()]; vector<string>const& channelStrings = m_channels[device.DeviceID()]; channelIndicies.clear(); // Create a list of strings from the device vector<string> sourceNames = device.GetChannelNames(); vectorStringIter sourceBegin = sourceNames.begin(); vectorStringIter sourceEnd = sourceNames.end(); // do a search for each name for(vectorStringIter iter = channelStrings.begin(); iter < channelStrings.end(); ++iter) { vectorStringIter item = find(sourceBegin, sourceEnd, *iter); if (item == sourceEnd) { UCSBUtility::LogError("Data Aggregator config failure: " "%s field does not exist in device %s", iter->c_str(), device.DisplayName().c_str()); } else { channelIndicies.push_back(item - sourceBegin); } } }
int main() { list<string>slist; string s; while(cin>>s) slist.push_back(s); auto iter = find(slist.begin(),slist.end(),"xixixix"); if(iter != slist.end()) slist.erase(iter); auto orig = slist; //keep a copy before we destroy the contents slist.clear(); //delete all the elements within the container cout<<"after clear, size is: "<<slist.size()<<endl; slist = orig; //restore the list slist.erase(slist.begin(),slist.end()); //equivalent cout<<"after erase begin to end,size is: "<<slist.size()<<endl; slist = orig; //restore the list auto elem1 = slist.begin(),elem2 = slist.end(); //delete the range of elements between two iterators //returns a iterator to the element just after the last removed element elem1 = slist.erase(elem1,elem2); cout<<"after erase elem1 to elem2,size is: "<<slist.size()<<endl; if(elem1 != elem2) cout<<"somethings wrong "<<endl; else cout<<"okay,they are equal"<<endl; }
int FP_Socks5::choseMethod(const fp_socks5_method_t *method) { for (unsigned int i = 0; i < (unsigned int) method->nMethods; ++i) { if (find(method_list.begin(), method_list.end(), method->methods[i]) != method_list.end()) { return method->methods[i]; } } return S5_METHOD_WRONG; }
LevelItemErase::~LevelItemErase() { if (find(level->Items().begin(), level->Items().end(), item) == level->Items().end()) { item->UnloadContent(); delete item; } }
int main() { list<int> numbers{1, 2, 3, 4, 5, 6, 0, 7, 8, 9}; auto zero = find(numbers.crbegin(), numbers.crend(), 0); if (zero != numbers.crend()) { cout << *zero << endl; } return 0; }
void SujetDObservation::detacher(Observateur * obs) { vector<Observateur *>::iterator it = find(mesObservateurs.begin(),mesObservateurs.end(),obs) ; if (it != mesObservateurs.end()) { mesObservateurs.erase(it) ; } }
// returns pointer to Group with name if it exists, empty pointer otherwise shared_ptr<Group> Model::find_group(const std::string& name) const { auto iter = find(m_groups.begin(), m_groups.end(), name); // If group not found return empty pointer if (iter == m_groups.end()) { return shared_ptr<Group>(); } return *iter; }
int main() { string word; vector<string> excluded{"abc", "aaa", "abd"}; cin >> word; auto found = find(excluded.cbegin(), excluded.cend(), word); // searching in a unsorted vector takes O(n) time, while it only takes O(1) in a unordered_set, O(logN) in a set (it's sorted). cout << (found == excluded.end() ? "not excluded" : "excluded") << endl; return 0; }
std::string HTTPServer::process(std::vector<char> &request) { std::vector<char>::iterator pos; pos = find(request.begin(), request.end(), ' '); std::string request_type(request.begin(), pos); request.erase(request.begin(), ++pos); pos = find(request.begin(), request.end(), ' '); std::string request_path(request.begin(), pos); if(request_path == "/") request_path = "/index.html"; std::string response = this->http_version; if(readFromFile(request_path)) { if(request_type == "GET") { response += getStatusCode(200); response += this->server_name; response += getContentType(request_path); response += getContentLength(); response += "\r\n"; for(pos = this->file_buffer.begin(); pos != this->file_buffer.end(); ++pos) { response += *pos; } } } else { std::string status; if(errno == EACCES) status = getStatusCode(403); else if(errno == ENOENT) status = getStatusCode(404); response += status; response += this->server_name; response += getContentType(".html") + "\r\n\r\n"; response += "<!DOCTYPE html><html><head><title>Error " + status.substr(0,3) + " Page</title></head><body><p align='center'><h1>Error " + status + "</h1></body></html>\r\n"; response.insert(response.find("\r\n\r\n"), "\r\n" + getContentLength(response)); } printf("%s\n", response.c_str()); return response; }
bool CmdLineOptions::is_posarg_set(const std::string& option) const { if ( !m_parse_called ) { throw cmdline::ParseNotCalled("is_posarg_set()"); } bool is_set = true; if ( find(m_posargs.begin(), m_posargs.end(), option) == m_posargs.end() ) { is_set = false; } return is_set; }
void searchArray() { int nValue; cout << "Enter the number to be searched in the array\n"; cin >> nValue; int *pSearch = find(&nNumbers[0], &nNumbers[6], nValue); cout << "Number " << (pSearch == &nNumbers[6] ? "not found" : "found") << endl; }
void searchVector() { vector<int> intVec(nNumbers, nNumbers+6); int nValue; cout << "Enter the number to be searched in the vector\n"; cin >> nValue; vector<int>::iterator iter = find(intVec.begin(), intVec.end(), nValue); cout << "Number " << (iter == intVec.end() ? "not found" : "found") << endl; }
void searchList() { list<int> intList(nNumbers, nNumbers+6); int nValue; cout << "Enter the number to be searched in the list\n"; cin >> nValue; list<int>::iterator iter = find(intList.begin(), intList.end(), nValue); cout << "Number " << (iter == intList.end() ? "not found" : "found") << endl; }
LevelItemErase::LevelItemErase(LevelItem* levelItem, Level* level, QUndoCommand* parent) : QUndoCommand(parent), item(levelItem), position(position), level(level) { setText("Insert LevelItem"); LevelItems::iterator it = find(level->Items().begin(), level->Items().end(), item); if (it != level->Items().begin()) it--; position = *it; }
double Lemm_collection::Compute_IQF(const vector<int> &frag, const vector<int> &query, const vector<int> &doc) { double res = 0; int freq = 0; for (size_t f_it = 0; f_it < frag.size(); ++f_it) { if (find(query.begin(), query.end(), frag[f_it] % 1000000) == query.end()) { freq = Compute_IF(frag[f_it] % 1000000, doc); res += Compute_ICLF(frag[f_it] % 1000000, freq); } } return res; }
// Remove a Group with matching name, throws and Error if no Group with // that name exists void Model::remove_group(const string& name) { // Try to locate the Group with name in container auto iter = find(m_groups.begin(), m_groups.end(), name); // If group not found throw and Error if (iter == m_groups.end()) { throw Error("Group not found!"); } // Group was found, remove it from the container m_groups.erase(iter); }