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


C++ Hash::begin方法代码示例

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


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

示例1: extract_hash

void extract_hash(Hash const& hash){
    Class hash_class(Hash().class_of());
    Class array_class(Array().class_of());
    Class string_class(String().class_of());
    for(Hash::const_iterator i=hash.begin(), iend=hash.end(); i!=iend; ++i){
        std::cout << i->key << ":\n";
        Object obj(i->value);
        if(obj.is_instance_of(hash_class))
            extract_hash(obj);
        else if(obj.is_instance_of(array_class))
            extract_array(obj);
        else if(obj.is_instance_of(string_class))
            std::cout << i->value << "\n";
        else
            std::cout << i->value << "\n";
    }
}
开发者ID:Bloodknight,项目名称:cubeat,代码行数:17,代码来源:rice_yml.cpp

示例2: mode

IntPair mode(const int *values, unsigned int size) {
  Hash::iterator it;
  Hash hash;
  for (int i = 0; i < size; i++) {
    it = hash.find(values[i]);
    if(it == hash.end()) {
      hash.insert( std::make_pair(values[i], 1));
    } else {
      it->second += 1;
    }
  }
  unsigned int counts = 0;
  Hash::iterator found;
  for (it = hash.begin(); it != hash.end(); ++it) {
    if(it->second > counts) {
      counts = it->second;
      found = it;
    }
  }
  return *found;
}
开发者ID:javang,项目名称:mlearning,代码行数:21,代码来源:mode.cpp

示例3: while

int
da_build_dump(da_build_t* builder, char* tmpfile, FILE* lexfile)
{
    Hash::iterator i, last;
    Hash* entries = builder->entries;
    char** keys = new char*[entries->size()];
    size_t* lens = new size_t[entries->size()];
    long* vals = new long[entries->size()];
    int size = 0;
    std::vector<long> lex_indices;

    std::cerr << entries->size() << " entries" << std::endl;

    i = entries->begin();
    while (i != entries->end()) {
	const std::string& key = i->first;
	last = entries->upper_bound(key);
	lex_indices.clear();
	for (; i != last; i++) {
	    lex_indices.push_back(i->second);
	}
	lens[size] = key.size();
	keys[size] = (char*) key.data();
	vals[size] = redump_lex(lens[size], lex_indices, tmpfile, lexfile);
	if (vals[size] < 0) {
	    std::cerr << "Unexpected error at " << key << std::endl;
	    cha_exit_perror((char*)"build darts file");
	}
	size++;
    }
    std::cerr << size << " keys" << std::endl;

    DoubleArrayL da;
    da.build(size, (const char**) keys, lens, vals);
    da.save(builder->path->c_str(), "wb");

    return builder->entries->size();
}
开发者ID:kev216,项目名称:mt_prepost_tool,代码行数:38,代码来源:dartsdic.cpp

示例4: execute

