C++ std::unordered_multiset
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
C++ std::unordered_multiset的更多相关文章
- 使用C++11的一点总结
C++11已不是新鲜技术,但对于我来说,工作中用得还不够多(前东家长时间使用gcc3.4.5,虽然去年升了4.8.2,但旧模块维护还是3.4.5居多:新东家用的是4.4.6,不能完整支持C ...
- [转载] C++11新特性
C++11标准发布已有一段时间了, 维基百科上有对C++11新标准的变化和C++11新特性介绍的文章. 我是一名C++程序员,非常想了解一下C++11. 英文版的维基百科看起来非常费劲,而中文版维基百 ...
- [技术] OIer的STL入门教程
注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...
- 在C++98基础上学习C++11新特性
自己一直用的是C++98规范来编程,对于C++11只闻其名却没用过其特性.近期因为工作的需要,需要掌握C++11的一些特性,所以查阅了一些C++11资料.因为自己有C++98的基础,所以从C++98过 ...
- [技术] OIer的C++标准库 : STL入门
注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...
- Wow C++11
什么是C++11? 一句话C++11是最新的C++标准,在2011年发布,所以叫C++11.在新的标准出现前,我们一直在用的是C++98,可想而知这份标准是1998年发布的,之后再2003年最过小的修 ...
- C++ 标准库概览(一分钟就看完了)
C++ 标准库以若干头文件的方式提供. 下面简单介绍一个各头文件的内容. 第一部分 容器 Containers <array> C++11 新增.提供了容器类模板 std::array,固 ...
- Understand the Qt containers(有对应表)
Container classes are one of the cornerstones of object-oriented programming, invaluable tools that ...
- C++标准模板库Stand Template Library(STL)简介与STL string类
参考<21天学通C++>第15和16章节,在对宏和模板学习之后,开启对C++实现的标准模板类STL进行简介,同时介绍简单的string类.虽然前面对于vector.deque.list等进 ...
随机推荐
- bzoj 1101 [POI2007]Zap——反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 #include<cstdio> #include<cstring& ...
- jdk1.8新特性之接口default方法
众所周知,default是java的关键字之一,使用场景是配合switch关键字用于条件分支的默认项.但自从java的jdk1.8横空出世以后,它就被赋予了另一项很酷的能力——在接口中定义非抽象方法. ...
- Python——while、continue、break、while-else、or、and、not
1. while 终止while循环: (1) 改变条件,使其不成立 (2) break 应用实例1:计算1+2+3+...+100 #1.使用两个变量 count = 1 sum = 0 while ...
- android图片优化
/1.不要将Button的背景设置为selector 如果是将Button的背景设置为selector,在初始化Button的时候会将正反选图片都加载在内存中,相当于一个按钮占用了两张相同大小图片所使 ...
- python 生成器和生成器表达式
1.生成器 生成器的本质就是迭代器 生成器的特点和迭代器一样.取值方式和迭代器一样(__next__(),send():给上一个yield传值) 生成器一般由生成器函数或者生成器表达式来创建 其实就是 ...
- Protobuff java 文件生成命令
protoc.exe -I./proto文件目录 --java_out=java文件目录 proto文件基于文件目录的全路径 protoc.exe -I./protoFolder --java_out ...
- ActiveMQ入门之四--ActiveMQ持久化方式
消息持久性对于可靠消息传递来说应该是一种比较好的方法,有了消息持久化,即使发送者和接受者不是同时在线或者消息中心在发送者发送消息后宕机了,在消息中心重新启动后仍然可以将消息发送出去,如果把这种持久化和 ...
- 【UVA】12504 Updating a Dictionary(STL)
题目 题目 分析 第一次用stringstream,真TMD的好用 代码 #include <bits/stdc++.h> using namespace std; int ...
- IDA Pro 权威指南学习笔记(八) - 基本 IDA 导航
导航目标 在分析阶段,IDA 会通过检查二进制文件的符号表生成符号名称,或根据二进制文件引用位置的方式自动生成一个名称 反汇编窗口中显示的任何名称都是导航目标 双击任何一个符号,IDA 将跳转到相应的 ...
- 如何在Oracle中向Collection类型的变量中逐条插入数据
这篇文章将要介绍如果需要生成一个新的Collection并且向其中添加数据的方法. procedure insert_object(d in dept_array, d2 out dept_array ...