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


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

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


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

示例1: addNeighbors

void addNeighbors(int x, int y, unordered_map<string,Point*>& pointsQueue){
    Point* p1 = new Point(x+1, y);
    string key1 = makeString(p1);
    
    if(isAccessible(x+1,y) && pointsQueue.count(key1)== 0){
        pointsQueue.insert(make_pair<string, Point*>( key1,p1));
        addNeighbors(p1->x, p1->y, pointsQueue);
    }else
        delete p1;
    
    Point* p2 = new Point(x-1, y);
    string key2 = makeString(p2);
    if(isAccessible(x-1,y) && pointsQueue.count(key2)== 0){
        pointsQueue.insert(make_pair<string, Point*>(key2,p2));
        addNeighbors(p2->x, p2->y, pointsQueue);
    }else
        delete p2;
    
    Point* p3 = new Point(x, y + 1);
    string key3 = makeString(p3);
    if(isAccessible(x,y +1) && pointsQueue.count(key3)== 0){
        
        pointsQueue.insert(make_pair<string, Point*>(key3, p3));
        addNeighbors(p3->x, p3->y, pointsQueue);
    }else
        delete p3;
    
    Point* p4 = new Point(x, y - 1);
    string key4 = makeString(p4);
    if(isAccessible(x,y-1) && pointsQueue.count(key4)== 0){
        pointsQueue.insert(make_pair<string, Point*>(key4, p4));
        addNeighbors(p4->x, p4->y, pointsQueue);
    }else
        delete p4;
}
开发者ID:goingeast,项目名称:data-structure-and-algorithms,代码行数:35,代码来源:MonkeyGrid.cpp

示例2: isMatch

    bool isMatch(const char *s, int pos, vector<pair<char, int> > &pattern, int ppos) {
    	unsigned int id = (pos << 16) | ppos;
    	
    	unordered_map<unsigned int, bool>::iterator iter = memo.find(id);
		if (memo.find(id) != memo.end()) return iter->second;
		
		bool res = false;
		
		if (ppos == pattern.size()) {
			res = s[pos] == '\0';
			memo.insert(make_pair(id, res));
			return res;
		}
		int i = pos;
		pair<char, int> &p = pattern[ppos];

		int 	offset = (p.second == SINGLE) ? 0 : -1;
		char 	ch = '\0';
		while (offset < 0 || (ch = s[pos + offset]) != '\0') {
			if (offset >= 0 && !cmp(ch, p.first)) {
				res = false;
				break;
			}
			if (isMatch(s, pos + offset + 1, pattern, ppos + 1)) {
				res = true;
				break;
			}
			if (p.second == SINGLE) break;
			offset++;
		}
		memo.insert(make_pair(id, res));
		return res;
	}
开发者ID:hgfeaon,项目名称:leetcode,代码行数:33,代码来源:RegularExpressionMatching.cpp

示例3: getDataFromServer

