void test_hash_set() { HashSet h; h.insert(225); h.insert(225+SEED); assert(h.find(225)); assert(h.find(225+SEED)); }
int main() { HashSet dict; dict.insert("DAMP"); dict.insert("LIKE"); dict.insert("LIMP"); dict.insert("DAME"); dict.insert("DAKP"); dict.insert("LIME"); Transform("DAMP", "LIKE", dict); dict.insert("LAMP"); Transform("DAMP", "LIKE", dict); dict.insert("DIKE"); Transform("DAMP", "DIKE", dict); return 0; }
int main() { HashSet<int> s; cout << s[1].getKeyCount() << endl; s.insert(1); cout << s[1].getKeyCount() << endl; s.insert(1); cout << s[1].getKeyCount() << endl; cout << s[1].getKeyCount() << endl; s.insert(2); s.insert(3); cout << s[1].getKey() << endl; cout << s[1].getKeyCount() << endl; cout << s.check(3) << endl; }
void perform_join(int range_bound) { struct list_item { int pos = 0; vector<pair<int, int>> ids; }; HashMap<int, list_item> index; for (int k = range_bound; k < (int)records.size(); k++) { int count = 0; int prefix_length = get_prefix_length(tokens[k]); HashSet<int> occurances; for (const pair<int, int> &token : tokens[k]) { if (count++ >= prefix_length) break; if (token.first <= widow_bound) continue; auto &item = index[token.first]; auto &list = item.ids; while (item.pos < (int)list.size() && records[list[item.pos].first].length() + THRESHOLD < records[k].length()) item.pos++; for (int t = item.pos; t < (int)list.size(); t++) { int cand = list[t].first; if (cand != k && abs(list[t].second - token.second) <= THRESHOLD) { occurances.insert(cand); } } list.emplace_back(k, token.second); } for (int cand : occurances) { cand_num++; int real_overlap = overlap(k, cand); int test_value = real_overlap + THRESHOLD * Q; if (test_value < (int)tokens[k].size() || test_value < (int)tokens[cand].size()) continue; if (edit_distance(records[k], records[cand], THRESHOLD) <= THRESHOLD) { res_num++; } } if ((int)records[k].length() - THRESHOLD >= (THRESHOLD + 1) * Q) continue; int bound = lower_bound(records.begin(), records.end(), (int)records[k].length() - THRESHOLD, [](const string &s, int value) { return (int)s.length() < value; }) - records.begin(); while (bound != range_bound) { cand_num++; if (edit_distance(records[k], records[bound], THRESHOLD) <= THRESHOLD) { res_num++; } bound++; } } }
HashSet<Label> PropertyMap::getKeys() const { HashSet<Label> keys; for (auto iter = m_properties.begin(); iter != m_properties.end(); ++iter) keys.insert(iter->first); return keys; }
int main() { FILE *in, *out; in = fopen("humble.in", "r"); out = fopen("humble.out", "w"); int k, n, popcount = 0, primes[110] = {0}; fscanf(in, "%d %d", &k, &n); for(int i=0; i < k; i++) fscanf(in, "%d", &primes[i]); priority_queue<ll> minheap; priority_queue<ll> maxheap; HashSet seen; for(int i=0; i < k; i++) { minheap.push(-primes[i]); maxheap.push(primes[i]); } while(minheap.size()) { ll current = -minheap.top(); minheap.pop(); popcount++; if (popcount == n) { fprintf(out, "%lld\n", current); return 0; } for(int i=0; i < k; i++) { ll number = current * primes[i]; if (maxheap.size() < n && !seen.find(number)) { minheap.push(-number); maxheap.push(number); seen.insert(number); } else if (number < maxheap.top() && !seen.find(number)) { maxheap.pop(); minheap.push(-number); maxheap.push(number); seen.insert(number); } } } return 0; }
QList<Hash>& operator>>( QList<Hash>& list, HashSet& vector ) { for ( int i = 0, nSize = list.size(); i < nSize; ++i ) { vector.insert( list[i] ); } return list; }
HashSet<String> Result::getOutputIds() { HashSet<String> ret; HashMap<String, vector<ResultData> >::Iterator iter = result_data_.begin(); for (; iter != result_data_.end(); iter++) { vector<ResultData>::iterator iter2 = (iter->second).begin(); for (; iter2 != (iter->second).end(); iter2++) { ResultData rd = *iter2; ret.insert(rd.getLigandConformationId()); } } return ret; }
int _tmain(int argc, _TCHAR* argv[]) { HashSet myHashSet; for (int i=0; i<30; i++) { myHashSet.insert(i); } cout<<"The HashSet:"<<endl; myHashSet.printHashSet(cout); cout<<"The number 0 exists?"<<"\t"<<myHashSet.exists(0)<<endl; cout<<"The number 30 exists?"<<"\t"<<myHashSet.exists(30)<<endl; cout<<"insert 40:"<<myHashSet.insert(40)<<endl; myHashSet.printHashSet(cout); cout<<"insert 10:"<<myHashSet.insert(10)<<endl; myHashSet.printHashSet(cout); cout<<"delete 40:"<<myHashSet.remove(40)<<endl; myHashSet.printHashSet(cout); cout<<"delete 50:"<<myHashSet.remove(50)<<endl; myHashSet.printHashSet(cout); return 0; }
void groupingElementTest() { csvsqldb::Variants first; first.push_back(csvsqldb::Variant(4711)); first.push_back(csvsqldb::Variant("Fürstenberg")); csvsqldb::Variants second; second.push_back(csvsqldb::Variant(815)); second.push_back(csvsqldb::Variant("Fürstenberg")); csvsqldb::GroupingElement elementLeft(first); csvsqldb::GroupingElement elementRight(second); MPF_TEST_ASSERT(elementLeft.getHash() != elementRight.getHash()); MPF_TEST_ASSERT(!(elementLeft == elementRight)); MPF_TEST_ASSERT(elementLeft == elementLeft); typedef std::unordered_set<csvsqldb::GroupingElement> HashSet; HashSet hashSet; hashSet.insert(elementLeft); hashSet.insert(elementRight); MPF_TEST_ASSERTEQUAL(2UL, hashSet.size()); HashSet::const_iterator found = hashSet.find(elementRight); MPF_TEST_ASSERT(found != hashSet.end()); csvsqldb::Variants third; third.push_back(csvsqldb::Variant(815)); third.push_back(csvsqldb::Variant("Fürstenberg")); csvsqldb::GroupingElement compareElement(third); found = hashSet.find(compareElement); MPF_TEST_ASSERT(found != hashSet.end()); }
int64_t countPairs(HashSet &hs, int mask) { hs.reset(); int64_t ans = 0; for (int i = 0; i < N; i++) { int m = mask; pair<int, int> key = make_pair(0, 0); while (m) { int x = __builtin_ctz(m); hashf(key, W[i][x]); m -= (1<<x); } if (hs.contains(key)) ans += hs[key]++; else hs.insert(key); } return ans; }
int main(int argc,char* argv[]) { assert(argc==3); std::string path = (argc > 1) ? argv[1] : "/usr/share/dict/words"; // Read dictionary into memory std::ifstream f(path); dict.insert(dict.end(),std::istreambuf_iterator<char>(f),std::istreambuf_iterator<char>()); // Read dictionary static HashSet entries(300000); for (const char* start=dict.data(), *limit=dict.data()+dict.size(); start!=limit; ++start) { const char* wordStart=start; for (; start != limit && *start != '\n'; ++start); const char* wordEnd=start; entries.insert(StringRef(wordStart,std::distance(wordStart,wordEnd))); } entries.write(argv[2]); }
int main() { ifstream cin("hashuri.in"); ofstream cout("hashuri.out"); HashSet<int> H; int N; cin >> N; for (int i = 0; i < N; ++i) { int type, value; cin >> type>> value; if (type == 1) H.insert(value); if (type == 2) H.erase(value); if (type == 3) cout << bool(*H.find(value) != 0) << "\n"; } }
// Dictionary merging/editing. // literalRE: // - true: behave like dictionary::merge, i.e. add regexps just like // any other key. // - false : interpret wildcard as a rule for items to be matched. bool merge ( dictionary& thisDict, const dictionary& mergeDict, const bool literalRE ) { static bool wildCardInMergeDict = false; bool changed = false; // Save current (non-wildcard) keys before adding items. HashSet<word> thisKeysSet; { List<keyType> keys = thisDict.keys(false); forAll(keys, i) { thisKeysSet.insert(keys[i]); } }
void switchableNotImplemented( const word &methodName, const dictionary &dict ) { static HashSet<fileName> notImplementedWarningAlreadyIssued; word switchName="ignore_unimplemented_"+methodName; bool warn=dict.lookupOrDefault<bool>(switchName,false); if(warn) { fileName fullName=dict.name()+"_"+methodName; if(!notImplementedWarningAlreadyIssued.found(fullName)) { Info << endl; WarningIn("switchableNotImpleemnted") << "The method " << methodName << " isn't properly " << " implemented (at least that is what the developer " << " thinks. You chose to ignore this for " << dict.name() << endl << "The consequences are your responsibility " << "(but if you're lucky everything will be OK)" << endl << "This warning will only appear once" << nl << endl; notImplementedWarningAlreadyIssued.insert(fullName); } } else { Info << endl << endl; Info << "It seems that the method " << methodName << " is not properly implemented (neither in the class or " << " any appropriate subclasses)." << endl << "If you think that it should work anyway add the entry" << nl << nl << switchName << " true;" << nl << endl << "to the dictionary " << dict.name() << " and we will " << "go on. Alternativly properly implement the method." << nl << nl << "Anyway: I'll go die now"; Info << endl << endl; notImplemented(methodName); } }
bool Foam::fileFormats::NASsurfaceFormat<Face>::read ( const fileName& filename ) { const bool mustTriangulate = this->isTri(); this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "Cannot read file " << filename << exit(FatalError); } // Nastran index of points DynamicList<label> pointId; DynamicList<point> dynPoints; DynamicList<Face> dynFaces; DynamicList<label> dynZones; DynamicList<label> dynSizes; Map<label> lookup; // assume the types are not intermixed // leave faces that didn't have a group in 0 bool sorted = true; label zoneI = 0; // Name for face group Map<word> nameLookup; // Ansa tags. Denoted by $ANSA_NAME. // These will appear just before the first use of a type. // We read them and store the PSHELL types which are used to name // the zones. label ansaId = -1; word ansaType, ansaName; // A single warning per unrecognized command HashSet<word> unhandledCmd; while (is.good()) { string line; is.getLine(line); // Ansa extension if (line.substr(0, 10) == "$ANSA_NAME") { string::size_type sem0 = line.find (';', 0); string::size_type sem1 = line.find (';', sem0+1); string::size_type sem2 = line.find (';', sem1+1); if ( sem0 != string::npos && sem1 != string::npos && sem2 != string::npos ) { ansaId = readLabel ( IStringStream(line.substr(sem0+1, sem1-sem0-1))() ); ansaType = line.substr(sem1+1, sem2-sem1-1); string rawName; is.getLine(rawName); if (rawName[rawName.size()-1] == '\r') { rawName = rawName.substr(1, rawName.size()-2); } else { rawName = rawName.substr(1, rawName.size()-1); } string::stripInvalid<word>(rawName); ansaName = rawName; // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType // << " name " << ansaName << endl; } } // Hypermesh extension // $HMNAME COMP 1"partName" if ( line.substr(0, 12) == "$HMNAME COMP" && line.find ('"') != string::npos ) { label groupId = readLabel ( IStringStream(line.substr(16, 16))() ); IStringStream lineStream(line.substr(32)); string rawName; lineStream >> rawName; string::stripInvalid<word>(rawName); word groupName(rawName); nameLookup.insert(groupId, groupName); // Info<< "group " << groupId << " => " << groupName << endl; } // Skip empty or comment if (line.empty() || line[0] == '$') { continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72] == '+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CTRIA3") { triFace fTri; label groupId = readLabel(IStringStream(line.substr(16,8))()); fTri[0] = readLabel(IStringStream(line.substr(24,8))()); fTri[1] = readLabel(IStringStream(line.substr(32,8))()); fTri[2] = readLabel(IStringStream(line.substr(40,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } dynFaces.append(fTri); dynZones.append(zoneI); dynSizes[zoneI]++; } else if (cmd == "CQUAD4") { face fQuad(4); UList<label>& f = static_cast<UList<label>&>(fQuad); label groupId = readLabel(IStringStream(line.substr(16,8))()); fQuad[0] = readLabel(IStringStream(line.substr(24,8))()); fQuad[1] = readLabel(IStringStream(line.substr(32,8))()); fQuad[2] = readLabel(IStringStream(line.substr(40,8))()); fQuad[3] = readLabel(IStringStream(line.substr(48,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } if (mustTriangulate) { dynFaces.append(triFace(f[0], f[1], f[2])); dynFaces.append(triFace(f[0], f[2], f[3])); dynZones.append(zoneI); dynZones.append(zoneI); dynSizes[zoneI] += 2; } else { dynFaces.append(Face(f)); dynZones.append(zoneI); dynSizes[zoneI]++; } } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) format" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "PSHELL") { // pshell type for zone names with the Ansa extension label groupId = readLabel(IStringStream(line.substr(8,8))()); if (groupId == ansaId && ansaType == "PSHELL") { nameLookup.insert(ansaId, ansaName); // Info<< "group " << groupId << " => " << ansaName << endl; } } else if (unhandledCmd.insert(cmd)) { Info<< "Unhandled Nastran command " << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << endl; } }
bool triSurface::readNAS(const fileName& fName) { IFstream is(fName); if (!is.good()) { FatalErrorIn("triSurface::readNAS(const fileName&)") << "Cannot read file " << fName << exit(FatalError); } // coordinates of point DynamicList<point> points; // Nastran index of point DynamicList<label> indices; // Faces in terms of Nastran point indices DynamicList<labelledTri> faces; // From face group to patch Map<label> groupToPatch; label nPatches = 0; // Name for face group Map<word> groupToName; // Ansa tags. Denoted by $ANSA_NAME. These will appear just before the // first use of a type. We read them and store the pshell types which // are used to name the patches. label ansaId = -1; word ansaType; string ansaName; // A single warning per unrecognized command HashSet<word> unhandledCmd; while (is.good()) { string line; is.getLine(line); // Ansa extension if (line.substr(0, 10) == "$ANSA_NAME") { string::size_type sem0 = line.find (';', 0); string::size_type sem1 = line.find (';', sem0+1); string::size_type sem2 = line.find (';', sem1+1); if ( sem0 != string::npos && sem1 != string::npos && sem2 != string::npos ) { ansaId = readLabel ( IStringStream(line.substr(sem0+1, sem1-sem0-1))() ); ansaType = line.substr(sem1+1, sem2-sem1-1); string nameString; is.getLine(ansaName); if (ansaName[ansaName.size()-1] == '\r') { ansaName = ansaName.substr(1, ansaName.size()-2); } else { ansaName = ansaName.substr(1, ansaName.size()-1); } // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType // << " name " << ansaName << endl; } } // Hypermesh extension // $HMNAME COMP 1"partName" if ( line.substr(0, 12) == "$HMNAME COMP" && line.find ('"') != string::npos ) { label groupId = readLabel ( IStringStream(line.substr(16, 16))() ); IStringStream lineStream(line.substr(32)); string rawName; lineStream >> rawName; groupToName.insert(groupId, string::validate<word>(rawName)); Info<< "group " << groupId << " => " << rawName << endl; } if (line.empty() || line[0] == '$') { // Skip empty or comment continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72]=='+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CTRIA3") { label groupId = readLabel(IStringStream(line.substr(16,8))()); label a = readLabel(IStringStream(line.substr(24,8))()); label b = readLabel(IStringStream(line.substr(32,8))()); label c = readLabel(IStringStream(line.substr(40,8))()); // Convert group into patch Map<label>::const_iterator iter = groupToPatch.find(groupId); label patchI; if (iter == groupToPatch.end()) { patchI = nPatches++; groupToPatch.insert(groupId, patchI); Info<< "patch " << patchI << " => group " << groupId << endl; } else { patchI = iter(); } faces.append(labelledTri(a, b, c, patchI)); } else if (cmd == "CQUAD4") { label groupId = readLabel(IStringStream(line.substr(16,8))()); label a = readLabel(IStringStream(line.substr(24,8))()); label b = readLabel(IStringStream(line.substr(32,8))()); label c = readLabel(IStringStream(line.substr(40,8))()); label d = readLabel(IStringStream(line.substr(48,8))()); // Convert group into patch Map<label>::const_iterator iter = groupToPatch.find(groupId); label patchI; if (iter == groupToPatch.end()) { patchI = nPatches++; groupToPatch.insert(groupId, patchI); Info<< "patch " << patchI << " => group " << groupId << endl; } else { patchI = iter(); } faces.append(labelledTri(a, b, c, patchI)); faces.append(labelledTri(c, d, a, patchI)); } else if (cmd == "PSHELL") { // Read shell type since group gives patchnames label groupId = readLabel(IStringStream(line.substr(8,8))()); if (groupId == ansaId && ansaType == "PSHELL") { groupToName.insert(groupId, string::validate<word>(ansaName)); Info<< "group " << groupId << " => " << ansaName << endl; } } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); indices.append(index); points.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorIn("triSurface::readNAS(const fileName&)") << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) output" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); indices.append(index); points.append(point(x, y, z)); } else if (unhandledCmd.insert(cmd)) { Info<< "Unhandled Nastran command " << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << endl; } }
// // Main // int somaticVariantFiltersMain(int argc, char** argv) { parseSomaticVariantFiltersOptions(argc, argv); Timer* pTimer = new Timer(PROGRAM_IDENT); // Load Reference ReadTable refTable(opt::referenceFile, SRF_NO_VALIDATION); refTable.indexReadsByID(); // Load BAMs BamTools::BamReader* pTumorBamReader = new BamTools::BamReader; pTumorBamReader->Open(opt::tumorBamFile); pTumorBamReader->LocateIndex(); assert(pTumorBamReader->HasIndex()); BamTools::BamReader* pNormalBamReader = new BamTools::BamReader; pNormalBamReader->Open(opt::normalBamFile); pNormalBamReader->LocateIndex(); assert(pNormalBamReader->HasIndex()); // Track duplicated variants HashSet<std::string> duplicateHash; std::ifstream input(opt::vcfFile.c_str()); std::string line; while(getline(input, line)) { if(line.empty()) continue; if(line[0] == '#') { std::cout << line << "\n"; continue; } // parse record VCFRecord record(line); if(record.isMultiAllelic()) { std::cerr << "Error: multi-allelic VCF found, please run vcfbreakmulti\n"; exit(EXIT_FAILURE); } // Check if we've seen this variant already std::string key = makeVariantKey(record); if(duplicateHash.find(key) != duplicateHash.end()) continue; else duplicateHash.insert(key); if(opt::verbose > 0) { std::stringstream ss; ss << "Variant: " << record << "\n"; fprintf(stderr, "===============================================\n%s", ss.str().c_str()); } StringStringHash tagHash; makeTagHash(record, tagHash); StringVector fail_reasons; int hplen = 0; if(!getTagValue(tagHash, "HPLen", hplen)) hplen = calculateHomopolymerLength(record, &refTable); if(hplen > opt::maxHPLen) fail_reasons.push_back("Homopolymer"); double dust = 0.0f; if(!getTagValue(tagHash, "Dust", dust)) dust = HapgenUtil::calculateDustScoreAtPosition(record.refName, record.refPosition, &refTable); if(dust > opt::maxDust) fail_reasons.push_back("LowComplexity"); double af; if(getTagValue(tagHash, "AF", af) && af < opt::minAF) fail_reasons.push_back("LowAlleleFrequency"); int varDP; if(getTagValue(tagHash, "VarDP", varDP) && varDP < opt::minVarDP) fail_reasons.push_back("LowVarDP"); double strandBias; if(getTagValue(tagHash, "SB", strandBias) && strandBias >= opt::maxStrandBias) fail_reasons.push_back("StrandBias"); CoverageStats tumor_stats = getVariantCoverage(pTumorBamReader, record, &refTable); CoverageStats normal_stats = getVariantCoverage(pNormalBamReader, record, &refTable); if(opt::verbose > 0) { fprintf(stderr, "Tumor: [%zu %zu]\n", tumor_stats.n_total_reads, tumor_stats.n_evidence_reads); fprintf(stderr, "Normal: [%zu %zu]\n", normal_stats.n_total_reads, normal_stats.n_evidence_reads); } if(normal_stats.n_evidence_reads > opt::maxNormalReads) fail_reasons.push_back("NormalEvidence"); if(normal_stats.n_total_reads < opt::minNormalDepth) fail_reasons.push_back("LowNormalDepth"); if(!tumor_stats.snv_evidence_quals.empty()) { double median_quality = median(tumor_stats.snv_evidence_quals); if(median_quality < opt::minMedianQuality) fail_reasons.push_back("LowQuality"); } if(tumor_stats.median_mapping_quality < opt::minMedianQuality) fail_reasons.push_back("LowMappingQuality"); if(!fail_reasons.empty()) { if(record.passStr != "PASS" && record.passStr != ".") fail_reasons.insert(fail_reasons.begin(), record.passStr); std::stringstream strss; std::copy(fail_reasons.begin(), fail_reasons.end(), std::ostream_iterator<std::string>(strss, ";")); record.passStr = strss.str(); record.passStr.erase(record.passStr.size() - 1); // erase trailing ; } std::cout << record << "\n"; } // Cleanup delete pTumorBamReader; delete pNormalBamReader; delete pTimer; return 0; }
int main(int argc, char *argv[]) { argList::validOptions.insert("noFlipMap", ""); # include "addRegionOption.H" # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" bool noFlipMap = args.optionFound("noFlipMap"); // Get times list instantList Times = runTime.times(); label startTime = Times.size()-1; label endTime = Times.size(); // check -time and -latestTime options # include "checkTimeOption.H" runTime.setTime(Times[startTime], startTime); # include "createNamedPolyMesh.H" // Search for list of objects for the time of the mesh IOobjectList objects ( mesh, mesh.pointsInstance(), polyMesh::meshSubDir/"sets" ); Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets" << nl << "Found : " << objects.names() << nl << endl; IOobjectList pointObjects(objects.lookupClass(pointSet::typeName)); //Pout<< "pointSets:" << pointObjects.names() << endl; for ( IOobjectList::const_iterator iter = pointObjects.begin(); iter != pointObjects.end(); ++iter ) { // Not in memory. Load it. pointSet set(*iter()); SortableList<label> pointLabels(set.toc()); label zoneID = mesh.pointZones().findZoneID(set.name()); if (zoneID == -1) { Info<< "Adding set " << set.name() << " as a pointZone." << endl; label sz = mesh.pointZones().size(); mesh.pointZones().setSize(sz+1); mesh.pointZones().set ( sz, new pointZone ( set.name(), //name pointLabels, //addressing sz, //index mesh.pointZones() //pointZoneMesh ) ); mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().instance() = mesh.facesInstance(); } else { Info<< "Overwriting contents of existing pointZone " << zoneID << " with that of set " << set.name() << "." << endl; mesh.pointZones()[zoneID] = pointLabels; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().instance() = mesh.facesInstance(); } } IOobjectList faceObjects(objects.lookupClass(faceSet::typeName)); HashSet<word> slaveCellSets; //Pout<< "faceSets:" << faceObjects.names() << endl; for ( IOobjectList::const_iterator iter = faceObjects.begin(); iter != faceObjects.end(); ++iter ) { // Not in memory. Load it. faceSet set(*iter()); SortableList<label> faceLabels(set.toc()); DynamicList<label> addressing(set.size()); DynamicList<bool> flipMap(set.size()); if (!noFlipMap) { word setName(set.name() + "SlaveCells"); Info<< "Trying to load cellSet " << setName << " to find out the slave side of the zone." << nl << "If you do not care about the flipMap" << " (i.e. do not use the sideness)" << nl << "use the -noFlipMap command line option." << endl; // Load corresponding cells cellSet cells(mesh, setName); // Store setName to exclude from cellZones further on slaveCellSets.insert(setName); forAll(faceLabels, i) { label faceI = faceLabels[i]; bool flip = false; if (mesh.isInternalFace(faceI)) { if ( cells.found(mesh.faceOwner()[faceI]) && !cells.found(mesh.faceNeighbour()[faceI]) ) { flip = false; } else if ( !cells.found(mesh.faceOwner()[faceI]) && cells.found(mesh.faceNeighbour()[faceI]) ) { flip = true; } else { FatalErrorIn(args.executable()) << "One of owner or neighbour of internal face " << faceI << " should be in cellSet " << cells.name() << " to be able to determine orientation." << endl << "Face:" << faceI << " own:" << mesh.faceOwner()[faceI] << " OwnInCellSet:" << cells.found(mesh.faceOwner()[faceI]) << " nei:" << mesh.faceNeighbour()[faceI] << " NeiInCellSet:" << cells.found(mesh.faceNeighbour()[faceI]) << abort(FatalError); } } else { if (cells.found(mesh.faceOwner()[faceI])) { flip = false; } else { flip = true; } } addressing.append(faceI); flipMap.append(flip); } }
void performanceTest_int() { const int N = 1; std::vector<int> textArray; { for (int i = 0; i < (1 << 18); ++i) textArray.push_back(rand() % 4096); } std::vector<int> rArray; for (int i = 0; i < (1 << 20); ++i) rArray.push_back(rand() % textArray.size()); std::vector<int> res; { Timer _t("HashSet"); for (int _ = 0; _ < N; ++_) { HashSet<int> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res.empty()) { res.assign(s.begin(), s.end()); } } } std::sort(res.begin(), res.end()); cout << res.size() << endl; std::vector<int> res2; { Timer _t("set"); for (int _ = 0; _ < N; ++_) { std::set<int> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res2.empty()) { res2.assign(s.begin(), s.end()); } } } std::sort(res2.begin(), res2.end()); cout << (res == res2) << endl; { Timer _t("hash_set"); for (int _ = 0; _ < N; ++_) { stdext::hash_set<int> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res2.empty()) { res2.assign(s.begin(), s.end()); } } } std::sort(res2.begin(), res2.end()); cout << (res == res2) << endl; }
void syntaxTest_HashSet() { { HashSet<int> s; s.insert(1); s.insert(2); s.insert(1); s.insert(3); s.insert(2); assert(s.size() == 3); s.erase(3); assert(s.size() == 2); s.erase(3); assert(s.size() == 2); } { int a[5] = {1, 3, 2, 4, 1}; HashSet<int> s(a, a + 5); assert(s.size() == 4); { HashSet<int> s2(s); assert(s2.size() == 4); } { HashSet<int> s2; assert(s2.empty()); s2 = s; assert(s2.size() == 4); assert(!s2.empty()); assert(s2.contain(3)); assert(s2.count(2) == 1); assert(s2 == s); assert(!(s2 != s)); } } { std::vector<int> v(5, 0); HashSet<int> s; s.insert(v.begin(), v.end()); assert(s.size() == 1); assert(s.find(1) == s.end()); assert(s.find(0) != s.end()); assert(s.find(0) == s.begin()); s.erase(s.find(0)); assert(s.empty()); s.insert(5); assert(!s.empty()); s.clear(); assert(s.empty()); HashSet<int> s2; s2.insert(5); std::swap(s, s2); assert(s2.empty()); assert(s.find(5) != s.end()); } { int a[4] = {1,2, 3, 1}; const HashSet<int> s(a, a + 4); HashSet<int> b; for (HashSet<int>::ConstIterator iter = s.begin(); iter != s.end(); ++iter) { b.insert(*iter); } assert(b.size() == 3); } }
void performanceTest_string() { const int N = 1; std::vector<std::string> textArray; { std::ifstream fi("1.txt"); for (std::string s; getline(fi, s);) textArray.push_back(s); } std::vector<int> rArray; for (int i = 0; i < (1 << 20); ++i) rArray.push_back(rand() % textArray.size()); std::vector<std::string> res; { Timer _t("HashSet"); for (int _ = 0; _ < N; ++_) { HashSet<std::string> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res.empty()) { res.assign(s.begin(), s.end()); } } } std::sort(res.begin(), res.end()); cout << res.size() << endl; std::vector<std::string> res2; { Timer _t("set"); for (int _ = 0; _ < N; ++_) { std::set<std::string> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res2.empty()) { res2.assign(s.begin(), s.end()); } } } std::sort(res2.begin(), res2.end()); cout << (res == res2) << endl; { Timer _t("hash_set"); for (int _ = 0; _ < N; ++_) { stdext::hash_set<std::string> s; for (int i = 0; i < textArray.size(); ++i) s.insert(textArray[i]); for (int i = 0; i < rArray.size(); ++i) { s.erase(textArray[rArray[i]]); } for (int i = 0; i < rArray.size(); ++i) { if (rArray[i] & 3) { s.erase(textArray[rArray[i]]); } else { s.insert(textArray[rArray[i]]); } } if (res2.empty()) { res2.assign(s.begin(), s.end()); } } } std::sort(res2.begin(), res2.end()); cout << (res == res2) << endl; }