Exemple #1
0
void test_hash_set() {
    HashSet h;
    h.insert(225);
    h.insert(225+SEED);
    assert(h.find(225));
    assert(h.find(225+SEED));
}
void RadioButtonGroup::remove(HTMLInputElement* button)
{
    ASSERT(button->isRadioButton());
    HashSet<HTMLInputElement*>::iterator it = m_members.find(button);
    if (it == m_members.end())
        return;

    bool wasValid = isValid();
    m_members.remove(it);
    if (button->isRequired()) {
        ASSERT(m_requiredCount);
        --m_requiredCount;
    }
    if (m_checkedButton) {
        button->setNeedsStyleRecalc();
        if (m_checkedButton == button) {
            m_checkedButton = nullptr;
            setNeedsStyleRecalcForAllButtons();
        }
    }

    if (m_members.isEmpty()) {
        ASSERT(!m_requiredCount);
        ASSERT(!m_checkedButton);
    } else if (wasValid != isValid())
        updateValidityForAllButtons();
    if (!wasValid) {
        // A radio button not in a group is always valid. We need to make it
        // valid only if the group was invalid.
        button->updateValidity();
    }
}
Exemple #3
0
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;
}
Exemple #4
0
TEST(WTF_HashSet, UniquePtrKey_FindUsingRawPointer)
{
    HashSet<std::unique_ptr<int>> set;

    auto uniquePtr = std::make_unique<int>(5);
    int* ptr = uniquePtr.get();
    set.add(WTF::move(uniquePtr));

    auto it = set.find(ptr);
    ASSERT_TRUE(it != set.end());
    EXPECT_EQ(ptr, it->get());
    EXPECT_EQ(5, *it->get());
}
Exemple #5
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());
    }
Exemple #6
0
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";
    }
}
void SVGDocumentExtensions::removeAllTargetReferencesForElement(SVGElement* referencingElement)
{
    Vector<SVGElement*> toBeRemoved;

    HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > >::iterator end = m_elementDependencies.end();
    for (HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > >::iterator it = m_elementDependencies.begin(); it != end; ++it) {
        SVGElement* referencedElement = it->key;
        HashSet<SVGElement*>* referencingElements = it->value.get();
        HashSet<SVGElement*>::iterator setIt = referencingElements->find(referencingElement);
        if (setIt == referencingElements->end())
            continue;

        referencingElements->remove(setIt);
        if (referencingElements->isEmpty())
            toBeRemoved.append(referencedElement);
    }

    m_elementDependencies.removeAll(toBeRemoved);
}
 /// Allows finding a match inside the deduplication hash (used for exact matching), precomputed hash
 bool find(boost::string_ref word, uint32_t hashValue) const { return h.find(word, hashValue); }
 /// Allows finding a match inside the deduplication hash (used for exact matching)
 bool find(boost::string_ref word) const { return h.find(word); }
Exemple #10
0
CHECK((std::pair<Iterator, bool> insert(const ValueType& item) throw()))
	HashSet<int> hs;
	TEST_EQUAL(hs.getSize(), 0)
	hs.insert(0);
	TEST_EQUAL(hs.getSize(), 1)
	hs.insert(1);
	TEST_EQUAL(hs.getSize(), 2)
	hs.insert(1);
	TEST_EQUAL(hs.getSize(), 2)
	hs.insert(2);
	TEST_EQUAL(hs.getSize(), 3)
RESULT

CHECK(Iterator find(const Key& key) throw())
	HashSet<int> hs;
	TEST_EQUAL((hs.find(0) == hs.end()), true)
	TEST_EQUAL((hs.find(1) == hs.end()), true)
	TEST_EQUAL((hs.find(2) == hs.end()), true)
	TEST_EQUAL((hs.find(-2) == hs.end()), true)
	hs.insert(0);
	TEST_EQUAL((hs.find(0) == hs.end()), false)
	TEST_EQUAL((hs.find(1) == hs.end()), true)
	TEST_EQUAL((hs.find(2) == hs.end()), true)
	TEST_EQUAL((hs.find(-2) == hs.end()), true)
	hs.insert(1);
	TEST_EQUAL((hs.find(0) == hs.end()), false)
	TEST_EQUAL((hs.find(1) == hs.end()), false)
	TEST_EQUAL((hs.find(2) == hs.end()), true)
	TEST_EQUAL((hs.find(-2) == hs.end()), true)
RESULT
//
// 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;
}
Exemple #12
0
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);
    }
}