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


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

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


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

示例1: main

int main() {
    initialize();

    for (int cnt = 0; cnt < t; cnt++) {
        scanf("%d", &n);

        eqcnt = noteqcnt = xcnt = 0;
        hashmap.clear();
        hashmap.reserve(SIZEMAX);
        make_set(SIZEMAX);
        flag = true;

        for (int opcnt = 0; opcnt < n; opcnt++) {
            int i, j, e;
            scanf("%d %d %d", &i, &j, &e);

            switch (e) {
                case 1:
                    eq[eqcnt].i = i;
                    eq[eqcnt].j = j;

                    if (hashmap.count(i) == 0) hashmap[i] = xcnt++;
                    if (hashmap.count(j) == 0) hashmap[j] = xcnt++;

                    union_set(hashmap[i], hashmap[j]);

                    eqcnt++;
                    break;
                case 0:
                    if (i == j) flag = false;

                    if (flag) {
                        noteq[noteqcnt].i = i;
                        noteq[noteqcnt].j = j;

                        noteqcnt++;
                    }
                    break;
            }  // switch to e
        }      // for

        for (int i = 0; i < noteqcnt and flag; i++) {
            Query &q = noteq[i];

            if (hashmap.count(q.i) > 0 and hashmap.count(q.j) > 0 and
                find_set(hashmap[q.i]) == find_set(hashmap[q.j]))
                flag = false;
        }  // for

        if (flag)
            printf(YES "\n");
        else
            printf(NO "\n");
    }  // for

    quit();
    return 0;
}  // function main
开发者ID:riteme,项目名称:test,代码行数:58,代码来源:main.cpp

示例2: 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

示例3: read

void read(ifstream& fin, unordered_map<string, double>& imMap)
{
	size_t imNum;
	fin.read((char *)&imNum, sizeof(size_t));

	imMap.clear();
	imMap.reserve(imNum);
	for (size_t i = 0; i < imNum; i++)
	{
		string imName;
		read(fin, imName);
		imMap.insert(make_pair<string, double>(move(imName), 0));
	}
}
开发者ID:garyzhao,项目名称:Sketch3DToolkit,代码行数:14,代码来源:HashIndexer.cpp

示例4: min

 WordDistance2(vector<string>& words) {
   result.reserve(2*words.size());
   string p;
   for(int i=0;i<words.size()-1;i++){ 
     for(int j=i+1;j<words.size();j++){
       if(words[i]==words[j]) continue;
       p = (words[i]>words[j]) ? (words[j]+"_"+words[i]) : (words[i]+"_"+words[j]);
       if(result.count(p)) {
         result[p] = min(result[p], j-i);
       } else { 
         result[p] = j-i;
       }
     }
   }
 }
开发者ID:kalashnikov,项目名称:leetcode,代码行数:15,代码来源:shortWordDistance.cpp

示例5: main

int main()
{
	known_cycles.reserve(1000000);
	known_cycles[1] = 1;

	unsigned i(0), j(0);
	while (cin >> i >> j)
	{
		if (!i || !j)
			break;
		auto n = FindMax(i, j);
		cout << i << " " << j << " " << n << endl;
	}
	return 0;
}
开发者ID:sakhnik,项目名称:uva,代码行数:15,代码来源:100-3n1.cpp

示例6: GetLocationMap

void PostingList::GetLocationMap(domain_t domain, unordered_map<int64_t, unordered_set<length_t>> &output) const {
    auto entry = datamap.find(domain);

    if (entry == datamap.end())
        return;

    output.reserve(entry->second.size() / kEntrySize);

    const char *bytes = entry->second.data();
    for (size_t i = 0; i < entry->second.size(); i += kEntrySize) {
        int64_t location = ReadInt64(bytes, i);
        length_t offset = ReadUInt16(bytes, i + 8);

        output[location].insert(offset);
    }
}
开发者ID:ModernMT,项目名称:MMT,代码行数:16,代码来源:PostingList.cpp

示例7: initialize_dict

void initialize_dict(const char * file, unordered_map<string, unordered_set<int>> & index_dict, vector<string> & dict)
{
  index_dict.reserve(10000);
  ifstream ifs(file);
  if (ifs.is_open())
  {
    while (ifs.good())
    {
      string line;
      getline(ifs, line);
      dict.push_back(line);
      istringstream iss(line);

      string word;
      int index = dict.size() - 1;
      for (auto i = istream_iterator<string>(iss); i != istream_iterator<string>(); i++)
      {
        index_dict[*i].insert(index);
      }
    }
  }
}
开发者ID:xiongm,项目名称:dotfiles,代码行数:22,代码来源:word_searcher.cpp


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