当前位置: 首页>>代码示例>>C++>>正文


C++ QSet::reserve方法代码示例

本文整理汇总了C++中QSet::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QSet::reserve方法的具体用法?C++ QSet::reserve怎么用?C++ QSet::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSet的用法示例。


在下文中一共展示了QSet::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: squeeze

void tst_QSet::squeeze()
{
    QSet<int> set;
    int n = set.capacity();
    QVERIFY(n == 0);

    set.reserve(1000);
    QVERIFY(set.capacity() >= 1000);

    set.squeeze();
    QVERIFY(set.capacity() < 100);

    for (int i = 0; i < 500; ++i)
        set.insert(i);
    QVERIFY(set.capacity() >= 500 && set.capacity() < 10000);

    set.reserve(50000);
    QVERIFY(set.capacity() >= 50000);

    set.squeeze();
    QVERIFY(set.capacity() < 500);

    set.remove(499);
    QVERIFY(set.capacity() < 500);

    set.insert(499);
    QVERIFY(set.capacity() >= 500);

    for (int i = 0; i < 500; ++i)
        set.remove(i);
    set.squeeze();
    QVERIFY(set.capacity() < 100);
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: classes

/*!
    Returns the list of classes of this element.
*/
QStringList QWebElement::classes() const
{
    if (!hasAttribute(QLatin1String("class")))
        return QStringList();

    QStringList classes =  attribute(QLatin1String("class")).simplified().split(QLatin1Char(' '), QString::SkipEmptyParts);
#if QT_VERSION >= 0x040500
    classes.removeDuplicates();
#else
    int n = classes.size();
    int j = 0;
    QSet<QString> seen;
    seen.reserve(n);
    for (int i = 0; i < n; ++i) {
        const QString& s = classes.at(i);
        if (seen.contains(s))
            continue;
        seen.insert(s);
        if (j != i)
            classes[j] = s;
        ++j;
    }
    if (n != j)
        classes.erase(classes.begin() + j, classes.end());
#endif
    return classes;
}
开发者ID:dzip,项目名称:webkit,代码行数:30,代码来源:qwebelement.cpp

示例3: mergeArraysOfStrings

    bool mergeArraysOfStrings(const QJsonArray &arrayFrom, QJsonArray &arrayTo) {
        QJsonArray arrayMerged;

        QSet<QString> commonValues;
        commonValues.reserve(arrayTo.size() + arrayFrom.size());

        int i = 0;
        int sizeTo = arrayTo.size();
        for (i = 0; i < sizeTo; ++i) {
            Q_ASSERT(arrayTo[i].type() == QJsonValue::String);
            commonValues.insert(arrayTo[i].toString());
        }

        int sizeFrom = arrayFrom.size();
        for (i = 0; i < sizeFrom; ++i) {
            Q_ASSERT(arrayFrom[i].type() == QJsonValue::String);
            commonValues.insert(arrayFrom[i].toString());
        }

        QSet<QString>::iterator begin = commonValues.begin();
        QSet<QString>::iterator end = commonValues.end();

        for (QSet<QString>::iterator it = begin; it != end; ++it) {
            arrayMerged.append(*it);
        }

        arrayTo = arrayMerged;
        return true;
    }
开发者ID:RostaTasha,项目名称:xpiks,代码行数:29,代码来源:jsonhelper.cpp

示例4: getCurrentBlockId

QSet<REntity::Id> RMemoryStorage::queryAllEntities(bool undone, bool allBlocks) {
    QSet<REntity::Id> result;
    result.reserve(entityMap.count());
    RBlock::Id currentBlock = getCurrentBlockId();
    QHash<REntity::Id, QSharedPointer<REntity> >::iterator it;
    for (it = entityMap.begin(); it != entityMap.end(); ++it) {
        QSharedPointer<REntity> e = *it;
        if (e.isNull()) {
            continue;
        }
        if (!undone && e->isUndone()) {
            continue;
        }
        if (!allBlocks && e->getBlockId() != currentBlock) {
            continue;
        }
//        if (!includeFrozenLayers) {
//            RLayer::Id layerId = e->getLayerId();
//            QSharedPointer<RLayer> layer = queryLayer(layerId);
//            if (!layer.isNull()) {
//                if (layer->isFrozen()) {
//                    continue;
//                }
//            }
//        }
//        if (!e.isNull() && (undone || !e->isUndone()) && (allBlocks
//                || e->getBlockId() == currentBlock)) {
//            result.insert(e->getId());
//        }
        result.insert(e->getId());
    }
    return result;
}
开发者ID:lukeandrew,项目名称:qcad,代码行数:33,代码来源:RMemoryStorage.cpp

示例5: statusReady

void ProjectChangesModel::statusReady(KJob* job)
{
    VcsJob* status=static_cast<VcsJob*>(job);

    QList<QVariant> states = status->fetchResults().toList();
    IProject* project = job->property("project").value<KDevelop::IProject*>();
    if(!project)
        return;

    QSet<QUrl> foundUrls;
    foundUrls.reserve(states.size());
    foreach(const QVariant& state, states) {
        const VcsStatusInfo st = state.value<VcsStatusInfo>();
        foundUrls += st.url();

        updateState(project, st);
    }

    QStandardItem* itProject = projectItem(project);

    IBasicVersionControl::RecursionMode mode = IBasicVersionControl::RecursionMode(job->property("mode").toInt());
    QSet<QUrl> uncertainUrls = urls(itProject).toSet().subtract(foundUrls);
    QList<QUrl> sourceUrls = job->property("urls").value<QList<QUrl>>();
    foreach(const QUrl& url, sourceUrls) {
        if(url.isLocalFile() && QDir(url.toLocalFile()).exists()) {
            foreach(const QUrl& currentUrl, uncertainUrls) {
                if((mode == IBasicVersionControl::NonRecursive && currentUrl.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) == url.adjusted(QUrl::StripTrailingSlash))
                    || (mode == IBasicVersionControl::Recursive && url.isParentOf(currentUrl))
                ) {
                    removeUrl(currentUrl);
                }
            }
        }
    }
开发者ID:KDE,项目名称:kdevplatform,代码行数:34,代码来源:projectchangesmodel.cpp

示例6: readShortcutsFromSettings

void VConfigManager::readShortcutsFromSettings()
{
    const QString group("shortcuts");

    m_shortcuts.clear();
    m_shortcuts = readShortcutsFromSettings(defaultSettings, group);

    // Update default settings according to user settings.
    QHash<QString, QString> userShortcuts = readShortcutsFromSettings(userSettings,
                                                                      group);
    QSet<QString> matched;
    matched.reserve(m_shortcuts.size());
    for (auto it = userShortcuts.begin(); it != userShortcuts.end(); ++it) {
        auto defaultIt = m_shortcuts.find(it.key());
        if (defaultIt != m_shortcuts.end()) {
            QString sequence = it.value().trimmed();
            if (sequence != defaultIt.value()) {
                if (isValidKeySequence(sequence)) {
                    matched.insert(it.key());
                    *defaultIt = sequence;
                }
            } else {
                matched.insert(it.key());
            }
        }
    }

    if (matched.size() < m_shortcuts.size()) {
        qDebug() << "override user shortcuts settings using default settings";
        writeShortcutsToSettings(userSettings, group, m_shortcuts);
    }
}
开发者ID:liunianbanbo,项目名称:vnote,代码行数:32,代码来源:vconfigmanager.cpp

示例7:

QSet<int> KeyTracker::pressedKeys() const
{
	QSet<int> keys;
	keys.reserve(d->keys.size());
	
	for (int key : d->keys)
		keys << (key + d->modifiers);
	
	return keys;
}
开发者ID:pasberth,项目名称:PaintField,代码行数:10,代码来源:keytracker.cpp

示例8:

QStringList
ProjectPackager::getAudioFiles()
{
    QStringList list;

    // get the Composition from the document, so we can iterate through it
    Composition *comp = &m_doc->getComposition();

    // We don't particularly care about tracks here, so just iterate through the
    // entire Composition to find the audio segments and get the associated
    // file IDs from which to obtain a list of actual files.  This could
    // conceivably pick up audio segments that are residing on MIDI tracks and
    // wouldn't otherwise be functional, but the important thing is to never
    // miss a single file that has any chance of being worth preserving.
    for (Composition::iterator i = comp->begin(); i != comp->end(); ++i) {
        if ((*i)->getType() == Segment::Audio) {

            AudioFileManager *manager = &m_doc->getAudioFileManager();

            unsigned int id = (*i)->getAudioFileId();

            AudioFile *file = manager->getAudioFile(id);

            // some polite sanity checking to avoid possible crashes
            if (!file) continue;

            list << file->getFilename();
        }
    }

    // QStringList::removeDuplicates() would have been easy, but it's only in Qt
    // 4.5.0 and up.  So here's the algorithm from Qt 4.5.0, courtesy of (and
    // originally Copyright 2009) Nokia

    QStringList *that = &list;

    int n = that->size();
    int j = 0;
    QSet<QString> seen;
    seen.reserve(n);
    for (int i = 0; i < n; ++i) {
        const QString &s = that->at(i);
        if (seen.contains(s))
            continue;
        seen.insert(s);
        if (j != i)
            (*that)[j] = s;
        ++j;
    }
    if (n != j)
        that->erase(that->begin() + j, that->end());
//    return n - j;

    return list;
}
开发者ID:tedfelix,项目名称:rosegarden,代码行数:55,代码来源:ProjectPackager.cpp

示例9: TWordDiffEntryList_removeDuplicates

static int TWordDiffEntryList_removeDuplicates(TWordDiffEntryList &aList)
{
	int n = aList.size();
	int j = 0;
	QSet<QString> seen;
	seen.reserve(n);
	for (int i = 0; i < n; ++i) {
		const CWordDiffEntry &s = aList.at(i);
		if (seen.contains(s.word())) continue;
		seen.insert(s.word());
		if (j != i) aList[j] = s;
		++j;
	}
	if (n != j) aList.erase(aList.begin() + j, aList.end());
	return (n - j);
}
开发者ID:dewhisna,项目名称:KingJamesPureBibleSearch,代码行数:16,代码来源:main.cpp

示例10: findEdgesIncidentToPoint

QSet<Edge> DelaunayTriangulation::
    findEdgesIncidentToPoint(Point p) {

    QSet<Edge> incidentEdges;
    incidentEdges.reserve(3);
    QSetIterator<Edge> it(edges);

    while (it.hasNext()) {
        Edge curEdge = it.next();
        if (curEdge.getEndPoint() == p || curEdge.getStartPoint() == p) {
            incidentEdges.insert(curEdge);
        }
    }

    return incidentEdges;
}
开发者ID:ViktoryiaYatskova,项目名称:Diploma,代码行数:16,代码来源:delaunaytriangulation.cpp

示例11: isError_data

void tst_QScriptValue::isError_data()
{
    QTest::addColumn<QScriptValue>("value");
    QTest::addColumn<bool>("expected");
    if (m_engine)
        delete m_engine;
    m_engine = new QScriptEngine();
    QSet<QString> expectedValue;
    expectedValue.reserve(6);
    for (uint i = 0; i < 6; ++i)
        expectedValue.insert(isError_array[i]);
    for (uint i = 0; i < 135; ++i) {
        QPair<QString, QScriptValue> testcase = initScriptValues(i);
        QTest::newRow(testcase.first.toAscii().constData()) << testcase.second << expectedValue.contains(testcase.first);
    }
}
开发者ID:AngelkPetkov,项目名称:tijscore,代码行数:16,代码来源:tst_qscriptvalue_generated_istype.cpp

示例12: removeDuplicates

void ProStringList::removeDuplicates()
{
    int n = size();
    int j = 0;
    QSet<ProString> seen;
    seen.reserve(n);
    for (int i = 0; i < n; ++i) {
        const ProString &s = at(i);
        if (seen.contains(s))
            continue;
        seen.insert(s);
        if (j != i)
            (*this)[j] = s;
        ++j;
    }
    if (n != j)
        erase(begin() + j, end());
}
开发者ID:anchowee,项目名称:QtCreator,代码行数:18,代码来源:proitems.cpp

示例13: QStringList_removeDuplicates

/*!
    \fn int QStringList::removeDuplicates()

    \since  4.5

    This function removes duplicate entries from a list.
    The entries do not have to be sorted. They will retain their
    original order.

    Returns the number of removed entries.
*/
int QtPrivate::QStringList_removeDuplicates(QStringList *that)
{
    int n = that->size();
    int j = 0;
    QSet<QString> seen;
    seen.reserve(n);
    for (int i = 0; i < n; ++i) {
        const QString &s = that->at(i);
        if (seen.contains(s))
            continue;
        seen.insert(s);
        if (j != i)
            (*that)[j] = s;
        ++j;
    }
    if (n != j)
        that->erase(that->begin() + j, that->end());
    return n - j;
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例14:

QSet<QString> ElementAvailableFN::allXSLTInstructions()
{
    enum
    {
        StringSetSize = 27
    };

    QSet<QString> retval;
    retval.reserve(StringSetSize);

    /* Alphabetically. */
    retval.insert(QLatin1String("analyze-string"));
    retval.insert(QLatin1String("apply-imports"));
    retval.insert(QLatin1String("apply-templates"));
    retval.insert(QLatin1String("attribute"));
    retval.insert(QLatin1String("attribute-set"));
    retval.insert(QLatin1String("call-template"));
    retval.insert(QLatin1String("character-map"));
    retval.insert(QLatin1String("choose"));
    retval.insert(QLatin1String("comment"));
    retval.insert(QLatin1String("copy"));
    retval.insert(QLatin1String("copy-of"));
    retval.insert(QLatin1String("document"));
    retval.insert(QLatin1String("element"));
    retval.insert(QLatin1String("fallback"));
    retval.insert(QLatin1String("for-each"));
    retval.insert(QLatin1String("for-each-group"));
    retval.insert(QLatin1String("if"));
    retval.insert(QLatin1String("message"));
    retval.insert(QLatin1String("namespace"));
    retval.insert(QLatin1String("next-match"));
    retval.insert(QLatin1String("number"));
    retval.insert(QLatin1String("perform-sort"));
    retval.insert(QLatin1String("processing-instruction"));
    retval.insert(QLatin1String("result-document"));
    retval.insert(QLatin1String("sequence"));
    retval.insert(QLatin1String("text"));
    retval.insert(QLatin1String("variable"));

    Q_ASSERT(retval.count() == StringSetSize);
    return retval;
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:42,代码来源:qelementavailablefn.cpp

示例15: QStringList_removeDuplicates

/*!
    \fn int QStringList::removeDuplicates()

    \since  4.5

    This function removes duplicate entries from a list.
    The entries do not have to be sorted. They will retain their
    original order.

    Returns the number of removed entries.
*/
int QtPrivate::QStringList_removeDuplicates(QStringList *that)
{
    int n = that->size();
    int j = 0;
    QSet<QString> seen;
    seen.reserve(n);
    int setSize = 0;
    for (int i = 0; i < n; ++i) {
        const QString &s = that->at(i);
        seen.insert(s);
        if (setSize == seen.size()) // unchanged size => was already seen
            continue;
        ++setSize;
        if (j != i)
            that->swap(i, j);
        ++j;
    }
    if (n != j)
        that->erase(that->begin() + j, that->end());
    return n - j;
}
开发者ID:AlexSoehn,项目名称:qt-base-deb,代码行数:32,代码来源:qstringlist.cpp


注:本文中的QSet::reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。