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


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

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


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

示例1: max_distance

uint max_distance(TreeNode* root)
{
    if (root == NULL) {
        return 0;
    }

    static std::tr1::unordered_map<void*, uint> cache;

    typeof(cache.begin()) it = cache.find(root);
    if (it != cache.end()) {
        return it->second;
    }

    uint leftCost = max_distance(root->left);
    uint rightCost = max_distance(root->right);

    uint leftHeight = height(root->left);
    uint rightHeight = height(root->right);

    uint childCost = leftCost > rightCost ? leftCost : rightCost;
    uint throughRoot = leftHeight + rightHeight + root->cost;

    uint ret = childCost > throughRoot ? childCost : throughRoot;
    cache.insert(std::make_pair(root, ret));

    return ret;
}
开发者ID:jackonan,项目名称:acm,代码行数:27,代码来源:max_distance_of_tree_node.cpp

示例2: displayMulti

//Implementation of displayMulti()
void Engine::displayMulti(std::tr1::unordered_map<string, unsigned int> table) {

    // If the map is empty there is nothing to be done.
    if(table.empty()) {
        cout << "No movies matched your search. Sorry" << endl << endl ;
        return ;
    }
    
    std::tr1::unordered_map<string, unsigned int>::iterator it2 ;
    string big ;
    
    // Iterate three times to get the three movies with highest frequencies
    for(int i = 0 ; i < 3 ; i++) { 
    
    // If the intersection is empty the job is done
        if(table.size() == 0) {
            cout << "No more movies." << endl << endl ;
            return ;
        }
        
        // Assume the movie with highest frequency is the first one
        big = table.begin()->first ;
        
        // Iterate through the rest of the movies and if one with higher frequency
        // is found swap it with big
        for(it2 = table.begin() ; it2 != table.end() ; it2++)
            if(table[big] < it2->second)
                big = it2->first;
        
        // Print the movie with highest frequency
        cout << "Movie " << i+1 << ": " << big << endl ;
        
        // Erase that movie from the map
        table.erase(big) ;
    }
    cout << endl ;
}
开发者ID:chrisrodz,项目名称:moviedb-search-engine,代码行数:38,代码来源:Engine.cpp

示例3: dccListen

void m_dccchat::dccListen(std::string id, Socket* listenSocket) {
	std::tr1::unordered_map<std::string, std::vector<std::string> >::iterator ourReportingModules = reportingModules.find(id);
	while (true) {
		if (!listenSocket->isConnected())
			break;
		std::string receivedMsg = listenSocket->receive();
		std::cout << "DCC " << id << ":" << receivedMsg << std::endl;
		std::tr1::unordered_map<std::string, Module*> modules = getModules(); // get a new one each time in case it is updated
		for (std::tr1::unordered_map<std::string, std::string>::iterator hookIter = moduleTriggers.begin(); hookIter != moduleTriggers.end(); ++hookIter) {
			if (hookIter->first == receivedMsg.substr(0, receivedMsg.find_first_of(' '))) {
				bool alreadyReporting = false;
				for (unsigned int i = 0; i < ourReportingModules->second.size(); i++) {
					if (ourReportingModules->second[i] == hookIter->second) {
						alreadyReporting = true;
						break;
					}
				}
				if (!alreadyReporting)
					ourReportingModules->second.push_back(hookIter->second);
			}
		}
		for (unsigned int i = 0; i < ourReportingModules->second.size(); i++) {
			std::tr1::unordered_map<std::string, Module*>::iterator modIter = modules.find(ourReportingModules->second[i]);
			if (modIter == modules.end())
				ourReportingModules->second.erase(ourReportingModules->second.begin()+i);
			else {
				std::vector<std::string> modSupports = modIter->second->supports();
				for (unsigned int i = 0; i < modSupports.size(); i++) {
					if (modSupports[i] == "DCC_CHAT") {
						dccChat* dccMod = (dccChat*)modIter->second;
						dccMod->onDCCReceive(id, receivedMsg);
						break;
					}
				}
			}
		}
	}
	std::tr1::unordered_map<std::string, Module*> modules = getModules();
	for (unsigned int i = 0; i < reportingModules.size(); i++) {
		std::tr1::unordered_map<std::string, Module*>::iterator modIter = modules.find(ourReportingModules->second[i]);
		dccChat* dccMod = (dccChat*) modIter->second;
		dccMod->onDCCEnd(id); // call the DCC end hook for each watching module as the DCC session ends
	}
	delete listenSocket;
	activeConnections.erase(id);
}
开发者ID:MasseR,项目名称:RoBoBo-IRC-BoBo,代码行数:46,代码来源:m_dccchat.cpp

示例4: getQualityScore

    double Modularity::getQualityScore(const Graph * graph, std::tr1::unordered_map<uint32_t, Community*>& communities, double gamma)
    {
     //	const uint32_t communityNum = communities.size();

	    double Q = 0.0;
	    uint32_t edge_num = graph->edge_num_;
        std::tr1::unordered_map<uint32_t, Community*>::iterator itr;
	    for(itr=communities.begin(); itr!=communities.end(); itr++)
	    {
            Community * community = itr->second;
		    uint32_t in_degree = community->in_degree_;
		    uint32_t total_degree = community->total_degree_;

		    Q += ((double)in_degree)/(2*(double)edge_num) - pow((double)total_degree/((double)(2*edge_num)), 2);
            //printf("Q: %f, indegree: %u, total: %u, edgenum: %u\n",Q,in_degree, total_degree, edge_num);
	    }
			std::cout << "Q: \t" << Q << "\n";

	    return Q;
    }
开发者ID:inmanhust,项目名称:RecSys,代码行数:20,代码来源:Modularity.cpp

示例5: it

inline void operator<< (object::with_zone& o, const std::tr1::unordered_map<K,V>& v)
{
	o.type = type::MAP;
	if(v.empty()) {
		o.via.map.ptr  = NULL;
		o.via.map.size = 0;
	} else {
		object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
		object_kv* const pend = p + v.size();
		o.via.map.ptr  = p;
		o.via.map.size = v.size();
		typename std::tr1::unordered_map<K,V>::const_iterator it(v.begin());
		do {
			p->key = object(it->first, o.zone);
			p->val = object(it->second, o.zone);
			++p;
			++it;
		} while(p < pend);
	}
}
开发者ID:skhaz,项目名称:msgpack-c,代码行数:20,代码来源:unordered_map.hpp

示例6: height

uint height(TreeNode* root)
{
    if (root == NULL) {
        return 0;
    }

    static std::tr1::unordered_map<void*, uint> cache;

    typeof(cache.begin()) it = cache.find(root);
    if (it != cache.end()) {
        return it->second;
    }

    uint left = height(root->left);
    uint right = height(root->right);
    uint child = left > right ? left : right;

    uint ret = root->cost + child;
    cache.insert(std::make_pair(root, ret));

    return ret;
}
开发者ID:jackonan,项目名称:acm,代码行数:22,代码来源:max_distance_of_tree_node.cpp

示例7:

std::vector<std::string> m_dccchat::getConnections() {
	std::vector<std::string> connections;
	for (std::tr1::unordered_map<std::string, Socket*>::iterator connIter = activeConnections.begin(); connIter != activeConnections.end(); ++connIter)
		connections.push_back(connIter->first);
	return connections;
}
开发者ID:MasseR,项目名称:RoBoBo-IRC-BoBo,代码行数:6,代码来源:m_dccchat.cpp


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