std::unordered_multiset

template < class Key,                         // unordered_multiset::key_type/value_type
class Hash = hash<Key>, // unordered_multiset::hasher
class Pred = equal_to<Key>, // unordered_multiset::key_equal
class Alloc = allocator<Key> // unordered_multiset::allocator_type
> class unordered_multiset;

Unordered Multiset

Unordered multisets are containers that store elements in no particular order, allowing fast retrieval of individual elements based on their value, much like unordered_set containers, but allowing different elements to have equivalent values.

In an unordered_multiset, the value of an element is at the same time its key, used to identify it. Keys are immutable(不可变的), therefore, the elements in an unordered_multiset cannot be modified once in the container - they can be inserted and removed, though.

Internally, the elements in the unordered_multiset are not sorted in any particular, but organized into buckets depending on their hash values to allow for fast access to individual elements directly by their values (with a constant average time complexity on average).

Elements with equivalent values are grouped together in the same bucket and in such a way that an iterator (see equal_range) can iterate through all of them.

Iterators in the container are at least forward iterators.

Notice that this container is not defined in its own header, but shares header <unordered_set> with unordered_set.

Example

#include <iostream>
#include <string>
#include <unordered_set> ///> Note: use the unordered_set header using namespace std; template<class T>
T cmerge(T a, T b){
T t(a);
t.insert(b.begin(), b.end());
return t;
} int main(int argc, char **argv)
{
unordered_multiset<string> first1;
unordered_multiset<string> first2( {"one", "two", "three"} );
unordered_multiset<string> first3( {"red", "green", "blue"} );
unordered_multiset<string> first4( first2 );
unordered_multiset<string> first5( cmerge(first4,first3) );
unordered_multiset<string> first6( first5.begin(), first5.end() ); cout << "\nFirst6 set: ";
for(const string& x: first6 ){
cout << " " << x;
} return 0;
}

Reference

cplusplus


C++ std::unordered_multiset的更多相关文章

  1. 使用C++11的一点总结

          C++11已不是新鲜技术,但对于我来说,工作中用得还不够多(前东家长时间使用gcc3.4.5,虽然去年升了4.8.2,但旧模块维护还是3.4.5居多:新东家用的是4.4.6,不能完整支持C ...

  2. [转载] C++11新特性

    C++11标准发布已有一段时间了, 维基百科上有对C++11新标准的变化和C++11新特性介绍的文章. 我是一名C++程序员,非常想了解一下C++11. 英文版的维基百科看起来非常费劲,而中文版维基百 ...

  3. [技术] OIer的STL入门教程

    注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...

  4. 在C++98基础上学习C++11新特性

    自己一直用的是C++98规范来编程,对于C++11只闻其名却没用过其特性.近期因为工作的需要,需要掌握C++11的一些特性,所以查阅了一些C++11资料.因为自己有C++98的基础,所以从C++98过 ...

  5. [技术] OIer的C++标准库 : STL入门

    注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...

  6. Wow C++11

    什么是C++11? 一句话C++11是最新的C++标准,在2011年发布,所以叫C++11.在新的标准出现前,我们一直在用的是C++98,可想而知这份标准是1998年发布的,之后再2003年最过小的修 ...

  7. C++ 标准库概览(一分钟就看完了)

    C++ 标准库以若干头文件的方式提供. 下面简单介绍一个各头文件的内容. 第一部分 容器 Containers <array> C++11 新增.提供了容器类模板 std::array,固 ...

  8. Understand the Qt containers(有对应表)

    Container classes are one of the cornerstones of object-oriented programming, invaluable tools that ...

  9. C++标准模板库Stand Template Library(STL)简介与STL string类

    参考<21天学通C++>第15和16章节,在对宏和模板学习之后,开启对C++实现的标准模板类STL进行简介,同时介绍简单的string类.虽然前面对于vector.deque.list等进 ...

随机推荐

  1. bzoj 3994 [SDOI2015]约数个数和——反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994 \( d(i*j)=\sum\limits_{x|i}\sum\limits_{y|j ...

  2. php处理字符串格式的计算表达式

    有时候我们对每一种产品都有一个提成公式,而这个计算提成的公式是以字符串格式存在表中的 当我们用这个计算公式时,他并不像我们写的:$a=2+3*5;这样简单的能计算出结果,而它是个字符串 所以,我们就必 ...

  3. windows 安装redis

    git :https://github.com/ServiceStack/redis-windows 备份地址:https://gitee.com/liuq1991v/redis-for-window ...

  4. jmetr _MD5加密_获取签名

    要达到的目的: app每个请求里面 请求头都带有一个 sign 的参数, 他的值是通过 开发自己设计的拼接方式 再通过md5加密生成 我们就是要生成这个sign的值出来 准备: 和开发要到签名组成公式 ...

  5. 017:磁盘I/0介绍和测试

    一. 磁盘 1. 磁盘的访问模式 顺序访问 顺序的访问磁盘上的块: 一般经过测试后,得到该值的单位是MB/s,表示为磁盘带宽,普通硬盘在 50~ 100 MB/s 随机访问 随机的访问磁盘上的块 也可 ...

  6. docker 学习(十) 容器常用命令

    1  docker run -it ubuntu:15.10 /bin/bash 如果有ubuntu:15.10这个镜像,就run,否则会从dockerhub下载,并run. -it 一般连用,表示按 ...

  7. python 之 functools模块

    functools模块用于高阶函数:作用于或返回其他函数的函数.一般而言,任何可调用对象都可以作为本模块用途的函数来处理. 官方文档已经有了详尽的介绍,这里就不在复述,详情请见:官方文档 .这里主要介 ...

  8. ecshop if多条件语句写法

    smarty中的if语句和php中的if语句一样,if必须与/if成对出现.可以使用else和elseif子句. 可以使用条件修饰词:eq.ne.neq.gt.lte.le.gte.ge.is eve ...

  9. linux 远程连接服务器ftp命令整理

    Ftp命令的功能是在本地机和远程机之间传送文件.该命令的一般格式如下: $ ftp 主机名/IP ftp将给出提示符,等待用户输入命令: $ ftp ftp > 最常用的命令有: ls 列出远程 ...

  10. IOS Background 之 Background Fetch

    http://www.ithao123.cn/content-1363653.html 定期更新数据的app,比如及时通信类,微博等app. 定期后台获取,等打开后获取的快一些. 30分钟后打开手,获 ...