bool diff(Set s1, Set s2) { /* iter = s1.begin(); int a = *(iter) + 1; iter = s1.end(); --iter; int b = *(iter) +1; iter = s2.begin(); int c = *(iter) - 1 ; iter = s2.end(); --iter; int d = *(iter) +1;*/ for(Set::iterator iter1 = s1.begin(); iter1 != s1.end(); ++iter1) for(Set::iterator iter2 = s2.begin(); iter2 != s2.end(); ++iter2) { int d = (*iter1) - (*iter2); d = (*iter1) > (*iter2) ? d : -d; if(d <= 1) return true; } return false; }
static Set set_difference(const Set& from, const Set& to) { Set result; std::set_difference( from.begin(), from.end() , to.begin(), to.end() , std::inserter(result, result.begin())); return result; }
void Project::startDirtyJobs() { Set<uint32_t> dirtyFiles; Map<Path, List<String> > toIndex; { MutexLocker lock(&mMutex); std::swap(dirtyFiles, mModifiedFiles); for (Set<uint32_t>::const_iterator it = dirtyFiles.begin(); it != dirtyFiles.end(); ++it) { const Set<uint32_t> deps = mDependencies.value(*it); dirtyFiles += deps; mVisitedFiles.remove(*it); mVisitedFiles -= deps; } mPendingDirtyFiles.unite(dirtyFiles); } bool indexed = false; for (Set<uint32_t>::const_iterator it = dirtyFiles.begin(); it != dirtyFiles.end(); ++it) { const SourceInformationMap::const_iterator found = mSources.find(*it); if (found != mSources.end()) { index(found->second, IndexerJob::Dirty); indexed = true; } } if (!indexed && !mPendingDirtyFiles.isEmpty()) { RTags::dirtySymbols(mSymbols, mPendingDirtyFiles); RTags::dirtySymbolNames(mSymbolNames, mPendingDirtyFiles); RTags::dirtyUsr(mUsr, mPendingDirtyFiles); mPendingDirtyFiles.clear(); } }
Set mergeSets(Set & set1, Set & set2) { Set ret; Set::iterator i, j; i = set1.begin(); j = set2.begin(); while(i != set1.end() && j != set2.end()) { if(*i < *j) { ret.push_back(*i); ++i; }else{ ret.push_back(*j); ++j; } } if(i == set1.end()){ ret.insert(ret.end(), j, set2.end()); }else{ ret.insert(ret.end(), i, set1.end()); } return ret; }
Set<Deriv> FunctionalPolynomial ::findFuncsForSummation(const Set<MultipleDeriv>& prevSet, const MultipleDeriv& currentDeriv) const { Set<Deriv> rtn; for (Set<MultipleDeriv>::const_iterator i = prevSet.begin(); i != prevSet.end(); i++) { const MultipleDeriv& mdPrev = *i; TEUCHOS_TEST_FOR_EXCEPTION(currentDeriv.size()+1 != mdPrev.size(), std::logic_error, "deriv orders must differ by 1. Found " "currentDeriv.size()=" << currentDeriv.size() << " while mdPrev.size()=" << mdPrev.size()); /* We are looking for cases where the previous multiple derivative * is equal to the current plus one *greater* element. In such cases, the * set difference will contain exactly one element, and that element * will be greater than or equal to the the upper bound of the current * set */ Set<Deriv> tmp; set_difference(mdPrev.begin(), mdPrev.end(), currentDeriv.begin(), currentDeriv.end(), inserter(tmp, tmp.begin())); if (tmp.size()==1) { const Deriv& d = *(tmp.begin()); if (currentDeriv.upper_bound(d) == currentDeriv.end()) rtn.put(d); } } return rtn; }
int main(int argc, char** argv) { typedef Array<OrderedPair<Array<MultiSet<int> >, Array<MultipleDeriv> > > CR; try { GlobalMPISession session(&argc, &argv); Expr u = new UnknownFunctionStub("u"); Expr v = new UnknownFunctionStub("v"); Expr w = new UnknownFunctionStub("w"); int nArgs = 2; MultipleDeriv md = makeDeriv(u,u); int order = md.order(); for (int l=1; l<=order; l++) { Array<int> s(l, nArgs); Array<Array<int> > distinctQ = indexCombinations(s); Set<MultiSet<int> > q; for (int p=0; p<distinctQ.size(); p++) { q.put(makeMultiSet(distinctQ[p])); } if (l > 1) cout << " + " << std::endl; for (Set<MultiSet<int> >::const_iterator i=q.begin(); i!=q.end(); i++) { const MultiSet<int>& lambda = *i; if (lambda != *(q.begin())) cout << " + " << std::endl; cout << "f_" << lambda << " * ["; for (int s=1; s<=md.order(); s++) { CR p = chainRuleTerms(s, lambda, md); bool firstTerm = true; for (CR::const_iterator j=p.begin(); j!=p.end(); j++) { if (!firstTerm) cout << "+"; firstTerm = false; Array<MultiSet<int> > K = j->first(); Array<MultipleDeriv> L = j->second(); write(md, K, L); } } cout << "]" << std::endl; } } } catch(std::exception& e) { Out::println(e.what()); } }
bool operator!=(const Set& a, const Set& b) { if( a.size( ) != b.size( ) ) return true; Set::Iterator it_a = a.begin(); Set::Iterator it_b = b.begin(); while( it_a != a.end() ){ if( *it_a != *it_b ) return true; it_a++; it_b++; } return false; }
Set<MultipleDeriv> EvaluatableExpr::setProduct(const Set<MultipleDeriv>& a, const Set<MultipleDeriv>& b) const { Set<MultipleDeriv> rtn; for (Set<MultipleDeriv>::const_iterator i=a.begin(); i!=a.end(); i++) { for (Set<MultipleDeriv>::const_iterator j=b.begin(); j!=b.end(); j++) { rtn.put(i->product(*j)); } } return rtn; }
static inline void joinCursors(SymbolMap &symbols, const Set<Location> &locations) { for (Set<Location>::const_iterator it = locations.begin(); it != locations.end(); ++it) { SymbolMap::iterator c = symbols.find(*it); if (c != symbols.end()) { CursorInfo &cursorInfo = c->second; for (Set<Location>::const_iterator innerIt = locations.begin(); innerIt != locations.end(); ++innerIt) { if (innerIt != it) cursorInfo.targets.insert(*innerIt); } // ### this is filthy, we could likely think of something better } } }
void Application::computeROC() { int numRegions=regions.size(); for(int i=0 ; i<numRegions ; ++i) { GffFeature *region=regions[i]; String chr=region->getSubstrate(); int regionID=region->getFeatureType().asInt(); Set<String>::iterator cur=factors.begin(), end=factors.end(); for(; cur!=end ; ++cur) { const String &factor=*cur; String key=factor+" "+regionID; //if(!predictions.isDefined(key)) INTERNAL_ERROR; Vector<GffFeature*> &preds=predictions[key]; key=chr+" "+factor; if(factor=="HB") key=chr+" HB1"; // ### HACK if(factor=="KR") key=chr+" KR1"; // ### HACK WigBinary *wig=wigFiles.isDefined(key) ? wigFiles[key] : NULL; if(!wig) continue; updateCounts(preds,wig,factor,region); } } computeSnSp(); }
void ListSymbolsJob::execute() { Set<String> out; std::shared_ptr<Project> proj = project(); if (proj) { if (queryFlags() & QueryMessage::IMenu) { out = imenu(proj); } else { out = listSymbols(proj); } } const bool elispList = queryFlags() & QueryMessage::ElispList; if (elispList) { write("(list", IgnoreMax|DontQuote); for (Set<String>::const_iterator it = out.begin(); it != out.end(); ++it) { write(*it); } write(")", IgnoreMax|DontQuote); } else { List<String> sorted = out.toList(); if (queryFlags() & QueryMessage::ReverseSort) { std::sort(sorted.begin(), sorted.end(), std::greater<String>()); } else { std::sort(sorted.begin(), sorted.end()); } const int count = sorted.size(); for (int i=0; i<count; ++i) { write(sorted.at(i)); } } }
DAVA::Entity * SceneHelper::CloneEntityWithMaterials(DAVA::Entity *fromNode) { Entity * newEntity = fromNode->Clone(); Vector<NMaterial *> materialInstances; EnumerateMaterialInstances(newEntity, materialInstances); Set<NMaterial *> materialParentsSet; uint32 instancesCount = materialInstances.size(); for(uint32 i = 0; i < instancesCount; ++i) materialParentsSet.insert(materialInstances[i]->GetParent()); Map<NMaterial *, NMaterial *> clonedParents; Set<NMaterial *>::const_iterator it = materialParentsSet.begin(); Set<NMaterial *>::const_iterator itEnd = materialParentsSet.end(); for(; it != itEnd; ++it) clonedParents[(*it)] = (*it)->Clone(); for(uint32 i = 0; i < instancesCount; ++i) { NMaterial * material = materialInstances[i]; NMaterial * parent = material->GetParent(); material->SetParent(clonedParents[parent]); } return newEntity; }
void Project::onJSFilesAdded() { Set<Path> jsFiles = fileManager->jsFiles(); for (Set<Path>::const_iterator it = jsFiles.begin(); it != jsFiles.end(); ++it) { index(*it); } }
static void testLexiconSet() { string lexfile; lexfile = findOnPath(LEXICON_PATH, "EnglishWords.dat"); if (lexfile == "") return; lexfile = expandPathname(lexfile); reportMessage("Reading EnglishWords.dat"); declare(Lexicon lexicon(lexfile)); reportMessage("Lexicon complete"); Vector<string> words; Lexicon::iterator iter1 = lexicon.begin(); Lexicon::iterator end1 = lexicon.end(); reportMessage("Creating word vector"); while (iter1 != end1) { words.add(*iter1++); } reportMessage("Word vector complete"); shuffle(words); reportMessage("Word vector shuffled"); reportMessage("Creating word set"); Set<string> wordSet; for (int i = 0; i < words.size(); i++) { wordSet.add(words[i]); } reportMessage("Word set complete"); iter1 = lexicon.begin(); end1 = lexicon.end(); Set<string>::iterator iter2 = wordSet.begin(); Set<string>::iterator end2 = wordSet.end(); int lexSetMatches = 0; while (iter1 != end1 && iter2 != end2) { if (*iter1++ == *iter2++) lexSetMatches++; } test(lexSetMatches, 127145); }
Set<MultipleDeriv> applyZx(const Set<MultipleDeriv>& W, const MultiIndex& x) { Set<MultipleDeriv> rtn; TEUCHOS_TEST_FOR_EXCEPTION(x.order() < 0 || x.order() > 1, std::logic_error, "invalid multiindex " << x << " in this context"); for (Set<MultipleDeriv>::const_iterator i=W.begin(); i!=W.end(); i++) { const MultipleDeriv& md = *i; TEUCHOS_TEST_FOR_EXCEPTION(md.order() != 1, std::logic_error, "Only first-order multiple functional derivatives " "should appear in this function. The derivative " << md << " is not first-order."); const Deriv& d = *(md.begin()); if (d.isFunctionalDeriv()) { /* */ TEUCHOS_TEST_FOR_EXCEPTION(!d.canBeDifferentiated(), std::logic_error, "function signature " << d << " cannot be " "differentiated further spatially"); /* accept a functional derivative if the associated function * is not identically zero */ const SymbolicFuncElement* sfe = d.symbFuncElem(); TEUCHOS_TEST_FOR_EXCEPTION(sfe==0, std::logic_error, "can't cast function in " << d << " to a SymbolicFuncElement"); if (sfe && !sfe->evalPtIsZero()) rtn.put(md); } } return rtn; }
void Set<T>::merge (const Set<T> & other) { for (Set<T>::Iterator i = other->begin(); i != other->end(); ++i) { this->add (*i); } }
Set operator&(const Set& a, const Set& b) { Set intersect; 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 ) intersect.insert( *it_a ); it_b++; } it_a++; } return intersect; }
Set<MultipleDeriv> EvaluatableExpr::setDivision(const Set<MultipleDeriv>& a, const Set<MultipleDeriv>& b) const { Set<MultipleDeriv> rtn; for (Set<MultipleDeriv>::const_iterator i=a.begin(); i!=a.end(); i++) { for (Set<MultipleDeriv>::const_iterator j=b.begin(); j!=b.end(); j++) { MultipleDeriv c = i->factorOutDeriv(*j); if (c.size() != 0) rtn.put(c); if (*i == *j) rtn.put(MultipleDeriv()); } } return rtn; }
SemanticContext::OR::OR(Ref<SemanticContext> const& a, Ref<SemanticContext> const& b) { Set operands; if (is<OR>(a)) { for (auto operand : std::dynamic_pointer_cast<OR>(a)->opnds) { operands.insert(operand); } } else { operands.insert(a); } if (is<OR>(b)) { for (auto operand : std::dynamic_pointer_cast<OR>(b)->opnds) { operands.insert(operand); } } else { operands.insert(b); } std::vector<Ref<PrecedencePredicate>> precedencePredicates = filterPrecedencePredicates(operands); if (!precedencePredicates.empty()) { // interested in the transition with the highest precedence auto predicate = [](Ref<PrecedencePredicate> const& a, Ref<PrecedencePredicate> const& b) { return a->precedence < b->precedence; }; auto reduced = std::max_element(precedencePredicates.begin(), precedencePredicates.end(), predicate); operands.insert(*reduced); } std::copy(operands.begin(), operands.end(), std::back_inserter(opnds)); }
void transaction_pool::dec(Set &set, SetIterator &it, boost::mutex &mutex) { Set del_these; { boost::mutex::scoped_lock lock(mutex); for(it = set.begin(); it != set.end(); it++) { (*it)->transaction_stop_when--; if ((*it)->transaction_stop_when == 0) { (*it)->run(); if ((*it)->transaction_status == ONGOING) del_these.insert(*it); } if ((*it)->ack_requestor_status == ONGOING) { (*it)->retransmission_when--; if ((*it)->retransmission_when == 0) { (*it)->ack_requestor(); (*it)->run(); } } if ((*it)->transaction_status != ONGOING) del_these.insert(*it); } } // delete finished transactions for (it = del_these.begin(); it != del_these.end(); it++) del(*it); }
void printSetS(const Set<string> & toPrint) { Set<string>::iterator it; for (it = toPrint.begin(); it != toPrint.end(); it++) { cout << *it << endl; } cout << endl; }
VS calc( VS s ) { Set S; for ( VS::iterator it_i = s.begin(); it_i != s.end(); ++ it_i ) { string a = *it_i; string b = rotate(a); cout << a << ", " << b << endl; if ( ! is_valid(a) ) { if ( is_valid(b) ) { S.insert(b); } } else if ( ! is_valid(b) ) { if ( is_valid(a) ) { S.insert(a); } } else { if ( S.count(a) ) S.insert(b); else if ( S.count(b) ) S.insert(a); else S.insert(min(a, b)); } } if ( S.size() != s.size() ) return VS(); VS res(S.begin(), S.end()); return res; }
static void save(BinaryBuffer& bb, const Set& m) { size_t s = m.size(); diy::save(bb, s); for (typename std::set<T>::const_iterator it = m.begin(); it != m.end(); ++it) diy::save(bb, *it); }
Set<MultipleDeriv> applyTx(const Set<MultipleDeriv>& s, const MultiIndex& x) { Set<MultipleDeriv> rtn; for (Set<MultipleDeriv>::const_iterator i=s.begin(); i!=s.end(); i++) { const MultipleDeriv& md = *i; for (MultipleDeriv::const_iterator j=md.begin(); j!=md.end(); j++) { const Deriv& d = *j; if (d.isFunctionalDeriv()) { const MultiIndex& mi = d.opOnFunc().mi(); MultiIndex miNew = mi+x; if (miNew.isValid()) { Deriv dNew = d.derivWrtMultiIndex(miNew); MultipleDeriv mdNew = md; mdNew.erase(mdNew.find(d)); mdNew.put(dNew); rtn.put(mdNew); } } } } return rtn; }
void FileManager::onRecurseJobFinished(const Set<Path> &paths) { bool emitJS = false; { std::lock_guard<std::mutex> lock(mMutex); // ### is this needed now? Set<Path> old; std::swap(mJSFiles, old); std::shared_ptr<Project> project = mProject.lock(); assert(project); FilesMap &map = project->files(); map.clear(); mWatcher.clear(); for (Set<Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) { if (it->endsWith(".js")) mJSFiles.insert(*it); const Path parent = it->parentDir(); if (parent.isEmpty()) { error() << "Got empty parent here" << *it; continue; } assert(!parent.isEmpty()); Set<String> &dir = map[parent]; if (dir.isEmpty()) watch(parent); dir.insert(it->fileName()); } assert(!map.contains("")); emitJS = old != mJSFiles; } if (emitJS) mJSFilesChanged(); }
void FileSystemWatcher::processChanges(unsigned int types) { assert(types); struct { const Type type; Signal<std::function<void(const Path&)> > &signal; Set<Path> &paths; } signals[] = { { Add, mAdded, mAddedPaths }, { Remove, mRemoved, mRemovedPaths }, { Modified, mModified, mModifiedPaths } }; const unsigned int count = sizeof(signals) / sizeof(signals[0]); for (unsigned i=0; i<count; ++i) { if (types & signals[i].type) { Set<Path> p; { std::lock_guard<std::mutex> lock(mMutex); std::swap(p, signals[i].paths); } for (Set<Path>::const_iterator it = p.begin(); it != p.end(); ++it) { signals[i].signal(*it); } } } }
void BasicGroupBigraph::groupProteinsBy(const Array<Set> & groups) { // remake the list of names and then remake the graph with them collapsed groupProtNames = Array<Array<string> > (groups.size()); originalN = Array<Counter> (groups.size()); int k; for (k=0; k<groups.size(); k++) { groupProtNames[k] = proteinsToPSMs.names[ groups[k] ]; // all possible sets of proteins can be present for a group if(!gbUseProteinGroupLevelInference){ originalN[k] = Counter( groups[k].size() ); }else{ // each group is either present or absent originalN[k] = Counter( 1 ); } } // remove all but the first of each group from the graph for (k=0; k<groups.size(); k++) { Set reps = groups[k].without( Set::SingletonSet(groups[k][0]) ); for (Set::Iterator iter = reps.begin(); iter != reps.end(); iter++) { disconnectProtein(*iter); } } reindex(); }
static inline void removeOutputs() { std::lock_guard<std::mutex> lock(sOutputsMutex); for (Set<LogOutput*>::const_iterator it = sOutputs.begin(); it != sOutputs.end(); ++it) delete *it; sOutputs.clear(); }
inline int lis () { Set s; pair <Iterator, bool> p_it; Iterator &it = p_it.first; int n = seq.size(); Pair p; int &i = p.second; for( i = 0; i < n; ++i ) { p.first = seq[i].first; p_it = s.insert( p ); if( it != s.begin() ) { Iterator it_aux = it; --it_aux; seq[i].second = (*it_aux).second; } if(p_it.second && ++it != s.end() ) s.erase( it ); } p = *( s.rbegin() ); do { p = seq[i]; l.push_front (p.first); } while (i != NP); return s.size(); }
void Set<T>::addToThisFrom(const Set<T>& other) { for (Set<T>::Iterator i = other.begin(); i != other.end(); ++i) { this->add (*i); } }