Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

unordered_multimap::count

公众成员函数  <unordered_map>
size_type count ( const key_type& k ) const;

计数具有特定键的元素

在容器中搜索键为k的元素,并返回所找到的元素数量。

☲  参数


K
要计数的元素的键值。
成员类型key_type是容器中元素的类型。在unordered_multimap容器中, 定义为类的第一个模板形参(Key)的别名。

☉  返回值



键值等于k的容器中元素的数量。
成员类型size_type是一个unsigned整型。

☣  示例



// unordered_multimap::count
#include <iostream>
#include <string>
#include <unordered_map>

int main ()
{
  std::unordered_multimap<std::string,std::string> myumm = {
     {"orange","FL"},
     {"strawberry","LA"},
     {"strawberry","OK"},
     {"pumpkin","NH"} };

  for (auto& x: {"orange","lemon","strawberry"}) {
    std::cout << x << ": " << myumm.count(x) << " entries.\n";
  }

  return 0;
}

输出:
orange: 1 entries.
lemon: 0 entries.
strawberry: 2 entries.

✥ 复杂度



平均情况:计算的元素数量呈线性。
最坏情况:容器大小呈线性。

☣ 迭代器的有效性



不变

🍄  另请参阅



unordered_multimap::equal_range 获取具有特定键的元素范围(公众成员函数)
unordered_multimap::size 返回容器大小(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图