TEST(StringSetTest, IntersectionOfTwoStrings) { // Tests the intersection of two set, including only strings occuring // in both sets. StringSet first, second; first.Add("First string."); first.Add("Second string."); first.Add("Third string."); second.Add("First string."); second.Add("Second string."); StringSet intersection = first.Intersection(second); EXPECT_TRUE(intersection.Contains("First string.")); EXPECT_TRUE(intersection.Contains("Second string.")); EXPECT_FALSE(intersection.Contains("Third string.")); EXPECT_EQ(2, intersection.Count()); }
static StringVector getAllSymbolsUsedByThisKernel( const std::string& kernelName, ir::Module* module) { auto kernel = module->kernels().find(kernelName); if(kernel == module->kernels().end()) return StringVector(); StringSet encountered; for(auto block = kernel->second->cfg()->begin(); block != kernel->second->cfg()->end(); ++block) { for(auto instruction = block->instructions.begin(); instruction != block->instructions.end(); ++instruction) { typedef std::vector<ir::PTXOperand*> OperandVector; auto ptx = static_cast<ir::PTXInstruction*>(*instruction); OperandVector operands; operands.push_back(&ptx->a); operands.push_back(&ptx->b); operands.push_back(&ptx->pg); operands.push_back(&ptx->pq); operands.push_back(&ptx->d); if(ptx->opcode != ir::PTXInstruction::Call) { operands.push_back(&ptx->c); } for(auto operand = operands.begin(); operand != operands.end(); ++operand) { if((*operand)->addressMode != ir::PTXOperand::Address && (*operand)->addressMode != ir::PTXOperand::FunctionName) { continue; } encountered.insert((*operand)->identifier); } } } return StringVector(encountered.begin(), encountered.end()); }
// Generate Transactions and Taxonomy // void gen_taxrules(TaxPar &par) { Taxonomy *tax; StringSet *lits; StringSetIter *patterns; Transaction *trans; poisson_distribution<LINT> tlen(par.tlen - 1); ofstream data_fp; ofstream pat_fp; ofstream tax_fp; data_fp.open(data_file, ios::trunc); pat_fp.open(pat_file, ios::trunc); tax_fp.open(tax_file, ios::trunc); if (data_fp.fail() || pat_fp.fail() || tax_fp.fail()) { cerr << "Error opening output file" << endl; exit(1); } // generate taxonomy and write it to file tax = new Taxonomy(par.nitems, par.nroots, par.fanout, par.depth_ratio); if (par.ascii) tax->write_asc(tax_fp); else tax->write(tax_fp); lits = new StringSet(par.nitems, par.lits, tax); par.write(pat_fp); lits->display(pat_fp); patterns = new StringSetIter(*lits); for (LINT i = 0; i < par.ntrans; i ++) { trans = mk_tran(*patterns, tlen(generator) + 1, tax); if (par.ascii) trans->write_asc(data_fp); else trans->write(data_fp); delete trans; delete trans; } data_fp.close(); pat_fp.close(); tax_fp.close(); }
static bool ValidateCheckPrefixes() { StringSet<> PrefixSet; for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end(); I != E; ++I) { StringRef Prefix(*I); if (!PrefixSet.insert(Prefix)) return false; if (!ValidateCheckPrefix(Prefix)) return false; } return true; }
void String::display(ofstream &fp, StringSet &lits, LINT prob_comp) { LINT i, j; StringP lstr; int flag = 0; fp << setw(6) << prob_comp * prob << " " << setw(6) << conf << " "; for(i = 0; i < nitems; i++) { fp << "("; lstr = lits.get_pat(items[i]); for (j = 0; j < lstr->nitems; j++) { if ( flag == 0 ) { fp << lstr->items[j]; flag = 1; } else fp << "," << lstr->items[j]; } flag = 0; fp << ")"; } fp << endl; return; }
void Put(const Slice& key, const Slice& value) { std::string str(key.data(), key.size()); std::string v(value.data(), value.size()); dels.erase(str); inserts[str] = v; }
void SBWorkspace::queueTargets(const StringSet& targetNames, const StringSet& configNames) { BuildSettings bs(NULL); bool isInteractive = bs.getValue("VSIMPORTER_INTERACTIVE") == "YES"; // Get the specified targets PotentialTargetsVec selectedTargets; if (isInteractive) { // Query the user to select targets to be queued selectTargets(selectedTargets); } else if (targetNames.empty()) { // Queue up all targets getAllTargets(selectedTargets); } else { // Try to find matching targets by name for (auto targetName : targetNames) { TargetProjectPair targetKV = findTargetWithName(targetName); if (targetKV.first) { selectedTargets.push_back(targetKV); } } } // Queue targets for (auto targetKV : selectedTargets) { SBTarget* target = targetKV.second->queueTarget(targetKV.first, &configNames); // Mark target as having been explicitly queued up if (target) { target->markExplicit(); } } }
//字符串拆分 void split(const string& in, const string delimiter, StringSet& out) { string::size_type cur = 0; string::size_type next = 0; next = in.find(delimiter, cur); while(next != std::string::npos) { out.insert(in.substr(cur, next - cur)); cur = next + 1; next = in.find(delimiter, cur); } out.insert(in.substr(cur)); }
static void writeProjectItem(const ProjectItem* item, const StringMap& params, const StringSet& urlSchemes) { if (!item) return; // Open input file auto inMode = item->replaceParams ? ios::in : ios::binary; ifstream ifs(item->inFile.c_str(), inMode); if (!ifs.is_open()) { SBLog::warning() << "Failed to open " << item->inFile << " for reading." << std::endl; return; } // Open output file ofstream ofs; auto outMode = item->replaceParams ? ios::out : ios::binary; openOutputFileStream(ofs, item->outFile, outMode); if (item->replaceParams) { // Expand input line by line and write it out std::string line; while (std::getline(ifs, line)) { expandString(line, params); ofs << line << std::endl; } } else { // Copy the file contents ofs << ifs.rdbuf(); } if (!urlSchemes.empty() && isAppxManifestFileName(item->inFile)) { ofs.close(); insertUrlSchemes(item->outFile, urlSchemes); } }
static bool can_finalize_function(StringRef F, SmallSet<Module*, 16> &known) { if (incomplete_fname.find(F) != incomplete_fname.end()) return false; Module *M = module_for_fname.lookup(F); if (M && known.insert(M).second) { for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { Function *F = &*I; if (F->isDeclaration() && !isIntrinsicFunction(F)) { if (!can_finalize_function(F->getName(), known)) return false; } } } return true; }
bool write_stringset(SerialOut &out, const StringSet &list) { auto len = static_cast<uint32_t>(list.size()); out.out_.Write((const char*)&len, sizeof(len)); for (auto &s : list) out <= s; return out.out_; }
void processItemPair(StringSet & as, ConfigListBuilder & lb, substring src, substring dst) { item_analysis a_src = analyzeItem(src); item_analysis a_dst = analyzeItem(dst); as.insert(a_src.item_name); as.insert(a_dst.item_name); generateLinkSection(lb, a_src.item_name, a_dst.item_name, a_src.right_properties.merge(a_dst.left_properties)); }
static bool mustPreserve(ld_plugin_symbol &Sym) { if (Sym.resolution == LDPR_PREVAILING_DEF) return true; if (Sym.resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) return CannotBeHidden.count(Sym.name); return false; }
void Exif::TreeView::setSelectedExif( const StringSet& selected ) { for ( QTreeWidgetItemIterator it( this ); *it; ++it ) { bool on = selected.contains( (*it)->text(1) ); (*it)->setCheckState(0,on ? Qt::Checked : Qt::Unchecked ); } }
static bool mustPreserve(const claimed_file &F, int i) { if (F.syms[i].resolution == LDPR_PREVAILING_DEF) return true; if (F.syms[i].resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) return CannotBeHidden.count(F.syms[i].name); return false; }
bool match(StringRef Query) const { if (Strings.count(Query)) return true; if (Trigrams.isDefinitelyOut(Query)) return false; return RegEx && RegEx->match(Query); }
// this takes ownership of a module after code emission is complete // and will add it to the execution engine when required (by jl_finalize_function) void jl_finalize_module(Module *m, bool shadow) { #if !defined(USE_ORCJIT) jl_globalPM->run(*m); #endif // record the function names that are part of this Module // so it can be added to the JIT when needed for (Module::iterator I = m->begin(), E = m->end(); I != E; ++I) { Function *F = &*I; if (!F->isDeclaration()) { bool known = incomplete_fname.erase(F->getName()); (void)known; // TODO: assert(known); // llvmcall gets this wrong module_for_fname[F->getName()] = m; } } #if defined(USE_ORCJIT) || defined(USE_MCJIT) // in the newer JITs, the shadow module is separate from the execution module if (shadow) jl_add_to_shadow(m); #else bool changes = jl_try_finalize(m); while (changes) { // this definitely isn't the most efficient, but it's only for the old LLVM 3.3 JIT changes = false; for (StringMap<Module*>::iterator MI = module_for_fname.begin(), ME = module_for_fname.end(); MI != ME; ++MI) { changes |= jl_try_finalize(MI->second); } } #endif }
MojErr MojDbKindState::initTokens(MojDbReq& req, const StringSet& strings) { MojAssertMutexLocked(m_lock); // load tokens MojErr err = readObj(TokensKey, m_tokensObj, m_kindEngine->kindDb(), req.txn(), m_oldTokensItem); MojErrCheck(err); // populate token vec MojUInt8 maxToken = 0; err = m_tokenVec.resize(m_tokensObj.size()); MojErrCheck(err); for (MojObject::ConstIterator i = m_tokensObj.begin(); i != m_tokensObj.end(); ++i) { MojString key = i.key(); MojInt64 value = i.value().intValue(); MojSize idx = (MojSize) (value - MojObjectWriter::TokenStartMarker); if (value < MojObjectWriter::TokenStartMarker || value >= MojUInt8Max || idx >= m_tokenVec.size()) { MojErrThrow(MojErrDbInvalidToken); } if (value > maxToken) { maxToken = (MojUInt8) value; } err = m_tokenVec.setAt(idx, key); MojErrCheck(err); } if (maxToken > 0) { m_nextToken = (MojUInt8) (maxToken + 1); } // add strings bool updated = false; for (StringSet::ConstIterator i = strings.begin(); i != strings.end(); ++i) { if (!m_tokensObj.contains(*i)) { updated = true; MojUInt8 token = 0; TokenVec tokenVec; MojObject tokenObj; err = addPropImpl(*i, false, token, tokenVec, tokenObj); MojErrCheck(err); } } if (updated) { err = writeTokens(m_tokensObj); MojErrCheck(err); } return MojErrNone; }
int StringSet::foundIn(const StringSet ss) const{ int count = 0; for (size_t i = 0; i < this->size(); ++i){ if(ss.duplicate(this->at(i))) count++; } return count; }
//////////////////////////////////////////////////////////////////////////////// // TODO: Duplicate code with reducer-shingle-threshold.cpp. Refactor into class // with virtual method call to call the emit method int main() { char value[1000], key[1000]; StringSet shingleSet; std::string prevKey; while (scanf("%s\t%s\n", key, value) != EOF) { if (prevKey != key) { emitShinglesWithDocSizes(shingleSet, prevKey); shingleSet.clear(); } shingleSet.insert(value); prevKey = key; } emitShinglesWithDocSizes(shingleSet, prevKey); return 0; }
int MMKVImpl::SMembers(DBID db, const Data& key, const StringArrayResult& members) { int err = 0; RWLockGuard<MemorySegmentManager, READ_LOCK> keylock_guard(m_segment); StringSet* set = GetObject<StringSet>(db, key, V_TYPE_SET, false, err)(); if (NULL == set || 0 != err) { return err; } StringSet::iterator it = set->begin(); while (it != set->end()) { it->ToString(members.Get()); it++; } return 0; }
//--------------------------------------------------------------------------- bool doScene( hkRootLevelContainer* container, const RCParams& params, const StringSet& options, const char* outFile ) { HkxSceneToolParams sceneParams; sceneParams.bVerbose = params.bVerbose; sceneParams.bMergeMeshesByMaterial = true; sceneParams.outFile = outFile; std::string stem(outFile); stem = stem.substr(0, stem.find_last_of("\\/")+1); std::string outDir; for (StringSet::const_iterator it = options.begin(); it != options.end(); ++it) { if (strstr(it->c_str(), "--outputDir")) { outDir = it->substr(it->find_first_of('=')+1); break; } } if (!outDir.length()) { outDir = ".\\"; } // first make sure they exist _mkdir(stem.c_str()); _mkdir((stem+outDir).c_str()); sceneParams.outDir = outDir.c_str(); HkxSceneTool sceneTool(sceneParams); sceneTool.initialize(container); if (sceneTool.process()) { } return true; }
void Serializer::appendOnlineUserFlags(const OnlineUserPtr& aUser, StringSet& flags_) noexcept { if (aUser->getIdentity().isAway()) { flags_.insert("away"); } if (aUser->getIdentity().isOp()) { flags_.insert("op"); } if (aUser->getIdentity().isBot() || aUser->getIdentity().isHub()) { flags_.insert("bot"); } if (aUser->isHidden()) { flags_.insert("hidden"); } if (aUser->supportsCCPM()) { flags_.insert("ccpm"); } auto cm = aUser->getIdentity().getConnectMode(); if (!aUser->getUser()->isNMDC() && (cm == Identity::MODE_NOCONNECT_PASSIVE || cm == Identity::MODE_NOCONNECT_IP || cm == Identity::MODE_UNDEFINED)) { flags_.insert("noconnect"); } else if (!aUser->getIdentity().isTcpActive(aUser->getClient())) { flags_.insert("passive"); } }
void World::Destroy() { theSound.Shutdown(); theInput.Destroy(); FinalizeTextureLoading(); PythonScriptingModule::Finalize(); delete _physicsDebugDraw; StringSet subs = theSwitchboard.GetSubscriptionsFor(this); StringSet::iterator it = subs.begin(); while (it != subs.end()) { theSwitchboard.UnsubscribeFrom(this, *it); ++it; } }
int main() { StringSet myList; string myString; while(getline(cin, myString)) { if (myString == "#") { break; } myList.insert(myString); } cout << myList.size() << endl; cout << myList; return 0; }
const void VCProject::getPlatforms(StringSet& ret) const { for (auto configKV : m_configurations) { const PlatformMap& platforms = configKV.second->getPlatforms(); for (auto platformKV : platforms) { ret.insert(platformKV.first); } } }
static bool isSubset(const StringSet& subset, const StringSet& superset) { for (auto e : subset) { if (superset.count(e) == 0) { return false; } } return true; }
void EntityInfoTable::updateComponentsNames(StringSet & victimSet, const EntityInfoTable * victimInfoTable) const { // Si la tabla que le hemos pasado no apunta a NULL añadiremos los nombres de componentes que tenga. if(victimInfoTable) { // Copiamos el conjunto de nombres de componentes de la tabla. victimSet.insert(victimInfoTable->_components.begin(), victimInfoTable->_components.end()); // Y después añadimos al conjunto los nombres de componentes de la tabla padre. updateComponentsNames(victimSet, victimInfoTable->_superInfoTable); } }
// ** Films::similarTo SimilarFilmsArray Films::similarTo( const StringSet& oids, int count ) const { struct SimilarFilmIntersection { SimilarFilm m_film; float m_similarity; int m_counter; SimilarFilmIntersection( const SimilarFilm& film = SimilarFilm() ) : m_film( film ), m_similarity( 0.0f ), m_counter( 0 ) {} }; std::map<std::string, SimilarFilmIntersection> filmIntersection; SimilarFilmsArray result; for( StringSet::const_iterator i = oids.begin(), end = oids.end(); i != end; ++i ) { SimilarFilmsArray items = similarTo( *i ); for( SimilarFilmsArray::const_iterator j = items.begin(), jend = items.end(); j != jend; ++j ) { const SimilarFilm& similar = *j; std::string key = j->m_film.m_id.toString(); if( filmIntersection.count( key ) == 0 ) { filmIntersection[key] = similar; } filmIntersection[key].m_similarity += j->m_similarity; filmIntersection[key].m_counter++; } } for( auto i = filmIntersection.begin(), end = filmIntersection.end(); i != end; ++i ) { if( i->second.m_counter == ( int )oids.size() ) { float similarity = i->second.m_similarity / i->second.m_counter; result.push_back( SimilarFilm( i->second.m_film.m_film, similarity, 0.0f, qualityFromRange( similarity, m_similarityQuartiles ) ) ); } } std::sort( result.begin(), result.end(), SimilarFilm::sortBySimilarity ); if( count ) { result.resize( std::min( count, ( int )result.size() ) ); } return result; }
bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) { ValueToValueMapTy VMap; Module *M = CloneModule(BD.getProgram(), VMap).release(); outs() << "Checking for crash with only these named metadata nodes:"; unsigned NumPrint = std::min<size_t>(NamedMDs.size(), 10); for (unsigned i = 0, e = NumPrint; i != e; ++i) outs() << " " << NamedMDs[i]; if (NumPrint < NamedMDs.size()) outs() << "... <" << NamedMDs.size() << " total>"; outs() << ": "; // Make a StringMap for faster lookup StringSet<> Names; for (const std::string &Name : NamedMDs) Names.insert(Name); // First collect all the metadata to delete in a vector, then // delete them all at once to avoid invalidating the iterator std::vector<NamedMDNode *> ToDelete; ToDelete.reserve(M->named_metadata_size() - Names.size()); for (auto &NamedMD : M->named_metadata()) // Always keep a nonempty llvm.dbg.cu because the Verifier would complain. if (!Names.count(NamedMD.getName()) && (!(NamedMD.getName() == "llvm.dbg.cu" && NamedMD.getNumOperands() > 0))) ToDelete.push_back(&NamedMD); for (auto *NamedMD : ToDelete) NamedMD->eraseFromParent(); // Verify that this is still valid. legacy::PassManager Passes; Passes.add(createVerifierPass(/*FatalErrors=*/false)); Passes.run(*M); // Try running on the hacked up program... if (TestFn(BD, M)) { BD.setNewProgram(M); // It crashed, keep the trimmed version... return true; } delete M; // It didn't crash, try something else. return false; }