Set < string > WebPage::allWords () const { Set < string > wordlist; unsigned int index = 0; bool space = false; //consider special characters as space int size = words.size (); string word; for (int a = 0; a < size; a++) { for (unsigned int i = 0; i < words.at (a).length (); i++) { char c = words.at (a).at (i); if (c < 48 || (c > 57 && c < 65) || (c > 90 && c < 97) || c > 122) //if there is a special character { if (!space) { word = words.at (a).substr (index, i - index); // get the substring of the whole string if (wordlist.find (word) == wordlist.end ()) // if word doesn't exist in the list wordlist.insert (lower (word)); //convert it to lowercase space = true; //start looking for another word } } else //if it isn't a special character { if (space) { space = false; index = i; } else if (i == words.at (a).length () - 1) { word = words.at (a).substr (index, i - index + 1); if (wordlist.find (word) == wordlist.end ()) //if it's not in the set wordlist.insert (lower (word)); //add it to the set } } } space = false; index = 0; } return wordlist; }
void RefsGroup::allotId(void) { // First insert all reference pictures into a set Set<std::uint32_t> rps; for (auto sample : mRefsList) { for (auto refIdx : sample) { rps.insert(refIdx); } } // Tag samples: // - every reference picture is give a non-zero positive tag // - every non-reference picture is give a tag a zero // The non-zero tags are currently set to sample index value + 1 // Map<std::uint32_t, std::uint32_t> sampleTag; std::uint32_t sampleIdx = 0; for (auto sample : mRefsList) { if (rps.find(sampleIdx) != rps.end()) { mSampleId.insert(std::make_pair(sampleIdx, sampleIdx + 1)); } else { mSampleId.insert(std::make_pair(sampleIdx, 0)); } sampleIdx += 1; } }
static constexpr auto apply(Set set) { return searchable_set([=](auto p) { return set.find([=](auto set) { return any_of(set, p); }).find(p); }); }
bool Config::loadSetting(const std::string &line, const std::string &name, Set &var) const { size_t i = isSetting(line, name, "="); if(i != std::string::npos) { var.clear(); var.insert( trim(line.substr(i)) ); return true; } i = isSetting(line, name, "+="); if(i != std::string::npos) { var.insert( trim(line.substr(i)) ); return true; } i = isSetting(line, name, "-="); if(i != std::string::npos) { Set::iterator a = var.find( trim(line.substr(i)) ); if(a != var.end()) { var.erase(a); } return true; } return false; }
void ParticlesEditorSceneModelHelper::AddNewNodesToSceneGraph(EffectParticleEditorNode* node, Entity* effectRootNode) { Set<Entity*> entitiesInParticleEditor; Set<Entity*> entitiesInSceneGraph; BuildEntitiesSets(node, effectRootNode, entitiesInParticleEditor, entitiesInSceneGraph); // Scene Graph contains more items than Particle Emitter node, add the new ones. int emittersCountInEffect = effectRootNode->GetChildrenCount(); for (int32 i = 0; i < emittersCountInEffect; i ++) { if (entitiesInParticleEditor.find(effectRootNode->GetChild(i)) != entitiesInParticleEditor.end()) { continue; } // Create the new Emitter and add it to the tree. ParticleEmitter * emitter = GetEmitter(effectRootNode->GetChild(i)); if (!emitter) { continue; } EmitterParticleEditorNode* emitterEditorNode = new EmitterParticleEditorNode(effectRootNode, effectRootNode->GetChild(i), QString::fromStdString(effectRootNode->GetChild(i)->GetName())); node->AddNode(emitterEditorNode); } }
static constexpr auto apply(Set set) { return make_infinite_set([=](auto p) { return set.find([=](auto set) { return any_of(set, p); }).find(p); }); }
// ============================================================================ // update the content of Data-On-Demand actions // ============================================================================ StatusCode DataOnDemandSvc::update () { if ( !m_updateRequired ) { return StatusCode::SUCCESS ; } /// convert obsolete "Nodes" into new "NodeMap" StatusCode sc = setupNodeHandlers() ; // convert "Nodes" new "NodeMap" if ( sc.isFailure() ) { stream() << MSG::ERROR << "Failed to setup old \"Nodes\"" << endmsg ; return sc ; } /// convert obsolete "Algorithms" into new "AlgMap" sc = setupAlgHandlers() ; // convert "Algorithms" into "AlgMap" if ( sc.isFailure() ) { stream() << MSG::ERROR << "Failed to setup old \"Algorithms\"" << endmsg ; return sc ; } /// add the default prefix add_prefix ( m_algMap , m_prefix ) ; /// add the default prefix add_prefix ( m_nodeMap , m_prefix ) ; /// get all directories typedef std::set<std::string> Set ; Set dirs ; if ( m_partialPath ){ get_dirs ( m_algMap , dirs ) ; } if ( m_partialPath ){ get_dirs ( m_nodeMap , dirs ) ; } // Set::iterator _e = dirs.find("/Event") ; if ( dirs.end() != _e ) { dirs.erase( _e ) ; } // add all directories as nodes for ( Set::const_iterator dir = dirs.begin() ; dirs.end() != dir ; ++dir ) { if ( m_algMap .end () != m_algMap .find ( *dir ) ) { continue ; } if ( m_nodeMap .end () != m_nodeMap .find ( *dir ) ) { continue ; } m_nodeMap [*dir] = "DataObject" ; } // m_algs .clear () ; m_nodes .clear () ; // /// setup algorithms for ( Map::const_iterator ialg = m_algMap.begin() ; m_algMap.end() != ialg ; ++ialg ) { if (i_setAlgHandler(ialg->first, ialg->second).isFailure()) return StatusCode::FAILURE; } /// setup nodes for ( Map::const_iterator inode = m_nodeMap.begin() ; m_nodeMap.end() != inode ; ++inode ) { i_setNodeHandler(inode->first, inode->second); } /// m_updateRequired = false ; // return StatusCode::SUCCESS ; }
void lookup( const Set& set, const std::string& word ) { Set::iterator it = set.find( word ); std::cout << word << ": " << ( it != set.end() ? "present" : "==== not present ====" ) << std::endl; }
// Generates the set given a word, and adds to map Set<WebPage*> SearchEngine::generateQuery(const std::string query) const { Set<WebPage*> containing; for(std::vector<WebPage*>::const_iterator it = pages.begin(); it != pages.end(); ++it) { Set<std::string> words = (*it)->allWords(); if(words.find(query) != words.end()) containing.insert(*it); } return containing; }
CubeArea* CubeArea::expandBase(AggregationMaps *aggregationMaps) const { const vector<Dimension*> &dimensions = *cube->getDimensions(); CubeArea* result = new CubeArea(env, cube, dimensions.size()); aggregationMaps->resize(dimensions.size()); if (dimCount() != dimensions.size()) { throw ErrorException( ErrorException::ERROR_INTERNAL, "CubeArea::expandBase area and dimension size differ."); } auto didit = dimensions.begin(); for (size_t dim = 0; dim < dimCount(); dim++, ++didit) { Dimension* dimension = *didit; Set* s = new Set(); for (ConstElemIter eit = elemBegin(dim); eit != elemEnd(dim); ++eit) { IdentifierType eId = *eit; Element* element = dimension->lookupElement(eId); if (!element) { LOG(ERROR) << "CubeArea::expandBase element id: " << *eit << " not found in dimension: " << dimension->getName(); continue; // possible corrupted journal } /* DLOG(WARNING) << "CubeArea::expandBase element id: " << eId << " added in dimension: " << dimension->getName() ; */ try { const WeightedSet* baseE = dimension->getBaseElements(element); for (auto baseIt = baseE->begin(); baseIt != baseE->end(); ++baseIt) { // it seems there is a bug in Set::insert which adds the same id multiple times. // therefore check if the element already exists if (s->find(baseIt.first()) == s->end()) { s->insert(baseIt.first()); } } /* DLOG(WARNING) << "CubeArea::expandBase adding " << baseE->size() << " source elements to aggregation map." ; */ aggregationMaps->at(dim).buildBaseToParentMap(eId, baseE); } catch (const ErrorException& e) { // LOG(ERROR) << "CubeArea::expandBase exception: " << e.getMessage(); } } result->insert(dim, s); aggregationMaps->at(dim).compactSourceToTarget(); } return result; }
Set operator|(const Set& a, const Set& b) { Set join; Set::Iterator it_a = a.begin(); while( it_a != a.end() ){ Set::Iterator it_b = b.begin(); while( it_b != b.end( ) ) { if( *it_a != *it_b ) { if( !join.find( *it_a ) ) join.insert( *it_a ); if( !join.find( *it_b ) ) join.insert( *it_b ); } it_b++; } it_a++; } return join; }
bool WatcherData::unwatch(const Path& path) { std::lock_guard<std::mutex> lock(mutex); auto p = paths.find(path); if (p == paths.end()) return false; paths.erase(p); CFRunLoopSourceSignal(source); CFRunLoopWakeUp(loop); return true; }
std::string nextInSet(const std::string& argName, const Set& legalValues) { std::string v= next(argName); if (legalValues.find(v) == legalValues.end()) { std::ostringstream msg; msg << "Must be one of \"" << util::join(legalValues.begin(), legalValues.end(), "\", \"") << "\""; --current_; throw IllegalValueError(appName(), argName, v.c_str(), msg.str()); } return v; }
Matrix makeMatrix(std::vector<WebPage*>& pages) { // sets have intersection (useful) Set<WebPage*> setOfPages(pages.begin(), pages.end()); // make the answer size_t n = pages.size(); Matrix ans(n); // for every page std::vector<WebPage*>::iterator i, j; size_t row = 0, col; i = pages.begin(); while (i != pages.end()) { // reset col col = 0; // go through every other page j = pages.begin(); Set<WebPage*> out = (*i)->allOutgoingLinks().setIntersection(setOfPages); while (j != pages.end()) { // every page can be randomly URL'd to ans[col][row] = RANDOM_RESTART / n; // if there are no outgoing links, // then assume there is a link to everything if (out.size() == 0) { ans[col][row] += (1 - RANDOM_RESTART) / n; } // if there is a link from i to j else if (out.find(*j) != out.end()) { // this page can also be linked to ans[col][row] += (1 - RANDOM_RESTART) / out.size(); } // increment ++ j; ++ col; } // increment ++ i; ++ row; } return ans; }
void TestTools::set_insert() { { Set<int> set1; QVERIFY(set1.size() == 0); set1.insert(1); QVERIFY(set1.size() == 1); set1.insert(2); QVERIFY(set1.size() == 2); set1.insert(2); QVERIFY(set1.size() == 2); QVERIFY(set1.contains(2)); set1.remove(2); QVERIFY(set1.size() == 1); QVERIFY(!set1.contains(2)); set1.insert(2); QVERIFY(set1.size() == 2); QVERIFY(set1.contains(2)); } { Set<int> set1; QVERIFY(set1.size() == 0); set1 << 1; QVERIFY(set1.size() == 1); set1 << 2; QVERIFY(set1.size() == 2); set1 << 2; QVERIFY(set1.size() == 2); QVERIFY(set1.contains(2)); set1.remove(2); QVERIFY(set1.size() == 1); QVERIFY(!set1.contains(2)); set1 << 2; QVERIFY(set1.size() == 2); QVERIFY(set1.contains(2)); } { Set<IdentityTracker> set; QCOMPARE(set.size(), 0); const int dummy = -1; IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; QCOMPARE(set.insert(id00).first->id, id00.id); QCOMPARE(set.size(), 1); QCOMPARE(set.insert(id01).first->id, id00.id); // first inserted is kept QCOMPARE(set.size(), 1); QCOMPARE(set.find(searchKey)->id, id00.id); } }
void ParticlesEditorSceneModelHelper::RemoveExcessiveNodesFromSceneGraph(EffectParticleEditorNode* node, Entity* effectRootNode) { // Some Particle Emitters were removed, update the tree. Set<Entity*> entitiesInParticleEditor; Set<Entity*> entitiesInSceneGraph; BuildEntitiesSets(node, effectRootNode, entitiesInParticleEditor, entitiesInSceneGraph); // Now compare these two lists and remove the excessive ones. for (Set<Entity*>::iterator iter = entitiesInParticleEditor.begin(); iter != entitiesInParticleEditor.end(); iter ++) { if (entitiesInSceneGraph.find(*iter) == entitiesInSceneGraph.end()) { ParticlesEditorController::Instance()->RemoveParticleEmitterNode(*iter); } } }
Provenance::Set* Provenance::descendants(const Set& roots) { Set open = roots; Set* closed = new Set(); while (!open.empty()) { const Provenance* n = *(open.begin()); const Set& c = n->children(); for (const Provenance* s : c) { // If s isn't in closed set, put it in open if (closed->find(s) == closed->end()) open.insert(s); } open.erase(n); closed->insert(n); } return closed; }
/* adds a new Complex element to the array but only if element doesn't already exist */ Set operator+ (const Complex& lhs, Set& rhs){ //store in a third array Set temp; temp = rhs; //check to see if we go over the array length if(temp.isFull()){ temp.throwError("* Array is full. Object not added."); return rhs; } else{ if ( rhs.find(lhs) < 0 ){ //the lhs is not in the set, add it temp.array[temp.arraySize] = lhs; temp.arraySize = temp.arraySize+1; } } return temp; }
static double test_find_failure() { static unsigned const Iterations = 10000; static unsigned const Count = 1000; Set set; initialize<Set>(set); boost::timer::cpu_timer timer; double total_nanos = 0; std::vector<T> data; int found = 0; for(unsigned i = 0; i != Iterations; ++i) { data.clear(); set.clear(); Generator::generate(data, Count); for(typename std::vector<T>::const_iterator iter = data.begin(); iter != data.end(); ++iter) { set.insert(*iter); } data.clear(); Generator::generate(data, Count); timer.start(); for(typename std::vector<T>::const_iterator iter = data.begin(); iter != data.end(); ++iter) { if (set.find(*iter) != set.end()) ++found; } total_nanos += timer.elapsed().wall; } if (found == 123) // never std::cout << "yeah right\n"; return (unsigned)(total_nanos / (Iterations * Count)); }
//use union find and skew tree Graph* Tree::Kruskal(Graph* g){ Skew* C = new Skew(); Set* Cyc = new Set(g->size); int final[g->size][g->size]; int n = g->size * g->size; int count = 0; for(int i = 0; i < g->size; i++) { for(int j = 0; j < g->size; j++) { final[i][j] = 0; if(g->edges[i][j] != 0) { int cost = g->edges[i][j]; g->edges[j][i] = 0; Node* n = new Node(); n->edge[0] = i; n->edge[1] = j; n->value = cost; C->insert(n, C->root); } } } while(C->root != nullptr && count <n-1) { Node* x = C->root; C->deleteMin(C->root); int v = x->edge[0]; int w = x->edge[1]; int fv = Cyc->find(x->edge[0]); int fw = Cyc->find(x->edge[1]); if(fv != fw) { final[v][w] == 1; final[w][v] == 1; Cyc->Sunion(v, w); } }
void TestTools::set_initializerList() { Set<int> set = {1, 1, 2, 3, 4, 5}; QCOMPARE(set.count(), 5); QVERIFY(set.contains(1)); QVERIFY(set.contains(2)); QVERIFY(set.contains(3)); QVERIFY(set.contains(4)); QVERIFY(set.contains(5)); // check _which_ of the equal elements gets inserted (in the QHash/QMap case, it's the last): const Set<IdentityTracker> set2 = {{1, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}; QCOMPARE(set2.count(), 5); const int dummy = -1; const IdentityTracker searchKey = {1, dummy}; QCOMPARE(set2.find(searchKey)->id, 0); Set<int> emptySet{}; QVERIFY(emptySet.isEmpty()); Set<int> set3{{}, {}, {}}; QVERIFY(!set3.isEmpty()); }
static constexpr auto apply(Set set, Pred p) { auto x = set.find(p); return if_(p(x), hana::just(x), hana::nothing); }
boost::optional<runtime_signature> resolve_overloads(Set const& overloads, Args...) { auto match = overloads.find(runtime_signature { typeid(Args)... }); if (overloads.end() == match) return boost::none; return *match; }
static constexpr auto apply(Set set, F f) { return searchable_set([=](auto q) { return f(set.find([=](auto x) { return q(f(x)); })); }); }
int main(int argc, char *argv[]) { //start here if (argc < 2) { cout << endl << "provide a filename" << endl; return 1; } ifstream mainData; mainData.open(argv[1]); if (mainData.fail()) { cout << endl << "Can't open target file plz start over" << endl; return 1; } //create the list for webpages, also the map connects webpage names and List index map<string, WebPage> allPages; map<string, WebPage>::iterator mIt; while (!mainData.fail()) { string pName; getline(mainData, pName, '\n'); if (mainData.fail()) { break; } WebPage temPage(pName); try { allPages.insert(pair<string, WebPage>(pName, temPage)); } catch (exception& e) { cout << e.what() << endl; } } //produce incoming links for all webpages for (mIt = allPages.begin(); mIt != allPages.end(); mIt++) { Set<string>::iterator ssIt; Set<string> forAddLink = mIt->second.allOutgoingLinks(); for (ssIt = forAddLink.begin(); ssIt != forAddLink.end(); ssIt++) { allPages[*ssIt].addIncomingLink(mIt->first); } } // creating the set of all distinct words in webpages Set<string> everyWords; for (mIt = allPages.begin(); mIt != allPages.end(); mIt++) { everyWords = everyWords.setUnion(mIt->second.allWords()); } //creating the map connects each word with its related pages map<string, Set<string> > wordPageMap; Set<string>::iterator wIt; for (wIt = everyWords.begin(); wIt != everyWords.end(); wIt++) { Set<string> setToInsert; for (mIt = allPages.begin(); mIt != allPages.end(); mIt++) { Set<string> setToEva = mIt->second.allWords(); if (setToEva.find(*wIt) != setToEva.end()) { setToInsert.insert(mIt->second.filename()); } } wordPageMap.insert(pair<string, Set<string> >(*wIt, setToInsert)); } QApplication app(argc, argv); MySearch sWindow; sWindow.passIn(everyWords, wordPageMap, allPages); sWindow.show(); return app.exec(); return 0; }
void setInt() { Set<int> s; //insert assert("Set::insert()", s.insert(2).second); assert("Set::insert()", s.insert(3).second); assert("Set::insert()", s.insert(4).second); assert("Set::size()", s.size() == 3); //dupe insert Pair<Set<int>::Iterator, bool> res = s.insert(2); assert("Set::insert()", !res.second); assert("Set::insert()", res.first != s.end()); assert("Set::insert()", *res.first == 2); //find Set<int>::Iterator itr = s.find(3); assert("Set::find()", itr != s.end()); assert("Set::find()", *itr == 3); //iterate itr = s.begin(); assert("Set::begin()", itr != s.end()); assert("Set::Iterator", *itr == 2); ++itr; assert("Set::Iterator", *itr == 3); ++itr; assert("Set::Iterator", *itr == 4); ++itr; assert("Set::Iterator", itr == s.end()); //iterator --itr; assert("Set::Iterator--", itr != s.end()); itr--; itr++; itr++; assert("Set::Iterator++", itr == s.end()); itr--; assert("Set::Iterator--", itr != s.end()); //const iterator Set<int>::ConstIterator citr = s.find(3); assert("cSet::find()", citr != s.end()); assert("cSet::find()", *citr == 3); citr = s.begin(); assert("cSet::begin()", citr != s.end()); assert("cSet::Iterator", *citr == 2); ++citr; assert("cSet::Iterator", *citr == 3); ++citr; assert("cSet::Iterator", *citr == 4); ++citr; assert("cSet::Iterator", citr == s.end()); --citr; assert("cSet::Iterator--", citr != s.end()); citr--; citr++; citr++; assert("cSet::Iterator++", citr == s.end()); citr--; assert("cSet::Iterator--", citr != s.end()); //erase assert("Set::erase()", s.erase(3)); assert("Set::erase()", s.size() == 2); //copy constuctor Set<int> copy(s); assert("Set::Set(Set)", copy.size() == 2); //clear s.clear(); assert("Set::clear()", s.size() == 0); itr = s.find(4); assert("Set::clear()", itr == s.end()); assert("Set::clear()", s.begin() == s.end()); //assignment operator s = copy; assert("Set::operator=()", s.size() == 2); }
static constexpr auto apply(Set set, F f) { return make_infinite_set([=](auto q) { return f(set.find(compose(q, f))); }); }
static constexpr auto apply(Set set, Pred p) { return p(set.find(p)); }
int main(){ Set t; assert( t.size( ) == 0 ); assert( t.insert("hello") == true ); assert( t.size( ) == 1 ); assert( t.insert("how") == true ); assert( t.size( ) == 2 ); assert( t.insert("are") == true ); assert( t.size( ) == 3 ); assert( t.insert("you?") == true ); assert( t.size( ) == 4 ); assert( t.insert("all") == true ); assert( t.size( ) == 5 ); assert( t.insert("great!") == true ); assert( t.size( ) == 6 ); assert( t.insert("jello") == true ); assert( t.size( ) == 7 ); assert( t.insert("apples") == true ); assert( t.size( ) == 8 ); assert( t.insert("zoo") == true ); assert( t.size( ) == 9 ); assert( t.insert("zoo") == false ); assert( t.size( ) == 9 ); assert( t.insert("zebra") == true ); assert( t.size( ) == 10 ); assert( t.insert("zap") == true ); assert( t.size( ) == 11 ); assert( t.insert("aladdin") == true ); assert( t.size( ) == 12 ); assert( t.find("hello") == true ); assert( t.find("how") == true ); assert( t.find("are") == true ); assert( t.find("you") == false ); assert( t.find("you?") == true ); assert( t.find("all") == true ); assert( t.find("great") == false ); assert( t.find("great!") == true ); assert( t.find("jello") == true ); assert( t.find("apples!") == false ); assert( t.find("apples") == true ); assert( t.find("zoo") == true ); assert( t.find("zooz") == false ); assert( t.find("zap") == true ); assert( t.find("zebra") == true ); assert( t.find("aladdin") == true ); cout << t; t.erase( "zoo" ); t.erase( "hello" ); cout << t; Set p = t; //assert( t.size( ) == 9 ); assert( (p==t) == true ); assert( (p!=t) == false ); p.insert( "gremlin" ); assert( (p==t) == false ); assert( (p!=t) == true ); assert( (p>=t) == true ); assert( (t>=p) == false ); assert( (p<=t) == false ); assert( (t<=p) == true ); p.erase( "how" ); assert( (p>=t) == false ); cout << p << endl; Set::Iterator i; for( i = p.begin( ); i != p.end( ); i++ ) { cout << *i << " "; } cout << "\ntesting complete" << endl; }