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


最新文章

  1. 使用 Redis 实现分布式锁
  2. 解决对含有第三方jar包的项目打包出现java.lang.NoClassDefFoundError问题
  3. 学习PYTHON之路, DAY 4 - PYTHON 基础 4 (内置函数)
  4. Android手动签名
  5. C#中委托实现的异步编程
  6. 小试SQL SERVER 2014 加密备份
  7. Liferay 6.2 改造系列之二十二:如何发布WAR包
  8. HDU 1372 Knight Moves
  9. 配置ini指定eclipse启动JDK版
  10. 在ASP.NET非MVC环境中(WebForm中)构造MVC的URL参数
  11. matlab 相同函数名解决
  12. VC++编程之对话框贴图
  13. PHP Session可能会引起并发问题
  14. [HIHO1041]国庆出游(DFS, bitset)
  15. maven 依赖排除
  16. 原生js日期时间插件鼠标点击文本框弹出日期时间表格选择日期时间
  17. bootcamp
  18. Android应用开发学习之状态栏通知
  19. Dapper中条件为In的写法
  20. 深入理解 ORM框架

热门文章

  1. bzoj1018[SHOI2008]堵塞的交通traffic——线段树
  2. 关于python urlopen 一个类似radio流的timeout方法
  3. xshell 提示 继续使用此程序必须应用到最新的更新或使用新版本 的解决方案
  4. 关于不同应用程序存储IO类型的描述
  5. [转载]Linux驱动mmap内存映射
  6. java多线程(2) 线程同步
  7. PTA 1005 Spell It Right (20)(20 分)水题
  8. DynamicConverter
  9. wkhtmktopdf
  10. 实验楼HTML基础入门学习