void getDataFromServer(string uri)
{
	int count=0;
	// http get request
	shared_ptr<HttpConnector> getrequest(new HttpConnector);
	//HttpConnector *getrequest = new HttpConnector;
	//result = getrequest->httpConnect(usrInput);
	result = getrequest->httpConnect(uri);
	if (result != "not valid")
	{
		shared_ptr<Parser> htmlParse(new Parser(result));
		//Parser *htmlParse = new Parser(result);
		// 성공하지 못했을 때 error코드 출력
		if (htmlParse->getstatusNum() != "200")
		{
			ret.push_back("\n페이지 요청 결과 : " + htmlParse->getstatusNum() + "  " + htmlParse->getstatus());
		}
		else
		{
			// html
			result = htmlParse->getHtml();
			shared_ptr<HTMLParser> htmlInfo(new HTMLParser(result));
			//HTMLParser *htmlInfo = new HTMLParser(result);
			ret = htmlInfo->getResult();
			hyperLinkMap = htmlInfo->getHyperLink();
			for (unsigned int i = 0; i < ret.size(); i++)
			{
				if (ret[i].length() >= 5)
				{
					if (ret[i].substr(ret[i].length() - 5, 5) == "image")
					{
						vector<char> tempimage;
						unordered_map<string, char*>::iterator FindIter = imagecache.find(ret[i].substr(0, ret[i].length() - 6));
						// cache image 찾았다면
						if (FindIter != imagecache.end())
						{
							images.insert(pair<int, char*>(count, FindIter->second));
							imageSize.insert(pair<int, int>(count, imagecacheSize.find(ret[i].substr(0, ret[i].length() - 6))->second));
							replace(ret, ret[i], "image");
							count++;
						}
						else
						{
							if (threads.size() < 50)
							{
								threads.push_back(thread(imageRequset, ret[i].substr(0, ret[i].length() - 6), count));
							}
							count++;
						}
					}
				}
			}
		}
	}
	else
	{
		ret.push_back("not valid");
	}
	for (auto& th : threads) th.detach();
}
开发者ID:dpdltm11,项目名称:NexonCUIWebBrowser,代码行数:60,代码来源:main.cpp

示例4: fillKeyboard

//helper function to prefill keyboard grid.
void fillKeyboard(unordered_map< char, vector<int> > &keyboard){

	string line1 = "qwertyuiop";
	string line2 = "asdfghjkl";
	string line3 = "zxcvbnm";

	for (int i = 0; i< line1.length(); i++ ){
		vector<int> position;
		position.push_back(0);
		position.push_back(i);
		keyboard.insert(make_pair(line1[i], position));
	}
	for (int i = 0; i< line2.length(); i++ ){
		vector<int> position;
		position.push_back(1);
		position.push_back(i);
		keyboard.insert(make_pair(line2[i], position));
	}
	for (int i = 0; i< line3.length(); i++ ){
		vector<int> position;
		position.push_back(2);
		position.push_back(i);
		keyboard.insert(make_pair(line3[i], position));
	}

	return;
}
开发者ID:ArthurSilveira,项目名称:Programming-Problems,代码行数:28,代码来源:main.cpp

示例5: string

	Arguments(int argc, char **argv, bool ignoreFirst = true) {
		this->argc = argc;
		this->argv = argv;
		this->ignoreFirst = ignoreFirst;

		for (int i = ignoreFirst ? 1 : 0; i < argc; i++) {
			string token = string(argv[i]);
			tokens.push_back(token);
		}

		string currentKey = "";
		map.insert({ currentKey, {} });
		for (string token : tokens) {
			if(startsWith(token, "---")) {
				cerr << "Invalid argument: " << token << endl;
				exit(1);
			} else if (startsWith(token, "--")) {
				currentKey = token.substr(2);
				map.insert({ currentKey,{} });
			} else if (startsWith(token, "-")) {
				currentKey = token.substr(1);
				map.insert({ currentKey,{} });
			} else {
				map[currentKey].push_back(token);
			}
		}
	}
开发者ID:davijo,项目名称:PotreeConverter,代码行数:27,代码来源:arguments.hpp

示例6: init

void init() {
	memset(children, -1, sizeof(children));

	int n; scanf("%d", &n);
	for (int i=0; i<n; ++i) {
		scanf("%s %s", name[0], name[1]);
		string sname1(name[0]);
		string sname2(name[1]);

		auto it = namemap.find(sname1);
		if (it == namemap.end()) {
			it = namemap.insert(pair<string, int>(sname1, first)).first;
			names[first++] = move(sname1);
		}
		int cid1 = it->second;

		it = namemap.find(sname2);
		if (it == namemap.end()) {
			it = namemap.insert(pair<string, int>(sname2, first)).first;
			names[first++] = move(sname2);
		}
		int cid2 = it->second;
		
		links[lfirst].cid = cid2;
		links[lfirst].nxt = children[cid1];
		children[cid1] = lfirst++;
	}

	dfs(0, 0);
	prermq();
}
开发者ID:cenhao,项目名称:coding,代码行数:31,代码来源:1069.cpp

