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


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

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


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

示例1: get

 int get(int key) {
     if(hashmap.count(key) == 0){
         return -1;
     }
     store.splice(store.begin(), store, hashmap[key]);
     hashmap[key] = store.begin();
     return (*hashmap[key]).second;
 }
开发者ID:Nov11,项目名称:leetcode,代码行数:8,代码来源:lrucache.cpp

示例2: get

 /*
  * @param key: An integer
  * @return: An integer
  */
 int get(int key) {
     // 1. access the cached items map
     // 2. update the key as the most recent used cache
     if (!cacheMap.count(key)) return -1;
     Node* item = cacheMap[key];
     updateCache(item);
     return item->value;
 }
开发者ID:PoundKey,项目名称:Algorithms,代码行数:12,代码来源:134.+LRU+Cache.cpp

示例3: Find

  int Find(int k) {
    if (!parent_.count(k)) {
      parent_[k] = k;
      rank_[k] = 1;
    }

    return FindHelper(k);
  }
开发者ID:jamarshon,项目名称:leetcode,代码行数:8,代码来源:947MostStonesRemovedWithSameRowOrColumn.cpp

示例4: inference_one

void inference_one(Blob &blob, 
	unordered_map<string, unsigned> &index_of_word,
	unordered_map<string, unsigned> &index_of_kb,
	unordered_map <string, unordered_map<string, vector<string>>> &graph,
	mat &Ws, mat &Ww){
	
	// Transform each word in question to corresponding index
	vector<string> words;
	
	vec f_q = zeros<vec>(Ww.n_rows);
	boost::split(words, blob.question, boost::is_any_of(" "));
	for (auto &w : words)
	{
		if (index_of_word.count(w) > 0){
			auto i = index_of_word[w];
			f_q += Ww.col(i);
		}
		else{
			cout << "cannot find " << w << " in index_of_word\n";
		}
	}
	
	vector<pair<double, AnswerInfo>>  answers;
	// Go over all candidate question topic entities
	for (auto &topic_e : blob.topic_entities){
		strategy_c1(graph, topic_e, f_q, index_of_kb, Ws, answers);
		//beam_search_c2(graph, topic_e, f_q, index_of_kb, Ws, answers);
	}
	sort(answers.begin(), answers.end(), [](const pair<double, AnswerInfo> &lhs, const pair<double, AnswerInfo>&rhs){return lhs.first > rhs.first; });

	std::ostringstream os;
	unordered_set<string> appeared;
	auto highest_score = answers[0].first;

	double threshold = 0.1;
	for (auto &a : answers){
		AnswerInfo &info = a.second;
		// The candidates whose scores are not far from the best answer are regarded as predicated results.
		// The threshould is set to be same with the margin defined at training stage.
		//if (highest_score - threshold > a.first) break;
		if (appeared.count(a.second.answer) == 0){
			os << info.answer << ":" << a.first << ":" << info.topic_entity << ":" << info.n_hop << " "; 
			appeared.insert(info.answer);
		}
	}
	string answer_str = os.str(); // Extra space at last need to be removed
	if (answer_str.back() == ' ')
		answer_str.pop_back();
	//static std::atomic<int> lno(0);
	//Ignore thread collision
	static int lno = 0;
	os.str("");
	//os.clear();
	os << blob.question << "\t" << blob.gold_answers_str << "\t" << answer_str << "\t" << blob.original_size_of_gold;
	blob.predicated = os.str();
	lno++;
	cout << "Process to line " << lno << endl;
}
开发者ID:v-shinc,项目名称:TransEBasedQA,代码行数:58,代码来源:inferenceCosine.cpp

示例5: check

 bool check(string sub, vector<int> &cnt, unordered_map<string, pair<int, int> >& umap) {
     if (umap.count(sub)) {
         if (umap[sub].second > cnt[umap[sub].first]) {
             cnt[umap[sub].first]++;
             return true;
         }
     }
     return false;
 }
开发者ID:jiayinjx,项目名称:leetcode-1,代码行数:9,代码来源:30-substring-with-concatenation-of-all-words.cpp

示例6: get_index

l get_index(unordered_map<string,l>& name_index, vector<player>& players, const string name) {
  if (name_index.count(name) == 0) {
    name_index[name] = players.size();
    player p;
    p.name = name;
    players.emplace_back(p);
  }
  return name_index[name];
}
开发者ID:metaflow,项目名称:contests,代码行数:9,代码来源:B.cpp

示例7: solve

int solve(int x) {
  if (memo.count(x))
    return memo[x];
  if (x & 1)
    memo[x] = max(x, solve(3*x+1));
  else
    memo[x] = max(x, solve(x >> 1));
  return memo[x];
}
开发者ID:juancate,项目名称:CompetitivePrograming,代码行数:9,代码来源:hallistone_hotpo.cpp

