本文整理汇总了C++中unordered_multimap::count方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_multimap::count方法的具体用法?C++ unordered_multimap::count怎么用?C++ unordered_multimap::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_multimap
的用法示例。
在下文中一共展示了unordered_multimap::count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */
bool insert(int val) {
int count = map.count(val);
map.insert(make_pair(val, elements.size()));
elements.push_back(val);
return !count;
}
示例2: consecutives
// 这里必须假设hash的操作是O(1)的
int consecutives(unordered_multimap<int, int> &hash,
int value,
bool ascending) { // true: 升序 false: 降序
int count = 0;
while (hash.count(value) > 0) {
++count;
hash.erase(value); // 非常重要!
value += ascending ? 1: (-1);
}
return count;
}
示例3: cache_access2
bool cache_access2 (int index, int tag, Data d) {
bool hit = 1;
pair<int, Data> mypair(index, d);
int count = L2.count(index);
// Miss
if (count <= 0) {
L2.insert(mypair);
miss_count2++;
hit = 0;
valid_cacheline2++;
}
else if (count == 1) {
auto range = L2.equal_range(index);
auto it = range.first;
Data d1 = it->second;
// Hit
if (d1.tag == tag) {
it->second.lru = 0;
//cout << "Hit" << endl;
hit_count2++;
}
// Miss
else {
it->second.lru = 1;
//cout << "Miss" << endl;
miss_count2++;
hit = 0;
L2.insert(mypair);
valid_cacheline2++;
}
}
else if (count == 2) {
auto range = L2.equal_range(index);
auto it = range.first;
auto it_1 = range.first;
auto it_2 = ++it;
Data d1 = it_1->second;
Data d2 = it_2->second;
// Hit
if (d1.tag == tag) {
it_1->second.lru = 0;
it_2->second.lru = 1;
//cout << "Hit" << endl;
hit_count2++;
}
else if (d2.tag == tag) {
it_1->second.lru = 1;
it_2->second.lru = 0;
//cout << "Hit" << endl;
hit_count2++;
}
else if (d1.lru == 1) {
it_2->second.lru = 1;
//cout << "Miss" << endl;
miss_count2++;
evict_count2++;
hit = 0;
L2.erase(it_1);
L2.insert(mypair);
}
else {
it_1->second.lru = 1;
//cout << "Miss" << endl;
miss_count2++;
evict_count2++;
hit = 0;
L2.erase(it_2);
L2.insert(mypair);
}
}
else {
cout << "Containing more than 2 cachelines" <<endl;
exit(1);
}
return hit;
}