示例7: id_of

int id_of(string &s, unordered_map<string, int> &mp) {
	auto it = mp.find(s);
	if (it == mp.end()) {
		mp.insert({s, mp.size()});
		return mp.size() - 1;
	} else	return it->second;
}
开发者ID:TimonKnigge,项目名称:Competitive-Programming,代码行数:7,代码来源:transportation.cpp

示例8: dispatchErrors

void dispatchErrors(vector<string>& vectSequences, uint k, unordered_map<string, vector<int>>& kmerToSignature, unordered_map<string, vector<pair<uint, uint>>>& kmerToReadPosi, unordered_map<uint, vector<uint>>& readToErrorPosition){
	string kmer;
	uint precP(0);
	for (uint r(0); r < vectSequences.size(); ++r){
		for (uint p(0); p < vectSequences[r].size() - k + 1; ++p){
			kmer =  vectSequences[r].substr(p, k);
			auto got = kmerToSignature.find(kmer);
			if (got != kmerToSignature.end()){
				uint sumSignature(0);
				for (uint n : got->second){
					sumSignature += n;
				}
				if (sumSignature > THRESHOLD1) { // we consider the kmer is errorless
					pair<uint, uint> rp({r, p});
					auto got2 = kmerToReadPosi.find(kmer);
					if (got2 != kmerToReadPosi.end()){
						got2->second.push_back(rp);
					} else {
						kmerToReadPosi.insert({kmer, {rp}});
					}
				} else { // kmer with error
					readToErrorPosition[r].push_back(p);
				}
			}
		}
	}
}
开发者ID:kamimrcht,项目名称:RNA_project,代码行数:27,代码来源:signatures.cpp

示例9: postOrder

void Solution508::postOrder(TreeNode *root, unordered_map<int, int> &counter, int &maxCount)
{
    if (root == nullptr)
        return;

    if (root->left)
    {
        postOrder(root->left, counter, maxCount);
        root->val += root->left->val;
    }
    if (root->right)
    {
        postOrder(root->right, counter, maxCount);
        root->val += root->right->val;
    }

    int count = counter.count(root->val);
    if (count == 0)
    {
        counter.insert({root->val, 1});
        count = 1;
    } else
        count = ++ counter[root->val];
    maxCount = std::max(maxCount, count);
}
开发者ID:zhangxiaoya,项目名称:LeetCodeCPP,代码行数:25,代码来源:Solution508.cpp

示例10: set

    void set(int key, int value)
    {
        auto itItemMap = m_itemMap.find(key);

        if (itItemMap != m_itemMap.end())
        {
            // The item with this key exists in the 
            // cache, so promote the item to the list 
            // tail. Note that itItemMap->second is 
            // updated with the new value.
            Promote(itItemMap->second);

            // Set the value.
            itItemMap->second->value = value;
        }
        else
        {
            // Check whether the cache has used all 
            // its capacity.
            if (m_itemMap.size() >= m_capacity)
            {
                // Erase the least recently used item.
                m_itemMap.erase(m_items.front().key);
                m_items.pop_front();
            }

            // Insert the item into the list and the key-to-list-iterator 
            // pair into the map.
            m_itemMap.insert(make_pair(
                key, m_items.insert(m_items.end(), Item(key, value))));
        }
    }
开发者ID:renweizhukov,项目名称:LeetCode,代码行数:32,代码来源:Solution.cpp

示例11: add_child

 S* add_child(M &move) {
     auto child = create_child(move);
     auto key = move.hash();
     auto pair = children.insert({key, child});
     auto it = pair.first;
     return it->second.get();
 }
开发者ID:lizhenghong66,项目名称:gtsa,代码行数:7,代码来源:gtsa.hpp