示例8: set

 /*
  * @param key: An integer
  * @param value: An integer
  * @return: nothing
  */
 void set(int key, int value) {
     if (m_capacity <= 0) return;
     if (cacheMap.count(key))
     {
         cacheMap[key]->value = value;
         // update an existing cache also makes it most recently used
         updateCache(cacheMap[key]); 
         return;
     }
     // 1. if LRUCache is full
     //  1.1 remove the least recent used cache - head
     //  1.2 insert key and value to the cache, make it the most recent used cache
     //  1.3 update the cache map
     // 2. if LRUCache is not full
     //  2.1 insert into the cache, and make it most recent used cache
     //  2.2 update the cache map
     if (isFull())
     {
         Node* node = new Node(key, value);
         Node* temp = head;
         if (head == tail)
         {
             // single item, replace it with the newly created node
             head = node;
             tail = node;
         }
         else
         {
             head = head->next;
             head->prev = NULL;
             tail->next = node;
             node->prev = tail;
             tail = node;
         }
         cacheMap[key] = node;
         cacheMap.erase(temp->key);
         delete temp;
     }
     else
     {
         Node* node = new Node(key, value);
         if (cacheMap.empty())
         {
             head = node;
             tail = node;
         }
         else
         {
             // make the node the most recent cache (tail)
            tail->next = node;
            node->prev = tail;
            tail = node;
         }
         cacheMap[key] = node;
     }
 }
开发者ID:PoundKey,项目名称:Algorithms,代码行数:61,代码来源:134.+LRU+Cache.cpp

示例9: nCr

ull nCr(int n, int k) {
	if (n == k) return 1;
	if (k <= 0) return 1;
	if (k == 1) return n;
	if (k == 2) return (0ull + n)*(n-1)/2;
	ull hash = 1267*n + k;
	if (myMap.count(hash)) return myMap[hash];

	return myMap[hash] = nCr(n-1,k) + nCr(n-1,k-1);
}
开发者ID:mhayter,项目名称:Cpp,代码行数:10,代码来源:530_binomial_showdown.cpp

示例10: WordDistance

 WordDistance(vector<string>& words) {
   db.reserve(words.size());
   for(int i=0;i<words.size();i++){
     if(db.count(words[i])) { 
       db[words[i]].push_back(i); 
     } else {
       db[words[i]] = vector<int>{i};
     }
   }
 }
开发者ID:kalashnikov,项目名称:leetcode,代码行数:10,代码来源:shortWordDistance.cpp

示例11:

list<self_state> reconstruct_path(const unordered_map<self_state, self_state>& previous, const self_state& current)
{
    list<self_state> path = {};
    if (previous.count(current) > 0)
    {
        path = reconstruct_path(previous, const_cast<unordered_map<self_state, self_state> &>(previous)[current]);
    }
    path.push_back(current);
    return path;
}
开发者ID:team-1504,项目名称:vision_2014,代码行数:10,代码来源:pathfinding.cpp

示例12: afegirRegal

/*
 * Funció que afageix un regal a la llista, o incrementa les
 * unitats en el cas de que el regal ja existeixi.
 */
void afegirRegal(string nomRegal){

    if(!regals.count(nomRegal)){
        //cout << "El regal NO exixteix! Afegit!" << endl;
        regals[nomRegal] = 1;
    }else{
        //cout << "El regal EXISTEIX! Increment!" << endl;
        regals[nomRegal]= regals[nomRegal]+1;
    }
}
开发者ID:josegarvinvictoria,项目名称:ReisMags,代码行数:14,代码来源:main.cpp

示例13: Factorial

long double Factorial(int n) {
  if (n == 0) {
    return 1;
  }
  static unordered_map<int, long double> ans;
  if (ans.count(n) == 0) {
    ans[n] = Factorial(n - 1) * n;
  }
  return ans[n];
}
开发者ID:fw1121,项目名称:Pandoras-Toolbox-for-Bioinformatics,代码行数:10,代码来源:main.cpp

示例14: insert_interaction

void insert_interaction(unordered_map<string,Interaction>& map,Interaction inter,
vector<Ht_matrix> const& matrices,vector<double> const& theta, vector<Dataset> const& all_datasets){
  string repres = inter.as_string();
  
  if(map.count(repres) > 0) // element already in map, do nothing
    return;
    
  if(inter.check_for_map(matrices,theta,all_datasets))
    map[repres] = inter;
}
开发者ID:RobABL,项目名称:baseRIT,代码行数:10,代码来源:trees.cpp

示例15: erase

        void erase(const string& idx) {
            if (index.empty() && count() > 0) {
                //...missing index, what to do?
            }

            if (index.count(idx) == 0) {
                //...throw
            }

            erase(index[idx]);
        }
开发者ID:joxmox,项目名称:joxhax,代码行数:11,代码来源:IndexedFile.hpp


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