int StatusJob::execute()
{
    bool matched = false;
    const char *alternatives = "fileids|watchedpaths|dependencies|symbols|symbolnames|sources|jobs|info|compilers";

    if (!strcasecmp(query.constData(), "fileids")) {
        matched = true;
        if (!write(delimiter) || !write("fileids") || !write(delimiter))
            return 1;
        const Hash<uint32_t, Path> paths = Location::idsToPaths();
        for (Hash<uint32_t, Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) {
            if (!write<256>("  %u: %s", it->first, it->second.constData()))
                return 1;
        }
        if (isAborted())
            return 1;
    }

    std::shared_ptr<Project> proj = project();
    if (!proj) {
        if (!matched)
            write(alternatives);
        return matched ? 0 : 1;
    }

    if (query.isEmpty() || !strcasecmp(query.constData(), "watchedpaths")) {
        matched = true;
        if (!write(delimiter) || !write("watchedpaths") || !write(delimiter))
            return 1;
        Set<Path> watched = proj->watchedPaths();
        if (!write("Indexer"))
            return 1;
        for (Set<Path>::const_iterator it = watched.begin(); it != watched.end(); ++it) {
            if (!write<256>("  %s", it->constData()))
                return 1;
        }
        if (proj->fileManager) {
            if (!write("FileManager"))
                return 1;
            watched = proj->fileManager->watchedPaths();
            for (Set<Path>::const_iterator it = watched.begin(); it != watched.end(); ++it) {
                if (!write<256>("  %s", it->constData()))
                    return 1;
            }
        }
        if (isAborted())
            return 1;
    }

    if (query.isEmpty() || !strcasecmp(query.constData(), "dependencies")) {
        matched = true;
        const DependencyMap map = proj->dependencies();
        if (!write(delimiter) || !write("dependencies") || !write(delimiter))
            return 1;
        DependencyMap depsReversed;

        for (DependencyMap::const_iterator it = map.begin(); it != map.end(); ++it) {
            if (!write<256>("  %s (%d) is depended on by", Location::path(it->first).constData(), it->first))
                return 1;
            const Set<uint32_t> &deps = it->second;
            for (Set<uint32_t>::const_iterator dit = deps.begin(); dit != deps.end(); ++dit) {
                if (!write<256>("    %s (%d)", Location::path(*dit).constData(), *dit))
                    return 1;
                depsReversed[*dit].insert(it->first);
            }
            if (isAborted())
                return 1;
        }
        for (DependencyMap::const_iterator it = depsReversed.begin(); it != depsReversed.end(); ++it) {
            write<256>("  %s (%d) depends on", Location::path(it->first).constData(), it->first);
            const Set<uint32_t> &deps = it->second;
            for (Set<uint32_t>::const_iterator dit = deps.begin(); dit != deps.end(); ++dit) {
                if (!write<256>("    %s (%d)", Location::path(*dit).constData(), *dit))
                    return 1;
            }
            if (isAborted())
                return 1;
        }
    }

    if (query.isEmpty() || !strcasecmp(query.constData(), "symbols")) {
        matched = true;
        const SymbolMap &map = proj->symbols();
        write(delimiter);
        write("symbols");
        write(delimiter);
        for (SymbolMap::const_iterator it = map.begin(); it != map.end(); ++it) {
            const Location loc = it->first;
            const std::shared_ptr<CursorInfo> ci = it->second;
            write(loc);
            write(ci);
            write("------------------------");
            if (isAborted())
                return 1;
        }
    }

    if (query.isEmpty() || !strcasecmp(query.constData(), "symbolnames")) {
        matched = true;
        const SymbolNameMap &map = proj->symbolNames();
//.........这里部分代码省略.........
开发者ID:atilaneves,项目名称:rtags,代码行数:101,代码来源:StatusJob.cpp

示例5: execute

int StatusJob::execute()
{
    auto match = [this](const char *name) {
        return !strncasecmp(query.constData(), name, query.size());
    };
    bool matched = false;
    const char *alternatives = "fileids|watchedpaths|dependencies|cursors|symbols|targets|symbolnames|sources|jobs|info|compilers|headererrors|memory";

    if (match("fileids")) {
        matched = true;
        if (!write(delimiter) || !write("fileids") || !write(delimiter))
            return 1;
        const Hash<uint32_t, Path> paths = Location::idsToPaths();
        for (Hash<uint32_t, Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) {
            if (!write<256>("  %u: %s", it->first, it->second.constData()))
                return 1;
        }
        if (isAborted())
            return 1;
    }

    if (match("headererrors")) {
        matched = true;
        if (!write(delimiter) || !write("headererrors") || !write(delimiter))
            return 1;
        for (auto err : Server::instance()->jobScheduler()->headerErrors()) {
            if (!write(Location::path(err)))
                return 1;
        }
        if (isAborted())
            return 1;
    }

    if (query.isEmpty() || match("info")) {
        matched = true;
        if (!write(delimiter) || !write("info") || !write(delimiter))
            return 1;
        String out;
        Log log(&out);
#ifdef NDEBUG
        out << "Running a release build\n";
#else
        out << "Running a debug build\n";
#endif
        const Server::Options &opt = Server::instance()->options();
        out << "socketFile" << opt.socketFile << '\n'
            << "dataDir" << opt.dataDir << '\n'
            << "options" << opt.options
            << "jobCount" << opt.jobCount << '\n'
            << "rpVisitFileTimeout" << opt.rpVisitFileTimeout << '\n'
            << "rpIndexDataMessageTimeout" << opt.rpIndexDataMessageTimeout << '\n'
            << "rpConnectTimeout" << opt.rpConnectTimeout << '\n'
            << "rpConnectTimeout" << opt.rpConnectTimeout << '\n'
            << "threadStackSize" << opt.threadStackSize << '\n'
            << "defaultArguments" << opt.defaultArguments << '\n'
            << "includePaths" << opt.includePaths << '\n'
            << "defines" << opt.defines << '\n'
            << "ignoredCompilers" << opt.ignoredCompilers;
        write(out);
    }


    std::shared_ptr<Project> proj = project();
    if (!proj) {
        if (!matched)
            write(alternatives);
        return matched ? 0 : 1;
    }

    if (query.isEmpty() || match("watchedpaths")) {
        matched = true;
        if (!write(delimiter) || !write("watchedpaths") || !write(delimiter))
            return 1;
        Hash<Path, Flags<Project::WatchMode> > watched = proj->watchedPaths();
        auto watchModeToString = [](Flags<Project::WatchMode> mode) {
            List<String> ret;
            if (mode & Project::Watch_FileManager)
                ret << "filemanager";
            if (mode & Project::Watch_SourceFile)
                ret << "source";
            if (mode & Project::Watch_Dependency)
                ret << "dependency";
            if (mode & Project::Watch_CompilationDatabase)
                ret << "compilationdatabase";
            return String::join(ret, '|');
        };
        for (const auto &it : watched) {
            if (!write<256>("  %s (%s)", it.first.constData(), watchModeToString(it.second).constData())) {
                return 1;
            }
        }
    }

    const Dependencies &deps = proj->dependencies();
    if (query.isEmpty() || match("dependencies")) {
        matched = true;
        if (!write(delimiter) || !write("dependencies") || !write(delimiter))
            return 1;

        for (auto it : deps) {
//.........这里部分代码省略.........
开发者ID:PhilllyJoy,项目名称:rtags,代码行数:101,代码来源:StatusJob.cpp

示例6: QVERIFY

void tst_QHash::insert1()
{
    const char *hello = "hello";
    const char *world = "world";
    const char *allo = "allo";
    const char *monde = "monde";

    {
        typedef QHash<QString, QString> Hash;
        Hash hash;
        QString key;
        for (int i = 0; i < 10; ++i) {
            key[0] = i + '0';
            for (int j = 0; j < 10; ++j) {
                key[1] = j + '0';
                hash.insert(key, "V" + key);
            }
        }

        for (int i = 0; i < 10; ++i) {
            key[0] = i + '0';
            for (int j = 0; j < 10; ++j) {
                key[1] = j + '0';
                hash.remove(key);
            }
        }
    }

    {
        typedef QHash<int, const char *> Hash;
        Hash hash;
        hash.insert(1, hello);
        hash.insert(2, world);

        QVERIFY(hash.size() == 2);
        QVERIFY(!hash.isEmpty());

        {
            Hash hash2 = hash;
            hash2 = hash;
            hash = hash2;
            hash2 = hash2;
            hash = hash;
            hash2.clear();
            hash2 = hash2;
            QVERIFY(hash2.size() == 0);
            QVERIFY(hash2.isEmpty());
        }
        QVERIFY(hash.size() == 2);

        {
            Hash hash2 = hash;
            hash2[1] = allo;
            hash2[2] = monde;

            QVERIFY(hash2[1] == allo);
            QVERIFY(hash2[2] == monde);
            QVERIFY(hash[1] == hello);
            QVERIFY(hash[2] == world);

            hash2[1] = hash[1];
            hash2[2] = hash[2];

            QVERIFY(hash2[1] == hello);
            QVERIFY(hash2[2] == world);

            hash[1] = hash[1];
	    QVERIFY(hash[1] == hello);
	}
	        {
            Hash hash2 = hash;
            hash2.detach();
            hash2.remove(1);
            QVERIFY(hash2.size() == 1);
            hash2.remove(1);
            QVERIFY(hash2.size() == 1);
            hash2.remove(0);
            QVERIFY(hash2.size() == 1);
            hash2.remove(2);
            QVERIFY(hash2.size() == 0);
            QVERIFY(hash.size() == 2);
        }

        hash.detach();

        {
            Hash::iterator it1 = hash.find(1);
            QVERIFY(it1 != hash.end());

            Hash::iterator it2 = hash.find(0);
            QVERIFY(it2 != hash.begin());
            QVERIFY(it2 == hash.end());

            *it1 = monde;
            QVERIFY(*it1 == monde);
            QVERIFY(hash[1] == monde);

            *it1 = hello;
            QVERIFY(*it1 == hello);
            QVERIFY(hash[1] == hello);
//.........这里部分代码省略.........
开发者ID:husninazer,项目名称:qt,代码行数:101,代码来源:tst_qhash.cpp


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