示例12: set

	void set(int key, int value) {
		if (capacity == 0) {
			return ;
		}
		unordered_map<int,QNode*>::iterator itr;
		QNode *tmp;
		itr = keyAddress.find(key);
		if (itr == keyAddress.end()) {
			tmp = new QNode(key, value);
			keyAddress.insert(pair<int, QNode*>(key, tmp));
		} else {
			tmp = itr->second;
			tmp->value = value;
			tmp->pre->next = tmp->next;
			tmp->next->pre = tmp->pre;
		}
		if (keyAddress.size() > capacity) {
			keyAddress.erase(rear.pre->key);
			rear.next = rear.pre;
			rear.pre = rear.pre->pre;
			rear.pre->next = &rear;
			delete rear.next;
			rear.next = NULL;
		}
		tmp->next = front.next;
		tmp->next->pre = tmp;
		front.next = tmp;
		tmp->pre = &front;
	}
开发者ID:cusion,项目名称:Algorithm,代码行数:29,代码来源:LRUCache.cpp

示例13: loadProgram

void loadProgram()
{
    std::ifstream fin;
    int count = 0;
    
    for (auto iter = filenames.cbegin(); iter != filenames.cend(); ++iter)
    {
        fin.open(*iter);
        if (fin.fail())
        {
            std::cerr << "Error: file " << *iter << "does not exsist!\n";
            exit(-1);
        }
        string temp;
        while (std::getline(fin, temp))
        {
            vector<string> instruction;
            std::istringstream iss(temp);
            string word;
            while (iss >> word)
            {
                instruction.push_back(word);
            }
            if (instruction[0] == "label" || instruction[0] == "function")
                instruction_address.insert({ instruction[1], count });
            instructions_ram.push_back(instruction);
            count++;
        }
        fin.close();
    }
    vector<string> end;
    end.push_back("end");
    instructions_ram.push_back(end);
}
开发者ID:noprom,项目名称:jack-compiler,代码行数:34,代码来源:VirtualMachion.cpp

示例14: set

	void set(int key, int value) {
		count++;
		if (valuemap.find(key) == valuemap.end())
		{
			// not find key in the cache

			if (size == cap)
			{
				// cache full, need deletion
				map<int, int>::iterator it = timekey.begin();
				int keytodelete = it->second;
				timekey.erase(it);
				keytime.erase(keytodelete);
				valuemap.erase(keytodelete);
				size--;
			}

			valuemap.insert(pair<int, int>(key, value));
			keytime.insert(pair<int, int>(key, count));
			timekey.insert(pair<int, int>(count, key));
			size++;

		}
		else
		{
			// find key in cache
			int time = keytime[key];
			timekey.erase(time);
			timekey.insert(pair<int, int>(count, key));
			keytime[key] = count;
			valuemap[key] = value;
		}
	}
开发者ID:atmqq1990,项目名称:leetcode,代码行数:33,代码来源:Q146_LRU_Cache.cpp

示例15: gatherAllClasses

void TestSchemaEvolution::gatherAllClasses() {
  static const char *classes[] = {"TH1F",
                                  "TH1S",
                                  "TH1D",
                                  "TH1I",
                                  "TH2F",
                                  "TH2S",
                                  "TH2D",
                                  "TH2I",
                                  "TH3F",
                                  "TH3S",
                                  "TH3D",
                                  "TH3I",
                                  "TProfile",
                                  "TProfile2D",
                                  "TF1",
                                  0};

  int i = 0;
  while (classes[i]) {
    TClass *tcl = TClass::GetClass(classes[i]);
    if (!tcl)
      continue;
    unique_classes_.insert(std::make_pair(classes[i], tcl->GetClassVersion()));
    analyseClass(tcl);
    ++i;
  }
}
开发者ID:hroskes,项目名称:cmssw,代码行数:28,代码来源:testSchemaEvolution.cpp


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